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

sscanf solution with buffer overflow prevention #4438

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

Conversation

DevonSchwartz
Copy link

@DevonSchwartz DevonSchwartz commented May 1, 2024

This fix is related to issue #4366.

This issue points to unsafe call to sscanf to get a username in the case of an invalid uid. The sscanf call has a potential buffer overflow. However, this sscanf call is not implimented in main. We implement the sscanf call safely in main by limiting user input to the size of PATH_MAX.

This commit creates a warning that fmt_str is not a string literal. However, fmt_str is equal to "%[PATH_MAX]s"

fix #4366

@lxc-jenkins
Copy link

This pull request didn't trigger Jenkins as its author isn't in the allow list.

An organization member must perform one of the following:

  • To have this branch tested by Jenkins, use the "ok to test" command.
  • To have a one time test done, use the "test this please" command.

Those commands are simple Github comments of the format: "jenkins: COMMAND"

@DevonSchwartz
Copy link
Author

I saw that the sanitizer fails because of a warning produced by the string literal fmt_str. We make fmt_str a string literal by using [] rather than dynamically allocating, but we still get this error. Should we still change our code to avoid the error?

@stgraber
Copy link
Member

stgraber commented May 2, 2024

Yeah, pretty much everyone runs with those warnings enabled in production so that needs to be addressed.

@DevonSchwartz
Copy link
Author

Is the check for the size of PATH necessary before we read in the buffer?

@DevonSchwartz
Copy link
Author

Should I squash the latest commits to close the sscanf issue?

@stgraber
Copy link
Member

stgraber commented May 6, 2024

Probably good to squash. I'm really not sure about the fix though but I'm also not a C developer so I'll let @mihalicyn, @brauner or @hallyn look at it.

First checks if PATH_MAX 4096 bytes

Signed-off-by: Devon Schwartz <devon.s.schwartz@utexas.edu>
@mihalicyn
Copy link
Member

I don't understand this. We are not using %s in the original code in this place. Please can you elaborate on this a bit?

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

Successfully merging this pull request may close these issues.

usage of sscanf with format %s is unsafe
5 participants