fix(hotbackup): bound home-path construction with snprintf#30
Merged
Conversation
db_hotbackup built the probe path with sprintf(buf, "%s/%s", home, home) into a fixed DB_MAXPATHLEN stack buffer. A -h argument longer than ~DB_MAXPATHLEN/2 overflowed buf. This is a local CLI utility run by the operator (not remotely reachable), so the impact is limited, but the unbounded write is a real defect. Use snprintf with sizeof(buf), matching the existing bounded call later in the same function. With an over-long -h the path now truncates and the subsequent path lookup fails cleanly (File name too long) instead of smashing the stack. Applied to both the canonical util/ source and the checked-in build_vxworks/ copy.
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.
What
db_hotbackupbuilt a probe path withsprintf(buf, "%s/%s", home, home)into a fixed
char buf[DB_MAXPATHLEN]stack buffer. A-hargument longerthan ~
DB_MAXPATHLEN/2overflowsbuf.Replace with
snprintf(buf, sizeof(buf), ...), matching the already-boundedsnprintfcall later in the same function. Applied to the canonicalutil/db_hotbackup.cand the checked-inbuild_vxworks/util/db_hotbackup.ccopy.
Impact
db_hotbackupis a local command-line utility run by the operator, not aremotely reachable surface, so the practical severity is limited (an operator
overflowing their own tool's stack). It is still a real unbounded write and
worth fixing.
Verification
make db_hotbackup, no new warnings).db_hotbackup -h <4096 'A's>now fails cleanly with"File name too long" instead of crashing; previously the
sprintfwrote~8KB into a
DB_MAXPATHLENbuffer.Note
Supersedes #23, which targeted the right line but patched only the generated
build_vxworks/copy and shipped a standalone regression test that exerciseda local
snprintfrather than the actual code path. This change fixes thecanonical source (and the vxworks copy) and verifies the real utility.