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

Fix out-of-bounds read & write #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jengelh
Copy link

@jengelh jengelh commented Aug 21, 2024

gcc warns:

selfile.c:1253:24: warning: "strncat" specified bound depends on the length of the source argument [-Wstringop-overflow=]
 1253 |                 (void) strncat(SFcurrentPath, str, len - 1);

The third argument ought to be the size of the destination, not the source. You need snprintf (or a contrived mix of min()+max()) if you want to also restrict the source length.

Also, len - 1 can underflow if the string length for some reason is 0, catch that case as well.

Run through the compiler only; not runtime-tested.

gcc warns:

selfile.c:1253:24: warning: "strncat" specified bound depends on the
length of the source argument [-Wstringop-overflow=]
 1253 |                 (void) strncat(SFcurrentPath, str, len - 1);

The third argument ought to be the size of the _destination_, not the
_source_. You need snprintf (or a contrived mix of min()+max()) if
you want to also restrict the source length.

Also, `len - 1` can underflow if the string length for some
reason is 0, catch that case as well.
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.

1 participant