!79 pcre2: sync patches from upstream

From: @xujing99 
Reviewed-by: @openeuler-basic 
Signed-off-by: @openeuler-basic
This commit is contained in:
openeuler-ci-bot 2024-02-05 03:28:28 +00:00 committed by Gitee
commit ea61a161f4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 177 additions and 1 deletions

View File

@ -0,0 +1,65 @@
From 542cb11242cfc9be9b6218965751bfbb13a8b6a2 Mon Sep 17 00:00:00 2001
From: Zoltan Herczeg <hzmester@freemail.hu>
Date: Wed, 27 Dec 2023 08:27:17 +0000
Subject: [PATCH] Fix incorrect class character matches in JIT
---
src/pcre2_jit_compile.c | 8 ++++++++
src/pcre2_jit_test.c | 1 +
2 files changed, 9 insertions(+)
diff --git a/src/pcre2_jit_compile.c b/src/pcre2_jit_compile.c
index c8a51da..f612574 100644
--- a/src/pcre2_jit_compile.c
+++ b/src/pcre2_jit_compile.c
@@ -8170,6 +8170,7 @@ while (*cc != XCL_END)
jump = CMP(SLJIT_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
+ c = charoffset;
/* In case of ucp_Cf, we overwrite the result. */
SET_CHAR_OFFSET(0x2066);
OP2U(SLJIT_SUB | SLJIT_SET_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
@@ -8181,6 +8182,9 @@ while (*cc != XCL_END)
OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x180e - 0x2066);
OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_EQUAL);
+ /* Restore charoffset. */
+ SET_CHAR_OFFSET(c);
+
JUMPHERE(jump);
jump = CMP(SLJIT_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
break;
@@ -8196,6 +8200,7 @@ while (*cc != XCL_END)
jump = CMP(SLJIT_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
+ c = charoffset;
/* In case of ucp_Cf, we overwrite the result. */
SET_CHAR_OFFSET(0x2066);
OP2U(SLJIT_SUB | SLJIT_SET_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
@@ -8204,6 +8209,9 @@ while (*cc != XCL_END)
OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_EQUAL);
+ /* Restore charoffset. */
+ SET_CHAR_OFFSET(c);
+
JUMPHERE(jump);
jump = CMP(SLJIT_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
break;
diff --git a/src/pcre2_jit_test.c b/src/pcre2_jit_test.c
index e4dace8..f2c714b 100644
--- a/src/pcre2_jit_test.c
+++ b/src/pcre2_jit_test.c
@@ -417,6 +417,7 @@ static struct regression_test_case regression_test_cases[] = {
{ MUP, 0, 0, 0, "[\\p{Lu}\\P{Latin}]+", "c\xEA\xA4\xAE,A,b" },
{ MUP, 0, 0, 0, "[\\x{a92e}\\p{Lu}\\P{Latin}]+", "c\xEA\xA4\xAE,A,b" },
{ CMUP, 0, 0, 0, "[^S]\\B", "\xe2\x80\x8a" },
+ { MUP, 0, 0, 0 | F_NOMATCH, "[^[:print:]\\x{f6f6}]", "\xef\x9b\xb6" },
/* Possible empty brackets. */
{ MU, A, 0, 0, "(?:|ab||bc|a)+d", "abcxabcabd" },
--
2.33.0

View File

@ -0,0 +1,105 @@
From 9783ca9bed0cfb682e7bc76ed605aeb38571930a Mon Sep 17 00:00:00 2001
From: Addison Crump <addison.crump@cispa.de>
Date: Sat, 18 Nov 2023 16:52:00 +0100
Subject: [PATCH] Sanity checks for ctype functions (#342)
* fixup: sanity checks for ctype functions
* format
* more grep fixes
* don't check if constrained by type
---
src/pcre2_compile.c | 4 ++++
src/pcre2_convert.c | 8 ++++++++
src/pcre2grep.c | 10 +++++-----
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c
index feb5bcd..b3e4969 100644
--- a/src/pcre2_compile.c
+++ b/src/pcre2_compile.c
@@ -2194,7 +2194,11 @@ if (c == CHAR_LEFT_CURLY_BRACKET)
{
if (ptr >= cb->end_pattern) goto ERROR_RETURN;
c = *ptr++;
+#if PCRE2_CODE_UNIT_WIDTH != 8
+ while (c == '_' || c == '-' || (c <= 0xff && isspace(c)))
+#else
while (c == '_' || c == '-' || isspace(c))
+#endif
{
if (ptr >= cb->end_pattern) goto ERROR_RETURN;
c = *ptr++;
diff --git a/src/pcre2_convert.c b/src/pcre2_convert.c
index 36466e4..fe396ae 100644
--- a/src/pcre2_convert.c
+++ b/src/pcre2_convert.c
@@ -540,6 +540,14 @@ Returns: !0 => character is found in the class
static BOOL
convert_glob_char_in_class(int class_index, PCRE2_UCHAR c)
{
+#if PCRE2_CODE_UNIT_WIDTH != 8
+if (c > 0xff)
+ {
+ /* ctype functions are not sane for c > 0xff */
+ return 0;
+ }
+#endif
+
switch (class_index)
{
case 1: return isalnum(c);
diff --git a/src/pcre2grep.c b/src/pcre2grep.c
index 776aa28..73cf45a 100644
--- a/src/pcre2grep.c
+++ b/src/pcre2grep.c
@@ -796,7 +796,7 @@ decode_ANSI_colour(const char *cs)
WORD result = csbi.wAttributes;
while (*cs)
{
- if (isdigit(*cs))
+ if (isdigit((unsigned char)(*cs)))
{
int code = atoi(cs);
if (code == 1) result |= 0x08;
@@ -810,7 +810,7 @@ while (*cs)
else if (code >= 90 && code <= 97) result = (result & 0xF0) | BGR_RGB(code - 90) | 0x08;
else if (code >= 100 && code <= 107) result = (result & 0x0F) | (BGR_RGB(code - 100) << 4) | 0x80;
- while (isdigit(*cs)) cs++;
+ while (isdigit((unsigned char)(*cs))) cs++;
}
if (*cs) cs++;
}
@@ -1989,7 +1989,7 @@ switch (*(++string))
case '{':
brace = TRUE;
string++;
- if (!isdigit(*string)) /* Syntax error: a decimal number required. */
+ if (!isdigit((unsigned char)(*string))) /* Syntax error: a decimal number required. */
{
if (!callout)
fprintf(stderr, "pcre2grep: Error in output text at offset %d: %s\n",
@@ -4036,7 +4036,7 @@ for (i = 1; i < argc; i++)
if (op->type == OP_OP_NUMBER || op->type == OP_OP_NUMBERS)
{
- if (isdigit((unsigned char)s[1])) break;
+ if (isdigit((unsigned char)(s[1]))) break;
}
else /* Check for an option with data */
{
@@ -4520,7 +4520,7 @@ for (fn = file_lists; fn != NULL; fn = fn->next)
{
int frc;
char *end = buffer + (int)strlen(buffer);
- while (end > buffer && isspace(end[-1])) end--;
+ while (end > buffer && isspace((unsigned char)(end[-1]))) end--;
*end = 0;
if (*buffer != 0)
{
--
2.33.0

View File

@ -1,6 +1,6 @@
Name: pcre2
Version: 10.42
Release: 4
Release: 5
Summary: Perl Compatible Regular Expressions
License: BSD
URL: http://www.pcre.org/
@ -26,6 +26,8 @@ Patch6014: backport-Fix-compile-loop-in-32-bit-mode-for-characters-above.pat
Patch6015: backport-Fix-incorrect-matching-of-0xffffffff-to-any-characte.patch
Patch6016: backport-Fix-accept-and-endanchored-interaction-in-JIT.patch
Patch6017: backport-Fix-backreferences-with-unset-backref-and-non-greedy.patch
Patch6018: backport-Sanity-checks-for-ctype-functions-342.patch
Patch6019: backport-Fix-incorrect-class-character-matches-in-JIT.patch
BuildRequires: autoconf libtool automake coreutils gcc make readline-devel
Obsoletes: pcre2-utf16 pcre2-utf32 pcre2-tools
@ -142,6 +144,10 @@ make check
%{_pkgdocdir}/html/
%changelog
* Mon Jan 22 2024 xujing <xujing125@huawei.com> - 10.42-5
- DESC:Sanity checks for ctype functions
Fix incorrect class character matches in JIT
* Mon Jan 22 2024 xujing <xujing125@huawei.com> - 10.42-4
- DESC:sync patches from upstream to fix some bugs