From 3766c023b68d0f3edd9986ca21877a7821dc5880 Mon Sep 17 00:00:00 2001 From: Packit Date: Sep 15 2020 17:00:43 +0000 Subject: Apply patch pcre-8.38-Fix-Q-E-before-qualifier-bug-when-auto-callouts-are-.patch patch_name: pcre-8.38-Fix-Q-E-before-qualifier-bug-when-auto-callouts-are-.patch present_in_specfile: true --- diff --git a/pcre_compile.c b/pcre_compile.c index 5786cd3..beed46b 100644 --- a/pcre_compile.c +++ b/pcre_compile.c @@ -4671,17 +4671,27 @@ for (;; ptr++) } goto NORMAL_CHAR; } + + /* Check for the start of a \Q...\E sequence. We must do this here rather + than later in case it is immediately followed by \E, which turns it into a + "do nothing" sequence. */ + + if (c == CHAR_BACKSLASH && ptr[1] == CHAR_Q) + { + inescq = TRUE; + ptr++; + continue; + } } - /* In extended mode, skip white space and comments. We need a loop in order - to check for more white space and more comments after a comment. */ + /* In extended mode, skip white space and comments. */ if ((options & PCRE_EXTENDED) != 0) { - for (;;) + const pcre_uchar *wscptr = ptr; + while (MAX_255(c) && (cd->ctypes[c] & ctype_space) != 0) c = *(++ptr); + if (c == CHAR_NUMBER_SIGN) { - while (MAX_255(c) && (cd->ctypes[c] & ctype_space) != 0) c = *(++ptr); - if (c != CHAR_NUMBER_SIGN) break; ptr++; while (*ptr != CHAR_NULL) { @@ -4695,7 +4705,15 @@ for (;; ptr++) if (utf) FORWARDCHAR(ptr); #endif } - c = *ptr; /* Either NULL or the char after a newline */ + } + + /* If we skipped any characters, restart the loop. Otherwise, we didn't see + a comment. */ + + if (ptr > wscptr) + { + ptr--; + continue; } } @@ -7900,16 +7918,6 @@ for (;; ptr++) c = ec; else { - if (escape == ESC_Q) /* Handle start of quoted string */ - { - if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E) - ptr += 2; /* avoid empty string */ - else inescq = TRUE; - continue; - } - - if (escape == ESC_E) continue; /* Perl ignores an orphan \E */ - /* For metasequences that actually match a character, we disable the setting of a first character if it hasn't already been set. */ diff --git a/testdata/testinput2 b/testdata/testinput2 index e8ca4fe..3a1134f 100644 --- a/testdata/testinput2 +++ b/testdata/testinput2 @@ -4227,4 +4227,6 @@ backtracking verbs. --/ /(A*)\E+/CBZ +/()\Q\E*]/BCZ + /-- End of testinput2 --/ diff --git a/testdata/testoutput2 b/testdata/testoutput2 index 09756b8..ac33cc4 100644 --- a/testdata/testoutput2 +++ b/testdata/testoutput2 @@ -14624,4 +14624,19 @@ No match End ------------------------------------------------------------------ +/()\Q\E*]/BCZ +------------------------------------------------------------------ + Bra + Callout 255 0 7 + Brazero + SCBra 1 + Callout 255 1 0 + KetRmax + Callout 255 7 1 + ] + Callout 255 8 0 + Ket + End +------------------------------------------------------------------ + /-- End of testinput2 --/