threads / patch / 54692

patch, 2 partsFix a segfault in git log --notes

Subject: [PATCH 0/2] Fix a segfault in git log --notes

## tl;dr

5 messages between Nov 23, 2020 and Nov 23, 2020. Diffs are folded; open one to read it.

replies: 4people: 2as markdown or json

nate@roosteregg.cc· Nov 23, 2020, 03:23 UTC · lore
From: Nate Avers <nate@roosteregg.cc>
Hi,

I came across a segfault in git log --notes (also affects diff-tree) when notes.displayRef is configured with no value (not an empty value). It appears to stem from a missing return statement in notes.c:notes_display_config(). Very small fix. (Not sure how much sense it makes to include the test.)

Thanks, Nate

Nate Avers (2):
  notes.c: fix a segfault in notes_display_config()
  t3301: test proper exit response to no-value notes.displayRef.
 notes.c          | 2 +-
 t/t3301-notes.sh | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)
-- 
2.27.0
nate@roosteregg.cc· Nov 23, 2020, 03:23 UTC · re: nate@roosteregg.cc · lore

[PATCH 1/2] notes.c: fix a segfault in notes_display_config()

From: Nate Avers <nate@roosteregg.cc>

If notes.displayRef is configured with no value[1], control should be returned to the caller when notes.c:notes_display_config() checks if 'v' is NULL. Otherwise, both git log --notes and git diff-tree --notes will subsequently segfault when refs.h:has_glob_specials() calls strpbrk() with a NULL first argument.

[1] Examples:
.git/config:
[notes]
	displayRef
$ git -c notes.displayRef [...]
Signed-off-by: Nate Avers <nate@roosteregg.cc>
---
 notes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to notes.c +1 −1
diff --git a/notes.c b/notes.c
index 564baac64d..d5ac081e76 100644
--- a/notes.c
+++ b/notes.c
@@ -970,7 +970,7 @@ static int notes_display_config(const char *k, const char *v, void *cb)
 
 	if (*load_refs && !strcmp(k, "notes.displayref")) {
 		if (!v)
-			config_error_nonbool(k);
+			return config_error_nonbool(k);
 		string_list_add_refs_by_glob(&display_notes_refs, v);
 	}
 
-- 
2.27.0
Junio C Hamano· Nov 23, 2020, 06:59 UTC · re: nate@roosteregg.cc · lore

Re: [PATCH 1/2] notes.c: fix a segfault in notes_display_config()

nate@roosteregg.cc writes:
>  	if (*load_refs && !strcmp(k, "notes.displayref")) {
>  		if (!v)
> -			config_error_nonbool(k);
> +			return config_error_nonbool(k);

"git grep config_error_nonbool" tells us that this is the only instance that ignores the return value from the function and does not cause the caller to die.

Looks good.  Thanks.
nate@roosteregg.cc· Nov 23, 2020, 03:23 UTC · re: nate@roosteregg.cc · lore

[PATCH 2/2] t3301: test proper exit response to no-value notes.displayRef.

From: Nate Avers <nate@roosteregg.cc>
Signed-off-by: Nate Avers <nate@roosteregg.cc>
---
 t/t3301-notes.sh | 5 +++++
 1 file changed, 5 insertions(+)
Show changes to t/t3301-notes.sh +5 −0
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index 8f43303007..ca60faf480 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -672,6 +672,11 @@ test_expect_success 'notes.displayRef respects order' '
 	test_cmp expect-both-reversed actual
 '
 
+test_expect_success 'notes.displayRef with no value handled gracefully' '
+	test_must_fail git -c notes.displayRef log -0 --notes &&
+	test_must_fail git -c notes.displayRef diff-tree --notes HEAD
+'
+
 test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
 	GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
 		git log -2 >actual &&
-- 
2.27.0
Junio C Hamano· Nov 23, 2020, 18:44 UTC · re: nate@roosteregg.cc · lore

Re: [PATCH 2/2] t3301: test proper exit response to no-value notes.displayRef.

nate@roosteregg.cc writes:
Show 19 quoted lines
> From: Nate Avers <nate@roosteregg.cc>
>
> Signed-off-by: Nate Avers <nate@roosteregg.cc>
> ---
>  t/t3301-notes.sh | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
> index 8f43303007..ca60faf480 100755
> --- a/t/t3301-notes.sh
> +++ b/t/t3301-notes.sh
> @@ -672,6 +672,11 @@ test_expect_success 'notes.displayRef respects order' '
>  	test_cmp expect-both-reversed actual
>  '
>  
> +test_expect_success 'notes.displayRef with no value handled gracefully' '
> +	test_must_fail git -c notes.displayRef log -0 --notes &&
> +	test_must_fail git -c notes.displayRef diff-tree --notes HEAD
> +'

Looks good. I didn't know we can feed the "no assignment means true" configuration from the command line with "git -c" ;-)

>  test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
>  	GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
>  		git log -2 >actual &&

← back to recent threads