Skip to content

[#1496] Don't free the result of pgmoneta_get_user_name() in test_utils_missing_basic - #1497

Closed
lookslikeameya wants to merge 1 commit into
pgmoneta:mainfrom
lookslikeameya:test-utils-user-name-free
Closed

lookslikeameya wants to merge 1 commit into
pgmoneta:mainfrom
lookslikeameya:test-utils-user-name-free

Conversation

@lookslikeameya

Copy link
Copy Markdown
Contributor

Fixes #1496.

pgmoneta_get_user_name() returns pw_name from getpwuid(), which the C library owns, but test_utils_missing_basic freed it. On macOS that aborts the whole test runner, so no summary is printed and the tests after it don't run. On glibc the free() happens to succeed because pw_name is the start of glibc's internal buffer, but the next getpwuid() would then use freed memory.

The test no longer frees it, and the header comment now says not to. The function itself is unchanged; its only other caller (admin.c) already uses it correctly.

Tested:

  • macOS 26.5.2 (arm64), PG17, test/check.sh -m utils: 64/65 pass, including test_utils_missing_basic. Before, the run aborted with no summary. The remaining failure, test_utils_misc (pgmoneta_backtrace_string()), also fails on main and is unrelated (will be working on that soon)
  • Full test/check.sh on macOS now runs all 297 tests instead of stopping in utils. The other failures also fail on main, mostly the incremental backup crash fixed by [#1470] Fix incremental backups on macOS #1472.
  • Rocky Linux 10 (aarch64) container set up like the CI Linux job, clang Debug with ASan, PG17, test/check.sh ci -m utils: 65/65 pass, no sanitizer reports.

@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 @lookslikeameya. I checked this: pgmoneta_get_user_name() returns pw->pw_name directly, and the only other caller (admin.c) just passes it to warnx(). Freeing it the way the test did: on macOS 26.7.1 the process dies inside free() (exit status 133), and on glibc the free() goes through, but under ASan the next getpwuid() reports a heap-use-after-free, as you described. The header comment is a good addition. LGTM.

@lookslikeameya

Copy link
Copy Markdown
Contributor Author

Thanks for testing :)

@jesperpedersen

Copy link
Copy Markdown
Member

Please, rebase

@lookslikeameya
lookslikeameya force-pushed the test-utils-user-name-free branch from db4f82f to bdfa1f5 Compare November 11, 2026 22:41
@jesperpedersen

Copy link
Copy Markdown
Member

Rebased and merged.

Thanks for your contribution !

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.

test_utils_missing_basic frees the result of pgmoneta_get_user_name()

3 participants