Repository navigation
config: handle allocation failures in config_list - #7429
Open
cristianchiriac wants to merge 1 commit into
Open
cristianchiriac wants to merge 1 commit into
cristianchiriac wants to merge 1 commit into
Conversation
git_config_list_append did not check the allocation of a new map head, so it stored NULL in the map and then wrote through it. It now allocates the list entry first and frees both on failure, which leaves the map unchanged. git_config_list_dup did not keep the error from duplicating an entry, so it freed the partial list and returned 0 without setting *out. Fixes libgit2#7416 Fixes libgit2#7417
This branch has not been deployed
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 #7416. Fixes #7417.
Both issues are in
src/libgit2/config_list.c, and an allocation-failure sweep over opening and snapshotting a config hits both, so they're fixed together:git_config_list_append: thegit__callocof a new map head wasn't checked. On failure,NULLwent into the map and was then written through. The list entry is now allocated first. If the map head allocation or theheadmap_putfails, both are freed and the map is left unchanged. Before, a failed list allocation also left the map pointing at an entry that the caller then freed.git_config_list_dup: the result ofgit_config_list_dup_entrywasn't assigned toerror. On failure, the partial list was freed and the function returned 0 without setting*out.Test:
config::oom::open_and_snapshot_fail_or_succeedwrites a small config with a multivar and a subsection. It then opens the config, snapshots it and reads two values, with an allocator that fails the Nth allocation. It does this for every N until no allocation fails. Each run must either report an error or return the values in the file. This is the same pattern asblame::oomin #7425.All tests in
-sconfigpass (MinGW gcc 16, Windows 11).