summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2017-03-28 13:52:24 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-03-28 13:52:24 -0700
commit57009b1dd9ac63b0cb0d9f5a78f69ce4e5837768 (patch)
tree4250a0ca6b08555cac3977f9e34297d5a62d0c00
parentMerge branch 'jk/execv-dashed-external' into maint (diff)
parentpickaxe: fix segfault with '-S<...> --pickaxe-regex' (diff)
downloadtgif-57009b1dd9ac63b0cb0d9f5a78f69ce4e5837768.tar.xz
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'
-rw-r--r--diffcore-pickaxe.c7
-rwxr-xr-xt/t4062-diff-pickaxe.sh5
2 files changed, 10 insertions, 2 deletions
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index 9795ca1c15..341529b5a8 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -81,12 +81,15 @@ static unsigned int contains(mmfile_t *mf, regex_t *regexp, kwset_t kws)
regmatch_t regmatch;
int flags = 0;
- while (*data &&
+ while (sz && *data &&
!regexec_buf(regexp, data, sz, 1, &regmatch, flags)) {
flags |= REG_NOTBOL;
data += regmatch.rm_eo;
- if (*data && regmatch.rm_so == regmatch.rm_eo)
+ sz -= regmatch.rm_eo;
+ if (sz && *data && regmatch.rm_so == regmatch.rm_eo) {
data++;
+ sz--;
+ }
cnt++;
}
diff --git a/t/t4062-diff-pickaxe.sh b/t/t4062-diff-pickaxe.sh
index f0bf50bda7..7c4903f497 100755
--- a/t/t4062-diff-pickaxe.sh
+++ b/t/t4062-diff-pickaxe.sh
@@ -19,4 +19,9 @@ test_expect_success '-G matches' '
test 4096-zeroes.txt = "$(cat out)"
'
+test_expect_success '-S --pickaxe-regex' '
+ git diff --name-only -S0 --pickaxe-regex HEAD^ >out &&
+ verbose test 4096-zeroes.txt = "$(cat out)"
+'
+
test_done