[Pcre-svn] [1618] code/trunk: Fix copy named substring bug.

Inizio della pagina
Delete this message
Autore: Subversion repository
Data:  
To: pcre-svn
Oggetto: [Pcre-svn] [1618] code/trunk: Fix copy named substring bug.
Revision: 1618
          http://vcs.pcre.org/viewvc?view=rev&revision=1618
Author:   ph10
Date:     2015-12-05 16:30:14 +0000 (Sat, 05 Dec 2015)
Log Message:
-----------
Fix copy named substring bug.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/pcre_get.c
    code/trunk/testdata/testinput2
    code/trunk/testdata/testoutput2


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2015-12-03 17:05:40 UTC (rev 1617)
+++ code/trunk/ChangeLog    2015-12-05 16:30:14 UTC (rev 1618)
@@ -23,15 +23,18 @@


5. Allow for up to 32-bit numbers in the ordin() function in pcregrep.

-6 . An empty \Q\E sequence between an item and its qualifier caused
+6.  An empty \Q\E sequence between an item and its qualifier caused
     pcre_compile() to misbehave when auto callouts were enabled. This bug was
     found by the LLVM fuzzer.


-7 . If a pattern that was compiled with PCRE_EXTENDED started with white 
+7.  If a pattern that was compiled with PCRE_EXTENDED started with white 
     space or a #-type comment that was followed by (?-x), which turns off 
     PCRE_EXTENDED, and there was no subsequent (?x) to turn it on again,
     pcre_compile() assumed that (?-x) applied to the whole pattern and
     consequently mis-compiled it. This bug was found by the LLVM fuzzer.
+    
+8.  An call of pcre_copy_named_substring() for a named substring whose number
+    was greater than the space in the ovector could cause a crash.



Version 8.38 23-November-2015

Modified: code/trunk/pcre_get.c
===================================================================
--- code/trunk/pcre_get.c    2015-12-03 17:05:40 UTC (rev 1617)
+++ code/trunk/pcre_get.c    2015-12-05 16:30:14 UTC (rev 1618)
@@ -250,6 +250,7 @@
   code         the compiled regex
   stringname   the name of the capturing substring
   ovector      the vector of matched substrings
+  stringcount  number of captured substrings 


 Returns:       the number of the first that is set,
                or the number of the last one if none are set,
@@ -258,13 +259,16 @@


#if defined COMPILE_PCRE8
static int
-get_first_set(const pcre *code, const char *stringname, int *ovector)
+get_first_set(const pcre *code, const char *stringname, int *ovector,
+ int stringcount)
#elif defined COMPILE_PCRE16
static int
-get_first_set(const pcre16 *code, PCRE_SPTR16 stringname, int *ovector)
+get_first_set(const pcre16 *code, PCRE_SPTR16 stringname, int *ovector,
+ int stringcount)
#elif defined COMPILE_PCRE32
static int
-get_first_set(const pcre32 *code, PCRE_SPTR32 stringname, int *ovector)
+get_first_set(const pcre32 *code, PCRE_SPTR32 stringname, int *ovector,
+ int stringcount)
#endif
{
const REAL_PCRE *re = (const REAL_PCRE *)code;
@@ -295,7 +299,7 @@
for (entry = (pcre_uchar *)first; entry <= (pcre_uchar *)last; entry += entrysize)
{
int n = GET2(entry, 0);
- if (ovector[n*2] >= 0) return n;
+ if (n < stringcount && ovector[n*2] >= 0) return n;
}
return GET2(entry, 0);
}
@@ -402,7 +406,7 @@
PCRE_UCHAR32 *buffer, int size)
#endif
{
-int n = get_first_set(code, stringname, ovector);
+int n = get_first_set(code, stringname, ovector, stringcount);
if (n <= 0) return n;
#if defined COMPILE_PCRE8
return pcre_copy_substring(subject, ovector, stringcount, n, buffer, size);
@@ -619,7 +623,7 @@
PCRE_SPTR32 *stringptr)
#endif
{
-int n = get_first_set(code, stringname, ovector);
+int n = get_first_set(code, stringname, ovector, stringcount);
if (n <= 0) return n;
#if defined COMPILE_PCRE8
return pcre_get_substring(subject, ovector, stringcount, n, stringptr);

Modified: code/trunk/testdata/testinput2
===================================================================
--- code/trunk/testdata/testinput2    2015-12-03 17:05:40 UTC (rev 1617)
+++ code/trunk/testdata/testinput2    2015-12-05 16:30:14 UTC (rev 1618)
@@ -4229,4 +4229,7 @@


/()\Q\E*]/BCZ

+/(?<A>)(?J:(?<B>)(?<B>))(?<C>)/
+    \O\CC
+
 /-- End of testinput2 --/


Modified: code/trunk/testdata/testoutput2
===================================================================
--- code/trunk/testdata/testoutput2    2015-12-03 17:05:40 UTC (rev 1617)
+++ code/trunk/testdata/testoutput2    2015-12-05 16:30:14 UTC (rev 1618)
@@ -14639,4 +14639,9 @@
         End
 ------------------------------------------------------------------


+/(?<A>)(?J:(?<B>)(?<B>))(?<C>)/
+    \O\CC
+Matched, but too many substrings
+copy substring C failed -7
+
 /-- End of testinput2 --/