[PATCH 0/2] grep: tolerate NULL argument to free_grep_expr()
- From
Taylor Blau <me@ttaylorr.com>
- Date
- Oct 10, 2022, 17:41 UTC
- Message-ID
- <cover.1665423686.git.me@ttaylorr.com>
- In-Reply-To
- <o2ijhZAUIi7nPTwQmsJfpvPIEeLbhvn1AP8rhW2hCNbC380Z2ogDHzZigqJsHI6RwphsIZR3OSJSy-wYvyWv5un632tKynHKFLFPLPEDH2g=@protonmail.com>
This short series demonstrates and fixes a bug whereby a NULL `struct grep_expr*` argument (such as when running `git log --invert-grep` without a `--grep` argument) could cause us to segfault when trying to dereference that argument.
An alternative approach is to disallow `--invert-grep` without a `--grep` argument. But a more user-friendly approach is to permit this combination by pretending as if neither argument was given. This patch series takes the latter approach by teaching free_grep_expr() that passing a NULL argument should result in a noop, not a segfault.
Taylor Blau (2): t4202: demonstrate `git log --invert-grep` segfault grep.c: tolerate NULL grep_expr in free_pattern_expr()
grep.c | 5 +++-- t/t4202-log.sh | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-)
-- 2.37.0.1.g1379af2e9d