summaryrefslogtreecommitdiff
path: root/git-compat-util.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-09-26 23:09:19 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-09-26 23:09:19 (GMT)
commit6a67695268562f67babdb7d5195c8a43cc4015fa (patch)
treeb5bbacc08e466f6de62cf2e9fd450d71ef0ea6c7 /git-compat-util.h
parent31b83f361bd962e9c5f96bf7714051d77f592af2 (diff)
parentb7d36ffca02c23f545d6e098d78180e6e72dfd8d (diff)
downloadgit-6a67695268562f67babdb7d5195c8a43cc4015fa.zip
git-6a67695268562f67babdb7d5195c8a43cc4015fa.tar.gz
git-6a67695268562f67babdb7d5195c8a43cc4015fa.tar.bz2
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 'git-compat-util.h')
-rw-r--r--git-compat-util.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index 37cce07..8aab0c3 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -977,6 +977,19 @@ void git_qsort(void *base, size_t nmemb, size_t size,
#define qsort git_qsort
#endif
+#ifndef REG_STARTEND
+#error "Git requires REG_STARTEND support. Compile with NO_REGEX=NeedsStartEnd"
+#endif
+
+static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,
+ size_t nmatch, regmatch_t pmatch[], int eflags)
+{
+ assert(nmatch > 0 && pmatch);
+ pmatch[0].rm_so = 0;
+ pmatch[0].rm_eo = size;
+ return regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND);
+}
+
#ifndef DIR_HAS_BSD_GROUP_SEMANTICS
# define FORCE_DIR_SET_GID S_ISGID
#else