Skip to content

[#1724] Fix AddressSanitizer SEGV in test_restore/test_utils, check.sh cleanup, and CI regressions - #1725

Merged
Pranav-error merged 1 commit into
pgmoneta:mainfrom
manishpatel00:issue1724_mkdir_asan_fix
Nov 29, 2026
Merged

Pranav-error merged 1 commit into
pgmoneta:mainfrom
manishpatel00:issue1724_mkdir_asan_fix

Conversation

@manishpatel00

@manishpatel00 manishpatel00 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1724
Fixes #1722

Description

This PR resolves the current test suite and CI compilation failures on main:

  1. AddressSanitizer SEGV: Tests in test_restore.c and test_utils.c passed string literals to pgmoneta_mkdir(), which modifies path separators in-place. Because string literals reside in read-only memory, this triggered an ASan write violation. Defining the test path variables as stack-allocated mutable arrays (char src[] = ...) resolves the crash without altering pgmoneta_mkdir() in utils.c.
  2. Tablespace Cleanup Permission: PostgreSQL creates /tmp/pgmoneta_tblspc subdirectories with mode 700. In check.sh, cleanup now uses sudo to reliably remove these directories in non-root test environments.
  3. Static Analysis & Strict Prototypes: Added a NULL check following malloc in pgmoneta_art_iterator_create(), added strict prototype void to pgmoneta_validate_muse_configuration(void) to resolve GCC compilation failure on main, and updated the cppcheck baseline for art.c and migration_pgbackrest.c.

Rebased on the latest main and squashed into a single commit.

@manishpatel00
manishpatel00 force-pushed the issue1724_mkdir_asan_fix branch from 65bdf9c to 2030291 Compare November 27, 2026 05:24
@manishpatel00 manishpatel00 changed the title [#1724] Fix AddressSanitizer SEGV in pgmoneta_mkdir on string literals and check.sh cleanup [#1724] Fix AddressSanitizer SEGV in pgmoneta_mkdir, check.sh cleanup, and art.c allocation Nov 27, 2026

@Pranav-error Pranav-error left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up. main has been red since dd85549 and this is the right crash: on the clang Debug jobs of main (run 45869251661), ASan reports a write SEGV in pgmoneta_mkdir (utils.c:1213) called from test_pgmoneta_copy_postgresql_restore_excludes_last_files (test_restore.c:218). pgmoneta_mkdir() puts a '\0' at each / and restores it, and the test passes string literals. The char x[] = "..." change in test_restore.c and test_utils.c fixes that on its own.

I'm not sure about the utils.c change, though:

  1. It is not needed for the crash once the tests pass arrays.
  2. It makes pgmoneta_mkdir() return 1 for any path of MAX_PATH (1024) characters or more, where mkdir(2) on Linux accepts up to PATH_MAX (4096). Several callers build the path with pgmoneta_append() without a cap, e.g. to_tblspc (restore.c:3495), to_directory (restore.c:3571), and most callers do not check the return value, so a long path would now fail quietly later instead of being created.

Could you drop the utils.c part and keep the test fix? If the idea is to also protect callers that only have a const char* (like pgmoneta_wal_store_create(), which casts downstream_dir at wal_store.c:769), a heap copy with no length limit would keep the current behavior for long paths.

The art.c NULL check and the baseline update look right (static-analysis passes with 13), and $SUDO is set at the top of check.sh (lines 91-95), so the cleanup change is fine.

@Pranav-error

Copy link
Copy Markdown
Collaborator

Hi @manishpatel00, any update on the review points above? main's clang Debug jobs are red on this pgmoneta_mkdir crash, so this is blocking the queue. Happy to re-test as soon as you push.

@manishpatel00
manishpatel00 force-pushed the issue1724_mkdir_asan_fix branch from 2030291 to c1c9e9f Compare November 29, 2026 13:56
@manishpatel00 manishpatel00 changed the title [#1724] Fix AddressSanitizer SEGV in pgmoneta_mkdir, check.sh cleanup, and art.c allocation [#1724] Fix AddressSanitizer SEGV in test_restore/test_utils, check.sh cleanup, and art.c allocation Nov 29, 2026
@manishpatel00

Copy link
Copy Markdown
Contributor Author

Hi @Pranav-error,

Thanks for the thoughtful review! You make a great point regarding utils.c and path limits.

I have:

  1. Dropped the changes to src/libpgmoneta/utils.c entirely, keeping pgmoneta_mkdir() untouched.
  2. Kept the char src[] = ... stack array fixes in test_restore.c and test_utils.c, which cleanly eliminates the ASan write SEGV.
  3. Kept the $SUDO cleanup in check.sh and the art.c allocation NULL check / baseline update.
  4. Rebased onto the latest main (72a4f7e) and squashed into a single clean commit.

Ready for re-testing. Thank you!

… check.sh cleanup, and CI regressions

Use mutable char arrays in test_restore.c and test_utils.c exclusion tests
to avoid AddressSanitizer SEGV write violations caused by pgmoneta_mkdir()
modifying directory separators in-place. Run tablespace directory cleanup
in check.sh with $SUDO.

In addition, check allocation in pgmoneta_art_iterator_create() to resolve
the nullPointerOutOfMemory cppcheck finding (pgmoneta#1722), add a strict prototype
for pgmoneta_validate_muse_configuration(void), and update the baseline for
art.c and migration_pgbackrest.c.

Fixes pgmoneta#1724
Fixes pgmoneta#1722

Signed-off-by: Manish Kumar <[email protected]>
@manishpatel00
manishpatel00 force-pushed the issue1724_mkdir_asan_fix branch from c1c9e9f to a4313da Compare November 29, 2026 14:09
@manishpatel00 manishpatel00 changed the title [#1724] Fix AddressSanitizer SEGV in test_restore/test_utils, check.sh cleanup, and art.c allocation [#1724] Fix AddressSanitizer SEGV in test_restore/test_utils, check.sh cleanup, and CI regressions Nov 29, 2026
@manishpatel00

manishpatel00 commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @Pranav-error,

Update on the latest push:

  1. Dropped utils.c change: Completely reverted pgmoneta_mkdir() in utils.c. The crash is cleanly resolved purely via the mutable stack array fix (char src[] = ...) in test_restore.c and test_utils.c.
  2. Kept check.sh and art.c fixes: Kept the $SUDO tablespace cleanup in check.sh and the allocation NULL check in art.c with baseline update.
  3. Fixed new GCC/CI regression from Support migrating other backups to pgmoneta #1681 on main: pgmoneta_validate_muse_configuration() was missing void in prototype/definition, failing GCC with -Werror=strict-prototypes, and added baseline entry for migration_pgbackrest.c.
  4. Clean 1 commit: Rebased on latest main and squashed into a single clean commit.

All 13 CI checks have completed and passed (including static analysis, format check, storage engines, and all Clang/GCC debug & release matrix builds). Ready for review and merge whenever you are ready. Thank you!

@Pranav-error
Pranav-error merged commit a4313da into pgmoneta:main Nov 29, 2026
13 checks passed
@Pranav-error

Copy link
Copy Markdown
Collaborator

Merged.

Thanks for your contribution !

@manishpatel00
manishpatel00 deleted the issue1724_mkdir_asan_fix branch November 29, 2026 19:01
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.

AddressSanitizer SEGV in pgmoneta_mkdir and check.sh tablespace cleanup failure Static analysis failure: unchecked allocation in art.c

2 participants