summaryrefslogtreecommitdiff
path: root/grep.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2016-09-26 16:09:19 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2016-09-26 16:09:19 -0700
commit6a67695268562f67babdb7d5195c8a43cc4015fa (patch)
treeb5bbacc08e466f6de62cf2e9fd450d71ef0ea6c7 /grep.c
parentMerge branch 'nd/checkout-disambiguation' (diff)
parentregex: use regexec_buf() (diff)
downloadtgif-6a67695268562f67babdb7d5195c8a43cc4015fa.tar.xz
Merge branch 'js/regexec-buf'
Some codepaths in "git diff" used regexec(3) on a buffer that was mmap(2)ed, which may not have a terminating NUL, leading to a read beyond the end of the mapped region. This was fixed by introducing a regexec_buf() helper that takes a <ptr,len> pair with REG_STARTEND extension. * js/regexec-buf: regex: use regexec_buf() regex: add regexec_buf() that can work on a non NUL-terminated string regex: -G<pattern> feeds a non NUL-terminated string to regexec() and fails
Diffstat (limited to 'grep.c')
-rw-r--r--grep.c14
1 files changed, 2 insertions, 12 deletions
diff --git a/grep.c b/grep.c
index d7d00b87cb..1194d35b5d 100644
--- a/grep.c
+++ b/grep.c
@@ -898,17 +898,6 @@ static int fixmatch(struct grep_pat *p, char *line, char *eol,
}
}
-static int regmatch(const regex_t *preg, char *line, char *eol,
- regmatch_t *match, int eflags)
-{
-#ifdef REG_STARTEND
- match->rm_so = 0;
- match->rm_eo = eol - line;
- eflags |= REG_STARTEND;
-#endif
- return regexec(preg, line, 1, match, eflags);
-}
-
static int patmatch(struct grep_pat *p, char *line, char *eol,
regmatch_t *match, int eflags)
{
@@ -919,7 +908,8 @@ static int patmatch(struct grep_pat *p, char *line, char *eol,
else if (p->pcre_regexp)
hit = !pcrematch(p, line, eol, match, eflags);
else
- hit = !regmatch(&p->regexp, line, eol, match, eflags);
+ hit = !regexec_buf(&p->regexp, line, eol - line, 1, match,
+ eflags);
return hit;
}