git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] t4202: demonstrate `git log --invert-grep` segfault

From
Taylor Blau <me@ttaylorr.com>
Date
Oct 10, 2022, 17:41 UTC
Message-ID
<fa27aca12c46d2934baa594c05b7b3d7672e0be6.1665423686.git.me@ttaylorr.com>
In-Reply-To
<cover.1665423686.git.me@ttaylorr.com>

When `--invert-grep` is given without a pattern, `git log` behaves as normal. But as of f41fb662f5 (revisions API: have release_revisions() release "grep_filter", 2022-04-13), this doesn't quite work because we try to dereference the NULL `grep_expr` pointer in `free_pattern_expr()`, leading to a sgefault.

The subsequent patch will explain the bug, provide a fix, and update this test to expect success.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 t/t4202-log.sh | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index cc15cb4ff6..e3ec5f5661 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -297,6 +297,12 @@ test_expect_success 'log --invert-grep --grep -i' '
 	fi
 '
 
+test_expect_failure 'log --invert-grep (no --grep)' '
+	git log --pretty="tformat:%s" >expect &&
+	git log --invert-grep --pretty="tformat:%s" >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'log --grep option parsing' '
 	echo second >expect &&
 	git log -1 --pretty="tformat:%s" --grep sec >actual &&
-- 
2.37.0.1.g1379af2e9d
Previous: Taylor BlauNext: Taylor Blau
Message 13 of 18 in “Git BUG 2.37.3 and 2.38.0”
  1. orygawOct 10, 2022
  2. rsbecker@nexbridge.comOct 10, 2022
  3. Taylor BlauOct 10, 2022
  4. Junio C HamanoOct 10, 2022
  5. log: require --grep for --invert-grep and --all-match, fix segfaultÆvar Arnfjörð Bjarmason, Oct 10, 2022
  6. Junio C HamanoOct 10, 2022
  7. Junio C HamanoOct 10, 2022
  8. Ævar Arnfjörð BjarmasonOct 10, 2022
  9. Taylor BlauOct 10, 2022
  10. grep.c: remove "extended" in favor of "pattern_expression", fix segfaultÆvar Arnfjörð Bjarmason, Oct 11, 2022
  11. Junio C HamanoOct 11, 2022
  12. 0/2 grep: tolerate NULL argument to free_grep_expr()Taylor Blau, Oct 10, 2022
  13. 1/2 t4202: demonstrate `git log --invert-grep` segfaultTaylor Blau, Oct 10, 2022
  14. 2/2 grep.c: tolerate NULL grep_expr in free_pattern_expr()Taylor Blau, Oct 10, 2022
  15. Junio C HamanoOct 10, 2022
  16. Taylor BlauOct 10, 2022
  17. Junio C HamanoOct 10, 2022
  18. Taylor BlauOct 10, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.