Repository navigation
Fix empty incremental-backup filename on non-glibc dirname() - #1352
Closed
Pranav-error wants to merge 1 commit into
Closed
Pranav-error wants to merge 1 commit into
Pranav-error wants to merge 1 commit into
Conversation
…rname() write_incremental_file() did: rel_path = pgmoneta_append(rel_path, relative_filename); rel_path = dirname(rel_path); file_name = pgmoneta_append(file_name, rel_path + strlen(rel_path) + 1); This relies on dirname() modifying its buffer in place and returning the same pointer, so pointer arithmetic past the inserted NUL lands on the original basename bytes. glibc commonly does this for simple inputs; POSIX doesn't require it, and BSD/macOS libc's dirname() can return a pointer into a separate static buffer instead -- verified empirically on macOS/clang, where this produces an EMPTY file_name rather than the real basename. Masked on Linux CI because glibc's dirname() happens to modify common inputs in place there. Fix: split directory and basename with strrchr() on a buffer we fully control, instead of depending on dirname()'s implementation-defined in-place behavior. Verified against a slash path, a no-slash path, and a single-level path via a standalone reproduction, and that the real codebase builds cleanly under -Werror with the change applied. Found by sweeping every dirname() call site in pg-family for the same portability bug class as pgmoneta#1345 after fixing that one in pgmoneta#1348 -- this is a different call site and failure mode (wrong data, not an invalid free), but the same root cause. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Member
|
Rebased and merged. Thanks for your contribution ! |
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.
Fixes #1351.
`write_incremental_file()` split a relative path into directory and
basename by calling `dirname()` and then doing pointer arithmetic
(`rel_path + strlen(rel_path) + 1`) to reach past it to the basename.
That only works if `dirname()` modifies its argument buffer in place
and returns the same pointer -- glibc commonly does this for simple
inputs, but POSIX doesn't require it, and BSD/macOS libc's `dirname()`
can return a pointer into a separate static buffer instead.
Verified empirically on macOS/clang with the exact pattern from this
function: `dirname()` returns a different pointer, and the basename
pointer arithmetic produces an empty string rather than the real
filename. This would be masked on Linux CI, since glibc's `dirname()`
happens to modify common inputs in place there.
Fix: split on `strrchr(rel_path, '/')` against a buffer we fully
control, rather than depending on `dirname()`'s implementation-defined
behavior. Verified the new logic against a slash path, a no-slash
path, and a single-level path via a standalone reproduction (output in
the issue), and that the real codebase still builds cleanly under
`-Werror`.
There's no existing test for incremental backups in this repo to build
on, so I haven't exercised this through a real backup run end-to-end --
said so plainly in the issue rather than overclaiming. Happy to add a
test case here if that's wanted, per the "write test cases that expose
corner-case bugs" guidance.