Repository navigation
Fix stack buffer overflows with overlong file names - #9289
Merged
Merged
Conversation
gmt_remote_dataset_id still used an unbounded sprintf in its srtm_relief_0 branch (#8928 only bounded the else branch), so an argument longer than PATH_MAX like @srtm_relief_0AAAA... overflowed the stack buffer. gmt_get_filename used sscanf "%[^=?]" without a width, smashing the stack for any file argument longer than PATH_MAX. Also bound the sprintf/strcpy copies of the argument in gmtwhich. Co-Authored-By: Claude Opus 5.5 <[email protected]>
joa-quim
approved these changes
Nov 5, 2026
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.
gmt_remote_dataset_idstill used an unboundedsprintfin itssrtm_relief_0branch (GenericMappingTools/gmt#8928 only bounded the other branch, see #8926), andgmt_get_filenameusedsscanfwith no width, so a file name longer thanPATH_MAXoverflowed a stack buffer. This bounds those copies plus three in gmtwhich.c. Reported by @hothaot.Tested with:
Both used to abort with a buffer overflow; now they report “not found”.
Other modules still abort on such names further down (
GMT_Get_FilePath, gmt_access); that would need a length check when options are parsed, left for a separate PR.🤖 Generated with Claude Code — Claude Opus 5.5 (review, gmt_io.c fix, final branch); initial gmt_remote.c/gmtwhich.c fix with Claude Sonnet 5.5.