Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strncpy out of bounds fix #1785

Open
wants to merge 1 commit into
base: priettt/ndkCrashFramesFix
Choose a base branch
from

Conversation

priettt
Copy link
Contributor

@priettt priettt commented Dec 28, 2024

We use strncpy in many places. In almost all places, we call it with the size of the destination array. That means something like this:

char destinationArray[3]
char sourceArray[5]
emb_strncpy(destinationArray, sourceArray, sizeof(destinationArray))

In that case, sizeof(destinationArray) will be 3. That means the while loop will execute until 4, and we will try to write src[3] to dst[3], which is out of bounds.

While C might let you write out of bounds, it may cause memory corruption or failure.

Changes:

  • Modified the while loop so i won't be equal to destination_len.
  • Added a source[i] != '\0' verification in case the source is smaller than the destination. Strings passed in src should end in that termination char. If they don't, we might face another OOB. We could solve this by also passing source_len as a parameter.
  • Added some test cases.
  • Improved naming.

@priettt priettt requested a review from a team as a code owner December 28, 2024 21:04
@priettt priettt changed the base branch from main to priettt/ndkCrashFramesFix December 28, 2024 21:04
Copy link
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

Copy link
Collaborator

@bidetofevil bidetofevil left a comment

Choose a reason for hiding this comment

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

welp

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.

2 participants