Skip to content

fix(hotbackup): bound home-path construction with snprintf#30

Merged
gburd merged 1 commit into
masterfrom
fix/hotbackup-sprintf-overflow
Jun 23, 2026
Merged

fix(hotbackup): bound home-path construction with snprintf#30
gburd merged 1 commit into
masterfrom
fix/hotbackup-sprintf-overflow

Conversation

@gburd

@gburd gburd commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

What

db_hotbackup built a probe path with sprintf(buf, "%s/%s", home, home)
into a fixed char buf[DB_MAXPATHLEN] stack buffer. A -h argument longer
than ~DB_MAXPATHLEN/2 overflows buf.

Replace with snprintf(buf, sizeof(buf), ...), matching the already-bounded
snprintf call later in the same function. Applied to the canonical
util/db_hotbackup.c and the checked-in build_vxworks/util/db_hotbackup.c
copy.

Impact

db_hotbackup is a local command-line utility run by the operator, not a
remotely 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

  • Builds clean (make db_hotbackup, no new warnings).
  • Functional check: db_hotbackup -h <4096 'A's> now fails cleanly with
    "File name too long" instead of crashing; previously the sprintf wrote
    ~8KB into a DB_MAXPATHLEN buffer.

Note

Supersedes #23, which targeted the right line but patched only the generated
build_vxworks/ copy and shipped a standalone regression test that exercised
a local snprintf rather than the actual code path. This change fixes the
canonical source (and the vxworks copy) and verifies the real utility.

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.
@gburd
gburd merged commit c9844c1 into master Jun 23, 2026
36 of 39 checks passed
@gburd
gburd deleted the fix/hotbackup-sprintf-overflow branch June 23, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant