You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Refactor ConfigEntry and related iterators for safer memory management - #1499
ConfigEntry is holding on to git_config_entry pointers for its entire lifespan, but this isn't safe or necessary. When getting a single entry without an iterator, this isn't really a concern. However, when entries are iterated with git_config_next, the previously-allocated iterator entry object is re-used. If ConfigEntry is still holding onto the git_config_entry, its values could change inappropriately and unexpectedly. The solution to this is to eagerly copy the underlying C values into the Python structure and move on.
Additionally, git_config_entry_free should never be used for iterated entries. Freeing the iterator automatically frees any entries it allocated, and manually freeing the entry can cause a crash. git_config_entry_free should be called only for entries retrieved without an iterator.
This pull request, which is a subset of the changes initially proposed in #1473, fixes this memory misuse by refactoring ConfigEntry and its related iterators.
No tests for the fix. A memory-safety refactor of this size (+201/−93 in config.py) ships with zero test changes. Please add regression tests, e.g.: collect list(config) and assert values remain intact after iteration ends; interleave two iterators and assert earlier entries aren't corrupted; valueless-key get_bool behavior. These are exactly the scenarios from Access violation accessing repo config entries #970.
Docstring: multivar "first value" is wrong. The new get_bool/get_int docstrings say "If the config var found is a multivar, only the first value is returned." Verified: git_config_get_entry returns the last value (['first', 'last'] → get_entry gives 'last'), matching git config --get semantics.
Docstring: "empty value" listed as truthy is wrong. get_bool/parse_bool say truthy values include "an empty value / NULL". Verified: Config.parse_bool('') is False (empty string is falsy); only a missing/NULL value is truthy. Suggest "a missing value (NULL)".
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
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.
ConfigEntryis holding on togit_config_entrypointers for its entire lifespan, but this isn't safe or necessary. When getting a single entry without an iterator, this isn't really a concern. However, when entries are iterated withgit_config_next, the previously-allocated iterator entry object is re-used. IfConfigEntryis still holding onto thegit_config_entry, its values could change inappropriately and unexpectedly. The solution to this is to eagerly copy the underlying C values into the Python structure and move on.Additionally,
git_config_entry_freeshould never be used for iterated entries. Freeing the iterator automatically frees any entries it allocated, and manually freeing the entry can cause a crash.git_config_entry_freeshould be called only for entries retrieved without an iterator.This pull request, which is a subset of the changes initially proposed in #1473, fixes this memory misuse by refactoring
ConfigEntryand its related iterators.