Skip to content

Fix stack buffer overflows with overlong file names - #9289

Merged
Esteban82 merged 1 commit into
masterfrom
fix-srtm-relief-overflow
Nov 5, 2026
Merged

Esteban82 merged 1 commit into
masterfrom
fix-srtm-relief-overflow

Conversation

@Esteban82

Copy link
Copy Markdown
Member

gmt_remote_dataset_id still used an unbounded sprintf in its srtm_relief_0 branch (GenericMappingTools/gmt#8928 only bounded the other branch, see #8926), and gmt_get_filename used sscanf with no width, so a file name longer than PATH_MAX overflowed a stack buffer. This bounds those copies plus three in gmtwhich.c. Reported by @hothaot.

Tested with:

gmt which @srtm_relief_0$(head -c 5000 /dev/zero | tr '\0' A)
gmt which $(head -c 5000 /dev/zero | tr '\0' A)

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.

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]>
@Esteban82
Esteban82 requested review from a team and joa-quim November 4, 2026 02:59
@Esteban82 Esteban82 added the bug Something isn't working label Nov 4, 2026
@Esteban82
Esteban82 merged commit 8e08023 into master Nov 5, 2026
28 of 31 checks passed
@Esteban82
Esteban82 deleted the fix-srtm-relief-overflow branch November 5, 2026 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants