fix: prevent stack buffer overflow in handle_name#127
Open
hacktron-app-stg[bot] wants to merge 1 commit into
Open
fix: prevent stack buffer overflow in handle_name#127hacktron-app-stg[bot] wants to merge 1 commit into
hacktron-app-stg[bot] wants to merge 1 commit into
Conversation
Replace unbounded strcpy of the untrusted argv[1] input into a fixed 64-byte stack buffer with a bounded snprintf, eliminating the stack buffer overflow (corruption of the saved frame pointer/return address).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Vulnerability
handle_nameinparser.ccopied the attacker-controlled command-line argument (argv[1], passed asinput) into a fixed 64-byte stack buffer usingstrcpy(), which does no length checking. Supplying an argument longer than 63 bytes overflowsname, corrupting adjacent stack data including the saved frame pointer and return address — a classic high-severity stack buffer overflow (DoS / potential arbitrary code execution).Taint path:
main→handle_name(argv[1])→strcpy(name, input).Fix
Replaced the unbounded
strcpywith a bounded, always-NUL-terminating copy:This truncates any input longer than the buffer instead of writing out of bounds, and keeps the original output format for normal input.
Verification
strcpyintochar name[64]from untrustedargv[1].gcc -c parser.cafter the change — the object file builds successfully. (Remaining-Wformat-security/getswarnings correspond to separate, out-of-scope findings in the same file and were intentionally not modified.)Automated fix by Hacktron for finding: https://staging.hacktron.ai/testestesttest/findings/452edc0b-bfd2-415c-a613-564947642227