From c3eb95a0d759d80d53ccb396627c400cd3db6e6d Mon Sep 17 00:00:00 2001 From: Nate Avers Date: Sun, 22 Nov 2020 22:23:41 -0500 Subject: [PATCH 1/2] notes.c: fix a segfault in notes_display_config() 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 Signed-off-by: Junio C Hamano --- notes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notes.c b/notes.c index 03e7d0cd2dd..928dde8b347 100644 --- a/notes.c +++ b/notes.c @@ -967,7 +967,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); } From 45fef1599af19404a7d0d80a985b303d665ef4a3 Mon Sep 17 00:00:00 2001 From: Nate Avers Date: Sun, 22 Nov 2020 22:23:42 -0500 Subject: [PATCH 2/2] t3301: test proper exit response to no-value notes.displayRef. Signed-off-by: Nate Avers Signed-off-by: Junio C Hamano --- t/t3301-notes.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh index d3fa298c6a1..d3694fad8a7 100755 --- a/t/t3301-notes.sh +++ b/t/t3301-notes.sh @@ -653,6 +653,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 &&