Skip to content

config: preserve entry ownership when list append fails - #7469

Open
LittleNewton wants to merge 1 commit into
libgit2:mainfrom
LittleNewton:fix/config-list-append-oom
Open

LittleNewton wants to merge 1 commit into
libgit2:mainfrom
LittleNewton:fix/config-list-append-oom

Conversation

@LittleNewton

Copy link
Copy Markdown

An allocation failure in git_config_list_append() can insert a NULL map head and then dereference it. Other failures can leak the new map head or modify the map and a multivar entry's name before the list node is allocated. A caller cannot reliably clean up or retry the rejected entry in that state.

Allocate the list node first, check the map-head allocation, and release temporary nodes if map insertion fails. After any append failure, the caller still owns an unchanged entry and existing configuration entries retain their values and multivar status. Document this internal ownership contract and release rejected entries in the file and memory configuration backends.

Add three focused allocation-failure sweeps for an empty list, hash-map growth, and multivar append. Each verifies the error, unchanged entry ownership and existing contents, successful retry of the same entry, and list destruction. The allocator delegates to the active allocator, including DEBUG_STRICT_ALLOC builds.

Fixes #7416. Related to #7429: its existing fix already addresses the unchecked allocation and allocation ordering. This is an overlapping, append-focused alternative with explicit ownership/retry regressions and cleanup in both configuration backends; it does not claim first discovery or supersede that PR's broader fixes (including #7417). Thank you to the original reporter and the author of #7429.

Validation

Tested on Linux x86_64 against 42a89d7cc9374a19e72fa57011e5fe3a99c7b3bf:

  • Before the production changes, the new empty-list regression crashes under AddressSanitizer with a NULL write at config_list.c:178.
  • After the changes, all three regressions pass. The complete -sconfig suite passes with AddressSanitizer and separately with DEBUG_STRICT_ALLOC=ON: 157 passed, 1 skipped in each build. Builds use ENABLE_WERROR=ON.
  • The complete offline suite with the strict allocator: 3,080 passed, 44 skipped, 1 failure in core::structinit::compare (padding-byte comparison). The same test fails in a complete offline run of unmodified upstream.
  • Utility suite with AddressSanitizer: 444 passed, 6 skipped, 1 failure in path::core::validate_current_user_ownership. The same failure reproduces on unmodified upstream in this container.
  • The initial offline run inherited lowercase proxy variables, causing three HTTP-proxy assertion failures. All four proxy tests pass with those variables removed from the test process.
  • LeakSanitizer cannot run in this container (fatal process-inspection error). The completed ASan runs use ASAN_OPTIONS=detect_leaks=0:abort_on_error=1; no successful leak-check run is claimed.

Focused regression command:

ASAN_OPTIONS=detect_leaks=0:abort_on_error=1 ./build/libgit2_tests -sconfig::list

Allocate the list node before mutating the map or sharing multivar names.
Check map-head allocation and release temporary nodes when insertion fails,
so an unsuccessful append leaves the entry owned by its caller. Release
rejected entries in the file and memory configuration backends.

Add allocation-failure sweeps that verify unchanged contents and ownership,
retrying the same entry, and destruction for new keys, map growth and
multivars. Wrap the active allocator to support strict allocator builds.

This overlaps the append fix in libgit2#7429, with focused ownership
and retry tests and cleanup in both configuration backends. Credit the
existing report and fix; this does not claim first discovery.

Fixes libgit2#7416.

This branch has not been deployed

No deployments
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.

[BUG] NULL deref in git_config_list_append on allocation failure

1 participant