Skip to content

Conversation

@rdmark
Copy link
Collaborator

@rdmark rdmark commented Aug 6, 2025

This changeset should resolve all Security and Reliability bugs detected by SonarQube

Potential buffer overflow in bstrlib.c:

bformata() and bassignformat() have calls to vsnprintf() that can potentially overflow the buffer if the value of the second parameter (length) is extremely large

This adds some validation that bails out if the value reaches INT_MAX

Potential null pointer dereference in bstest.c:

The check framework does an assertion for null pointers in the test data, but continues test execution even when the assertion fails, which leads to the potential null pointer dereference when subsequent tests does other assertions on the same pointers

Now we instead abort the test with ck_abort_msg() when a null pointer is encountered

bformata() and bassignformat() have calls to vsnprintf() that can
potentially overflow the buffer if the value of the second parameter
is extremely large

This adds some validation that bails out if the value reaches INT_MAX
@rdmark rdmark force-pushed the buffer-overflow branch 3 times, most recently from d078ff4 to 4e64e98 Compare August 6, 2025 18:26
@rdmark rdmark changed the title Protect against buffer overflow in formatting functions Protect against buffer overflows and null pointer dereferences Aug 6, 2025
@rdmark rdmark requested a review from msteinert August 6, 2025 18:32
The check framework does an assertion for null pointers in the test data, but continues test execution even when the assertion fails, which leads to the potential null pointer dereference when subsequent tests does other assertions on the same pointers

Now we instead abort the test with ck_abort_msg() when a null pointer is encountered
@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 6, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
10.8% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@rdmark
Copy link
Collaborator Author

rdmark commented Aug 6, 2025

@msteinert What do you think about these changes? They should bring us to green status in both the Security and Reliability categories in SonarQube.

The 10% code duplication failure can't be avoided I think given the nature of the code, but I'm open to suggestions.

@msteinert
Copy link
Owner

Sorry for the delay getting to your PRs, I was on vacation last week. I'm going to try to get caught up in the next couple days.

Copy link
Owner

@msteinert msteinert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

I agree, it doesn't seem possible to avoid duplication here.

@msteinert msteinert merged commit 594d2f3 into main Aug 11, 2025
22 of 25 checks passed
@rdmark rdmark deleted the buffer-overflow branch August 11, 2025 18:22
@rdmark
Copy link
Collaborator Author

rdmark commented Aug 11, 2025

Cheers! After merging this PR, one new issue and a few old ones remain, so I'll prepare a new one shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants