Skip to content

[PW_SID:1181248] [v2] sdp: Prevent integer underflow in string attribute length calculation - #2635

Closed
BluezTestBot wants to merge 1 commit into
masterfrom
1181248
Closed

BluezTestBot wants to merge 1 commit into
masterfrom
1181248

Conversation

@BluezTestBot

Copy link
Copy Markdown

In lib/bluetooth/sdp.c, attribute string length calculations subtract
sizeof(uint8_t) from d->unitSize (e.g. d->unitSize - sizeof(uint8_t)).
When d->unitSize is 0 or less than sizeof(uint8_t), this subtraction
underflows in 32-bit integer arithmetic to a negative/huge length value,
passing invalid sizes to memory allocation and length extraction
functions.

Add explicit lower-bound guards checking d->unitSize > (int)sizeof(uint8_t)
to ensure that when d->unitSize <= sizeof(uint8_t), the calculated string
length is safely set to 0.

Assisted-by: Antigravity

Changes in v2:

  • Cast sizeof(uint8_t) to (int) in comparison checks to fix
    -Werror=sign-compare compiler warnings reported by BlueZ CI.
  • Refactor length calculation blocks to use clear if/else guards.

lib/bluetooth/sdp.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)

In lib/bluetooth/sdp.c, attribute string length calculations subtract
sizeof(uint8_t) from d->unitSize (e.g. d->unitSize - sizeof(uint8_t)).
When d->unitSize is 0 or less than sizeof(uint8_t), this subtraction
underflows in 32-bit integer arithmetic to a negative/huge length value,
passing invalid sizes to memory allocation and length extraction
functions.

Add explicit lower-bound guards checking d->unitSize > (int)sizeof(uint8_t)
to ensure that when d->unitSize <= sizeof(uint8_t), the calculated string
length is safely set to 0.

Assisted-by: Antigravity
@BluezTestBot

Copy link
Copy Markdown
Author

CheckPatch
Desc: Run checkpatch.pl script
Duration: 0.55 seconds
Result: PASS

@BluezTestBot

Copy link
Copy Markdown
Author

GitLint
Desc: Run gitlint
Duration: 0.37 seconds
Result: PASS

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@BluezTestBot

Copy link
Copy Markdown
Author

BuildEll
Desc: Build and Install ELL
Duration: 19.72 seconds
Result: PASS

@BluezTestBot

Copy link
Copy Markdown
Author

BluezMake
Desc: Build BlueZ
Duration: 393.94 seconds
Result: PASS

@BluezTestBot

Copy link
Copy Markdown
Author

MakeCheck
Desc: Run Bluez Make Check
Duration: 0.90 seconds
Result: PASS

@BluezTestBot

Copy link
Copy Markdown
Author

MakeDistcheck
Desc: Run Bluez Make Distcheck
Duration: 143.49 seconds
Result: PASS

@BluezTestBot

Copy link
Copy Markdown
Author

CheckValgrind
Desc: Run Bluez Make Check with Valgrind
Duration: 146.23 seconds
Result: PASS

@BluezTestBot

Copy link
Copy Markdown
Author

CheckSmatch
Desc: Run smatch tool with source
Duration: 291.36 seconds
Result: PASS

@BluezTestBot

Copy link
Copy Markdown
Author

bluezmakeextell
Desc: Build Bluez with External ELL
Duration: 96.12 seconds
Result: PASS

@BluezTestBot

Copy link
Copy Markdown
Author

TestFunctional
Desc: Run test-functional
Duration: 1156.46 seconds
Result: PASS

@BluezTestBot

Copy link
Copy Markdown
Author

IncrementalBuild
Desc: Incremental build with the patches in the series
Duration: 392.60 seconds
Result: PASS

@BluezTestBot

Copy link
Copy Markdown
Author

ScanBuild
Desc: Run Scan Build
Duration: 1150.89 seconds
Result: PASS

@BluezTestBot
BluezTestBot deleted the 1181248 branch October 8, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants