diff options
author | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2016-02-06 16:54:14 +0000 |
---|---|---|
committer | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2016-02-06 16:54:14 +0000 |
commit | 3da5528b47b88c32224cf9d14d8a4e80cd7a0815 (patch) | |
tree | 667010d32d2e7d8436fc1e6ec9eaa31784c7f23b | |
parent | 662911d355f62321074629645ceb6f5ccf5e1a03 (diff) | |
download | pcre-3da5528b47b88c32224cf9d14d8a4e80cd7a0815.tar.gz |
Fix pcretest bad behaviour for callout in lookbehind.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1625 2f5784b3-3f2a-0410-8824-cb99058d5e15
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | pcretest.c | 14 | ||||
-rw-r--r-- | testdata/testinput2 | 4 | ||||
-rw-r--r-- | testdata/testoutput2 | 15 |
4 files changed, 33 insertions, 4 deletions
@@ -49,6 +49,10 @@ Version 8.39 xx-xxxxxx-201x 12. Assertion code generator in JIT has been optimized. +13. A pattern such as /(?<=((?C)0))/, which has a callout inside a lookbehind + assertion, caused pcre2test to generate incorrect output, and also to read + uninitialized memory (detected by ASAN or valgrind). + Version 8.38 23-November-2015 ----------------------------- @@ -2250,7 +2250,7 @@ data is not zero. */ static int callout(pcre_callout_block *cb) { FILE *f = (first_callout | callout_extra)? outfile : NULL; -int i, pre_start, post_start, subject_length; +int i, current_position, pre_start, post_start, subject_length; if (callout_extra) { @@ -2280,14 +2280,19 @@ printed lengths of the substrings. */ if (f != NULL) fprintf(f, "--->"); +/* If a lookbehind is involved, the current position may be earlier than the +match start. If so, use the match start instead. */ + +current_position = (cb->current_position >= cb->start_match)? + cb->current_position : cb->start_match; + PCHARS(pre_start, cb->subject, 0, cb->start_match, f); PCHARS(post_start, cb->subject, cb->start_match, - cb->current_position - cb->start_match, f); + current_position - cb->start_match, f); PCHARS(subject_length, cb->subject, 0, cb->subject_length, NULL); -PCHARSV(cb->subject, cb->current_position, - cb->subject_length - cb->current_position, f); +PCHARSV(cb->subject, current_position, cb->subject_length - current_position, f); if (f != NULL) fprintf(f, "\n"); @@ -5740,3 +5745,4 @@ return yield; } /* End of pcretest.c */ + diff --git a/testdata/testinput2 b/testdata/testinput2 index 967a241..086e0f4 100644 --- a/testdata/testinput2 +++ b/testdata/testinput2 @@ -4235,4 +4235,8 @@ backtracking verbs. --/ /(?=a\K)/ ring bpattingbobnd $ 1,oern cou \rb\L +/(?<=((?C)0))/ + 9010 + abcd + /-- End of testinput2 --/ diff --git a/testdata/testoutput2 b/testdata/testoutput2 index 5fb28d5..d414a72 100644 --- a/testdata/testoutput2 +++ b/testdata/testoutput2 @@ -14650,4 +14650,19 @@ Start of matched string is beyond its end - displaying from end to start. 0: a 0L +/(?<=((?C)0))/ + 9010 +--->9010 + 0 ^ 0 + 0 ^ 0 + 0: + 1: 0 + abcd +--->abcd + 0 ^ 0 + 0 ^ 0 + 0 ^ 0 + 0 ^ 0 +No match + /-- End of testinput2 --/ |