Skip to content

Commit 57009b1

Browse files
committed
Merge branch 'js/regexec-buf' into maint
Fix for potential segv introduced in v2.11.0 and later (also v2.10.2). * js/regexec-buf: pickaxe: fix segfault with '-S<...> --pickaxe-regex'
2 parents fd3ab91 + f53c5de commit 57009b1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

diffcore-pickaxe.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,15 @@ static unsigned int contains(mmfile_t *mf, regex_t *regexp, kwset_t kws)
8181
regmatch_t regmatch;
8282
int flags = 0;
8383

84-
while (*data &&
84+
while (sz && *data &&
8585
!regexec_buf(regexp, data, sz, 1, &regmatch, flags)) {
8686
flags |= REG_NOTBOL;
8787
data += regmatch.rm_eo;
88-
if (*data && regmatch.rm_so == regmatch.rm_eo)
88+
sz -= regmatch.rm_eo;
89+
if (sz && *data && regmatch.rm_so == regmatch.rm_eo) {
8990
data++;
91+
sz--;
92+
}
9093
cnt++;
9194
}
9295

t/t4062-diff-pickaxe.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ test_expect_success '-G matches' '
1919
test 4096-zeroes.txt = "$(cat out)"
2020
'
2121

22+
test_expect_success '-S --pickaxe-regex' '
23+
git diff --name-only -S0 --pickaxe-regex HEAD^ >out &&
24+
verbose test 4096-zeroes.txt = "$(cat out)"
25+
'
26+
2227
test_done

0 commit comments

Comments
 (0)