forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix git log --graph -u
hangs
#5193
Merged
dscho
merged 3 commits into
git-for-windows:main
from
derrickstolee:line-log-use-after-free
Oct 7, 2024
Merged
Fix git log --graph -u
hangs
#5193
dscho
merged 3 commits into
git-for-windows:main
from
derrickstolee:line-log-use-after-free
Oct 7, 2024
Conversation
This file contains 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
The output_prefix() method in line-log.c may call a function pointer via the diff_options struct. This function pointer returns a strbuf struct and then its buffer is passed back. However, that implies that the consumer is responsible to free the string. This is especially true because the default behavior is to duplicate the empty string. The existing functions used in the output_prefix pointer include: 1. idiff_prefix_cb() in diff-lib.c. This returns the data pointer, so the value exists across multiple calls. 2. diff_output_prefix_callback() in graph.c. This uses a static strbuf struct, so it reuses buffers across calls. These should not be freed. 3. output_prefix_cb() in range-diff.c. This is similar to the diff-lib.c case. In each case, we should not be freeing this buffer. We can convert the output_prefix() function to return a const char pointer and stop freeing the result. This choice is essentially the opposite of what was done in 394affd (line-log: always allocate the output prefix, 2024-06-07). This was discovered via 'valgrind' while investigating a public report of a bug in 'git log --graph -L' [1]. [1] git-for-windows#5185 This issue would have been caught by the new test, when Git is compiled with ASan to catch these double frees. Co-authored-by: Jeff King <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Derrick Stolee <[email protected]>
Now that output_prefix() returns a const char * type, it matches the behavior of diff_line_prefix() and no longer needs to exist on its own. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Derrick Stolee <[email protected]>
The uses of the output_prefix function pointer in the diff_options struct is currently difficult to work with by returning a pointer to a strbuf. There is only one use that cares about the length of the string, which appears to be the only justification of the return type. We already noticed confusing memory issues around this return type, so use a const char * return type to make it clear that the caller does not own this string buffer. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Derrick Stolee <[email protected]>
derrickstolee
approved these changes
Oct 7, 2024
dscho
added a commit
to dscho/git
that referenced
this pull request
Oct 8, 2024
This fixes git-for-windows#5185 by backporting gitgitgadget#1806 (which, sadly, seems not to have made it into Git v2.47.0).
git-for-windows-ci
pushed a commit
that referenced
this pull request
Oct 8, 2024
This fixes #5185 by backporting gitgitgadget#1806 (which, sadly, seems not to have made it into Git v2.47.0).
dscho
added a commit
that referenced
this pull request
Oct 8, 2024
This fixes #5185 by backporting gitgitgadget#1806 (which, sadly, seems not to have made it into Git v2.47.0).
git-for-windows-ci
pushed a commit
that referenced
this pull request
Oct 9, 2024
This fixes #5185 by backporting gitgitgadget#1806 (which, sadly, seems not to have made it into Git v2.47.0).
git-for-windows-ci
pushed a commit
that referenced
this pull request
Oct 9, 2024
This fixes #5185 by backporting gitgitgadget#1806 (which, sadly, seems not to have made it into Git v2.47.0).
dscho
added a commit
that referenced
this pull request
Oct 9, 2024
This fixes #5185 by backporting gitgitgadget#1806 (which, sadly, seems not to have made it into Git v2.47.0).
dscho
added a commit
that referenced
this pull request
Oct 11, 2024
This fixes #5185 by backporting gitgitgadget#1806 (which, sadly, seems not to have made it into Git v2.47.0).
dscho
added a commit
that referenced
this pull request
Nov 22, 2024
This fixes #5185 by backporting gitgitgadget#1806 (which, sadly, seems not to have made it into Git v2.47.0).
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.
This fixes #5185 by backporting gitgitgadget#1806 (which, sadly, seems not to have made it into Git v2.47.0).