sync community patchs

(cherry picked from commit 774fddf611f12c79c90537e2d9ba1046e4de0b7f)
This commit is contained in:
yangmingtaip 2022-10-18 20:10:03 +08:00 committed by openeuler-sync-bot
parent 4758fdd70f
commit becff834e4
13 changed files with 907 additions and 5 deletions

View File

@ -0,0 +1,57 @@
From 4804b00e8f50e446be43ee51863c8cdd3c743bea Mon Sep 17 00:00:00 2001
From: Philip Hazel <Philip.Hazel@gmail.com>
Date: Thu, 30 Jun 2022 17:37:51 +0100
Subject: [PATCH] Add an #ifdef to avoid the need even to link with
pcre2_jit_compile.o when JIT is not supported
Conflict:delete changelog
Reference:https://github.com/PCRE2Project/pcre2/commit/4804b00e8f50e446be43ee51863c8cdd3c743bea
---
src/pcre2_compile.c | 2 ++
src/pcre2test.c | 4 ++--
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c
index 383159b..b906dc0 100644
--- a/src/pcre2_compile.c
+++ b/src/pcre2_compile.c
@@ -1264,8 +1264,10 @@ PCRE2_SIZE* ref_count;
if (code != NULL)
{
+#ifdef SUPPORT_JIT
if (code->executable_jit != NULL)
PRIV(jit_free)(code->executable_jit, &code->memctl);
+#endif
if ((code->flags & PCRE2_DEREF_TABLES) != 0)
{
diff --git a/src/pcre2test.c b/src/pcre2test.c
index 84987d7..11ec3ca 100644
--- a/src/pcre2test.c
+++ b/src/pcre2test.c
@@ -4737,19 +4737,19 @@ if ((pat_patctl.control & CTL_INFO) != 0)
if (pat_patctl.jit != 0 && (pat_patctl.control & CTL_JITVERIFY) != 0)
{
+#ifdef SUPPORT_JIT
if (FLD(compiled_code, executable_jit) != NULL)
fprintf(outfile, "JIT compilation was successful\n");
else
{
-#ifdef SUPPORT_JIT
fprintf(outfile, "JIT compilation was not successful");
if (jitrc != 0 && !print_error_message(jitrc, " (", ")"))
return PR_ABEND;
fprintf(outfile, "\n");
+ }
#else
fprintf(outfile, "JIT support is not available in this version of PCRE2\n");
#endif
- }
}
}
--
2.27.0

View File

@ -0,0 +1,110 @@
From 7549fdca744378b9e6597c2882a490308573368b Mon Sep 17 00:00:00 2001
From: Philip Hazel <Philip.Hazel@gmail.com>
Date: Thu, 30 Jun 2022 17:06:32 +0100
Subject: [PATCH] Change length variables in pcre2grep from int to size_t
Conflict:delete Changelog
Reference:https://github.com/PCRE2Project/pcre2/commit/7549fdca744378b9e6597c2882a490308573368b
---
src/pcre2grep.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/src/pcre2grep.c b/src/pcre2grep.c
index 519346b..1484d67 100644
--- a/src/pcre2grep.c
+++ b/src/pcre2grep.c
@@ -232,15 +232,16 @@ static int after_context = 0;
static int before_context = 0;
static int binary_files = BIN_BINARY;
static int both_context = 0;
-static int bufthird = PCRE2GREP_BUFSIZE;
-static int max_bufthird = PCRE2GREP_MAX_BUFSIZE;
-static int bufsize = 3*PCRE2GREP_BUFSIZE;
static int endlinetype;
static int count_limit = -1; /* Not long, so that it works with OP_NUMBER */
static unsigned long int counts_printed = 0;
static unsigned long int total_count = 0;
+static PCRE2_SIZE bufthird = PCRE2GREP_BUFSIZE;
+static PCRE2_SIZE max_bufthird = PCRE2GREP_MAX_BUFSIZE;
+static PCRE2_SIZE bufsize = 3*PCRE2GREP_BUFSIZE;
+
#ifdef WIN32
static int dee_action = dee_SKIP;
#else
@@ -433,8 +434,8 @@ static option_item optionlist[] = {
{ OP_NODATA, 'a', NULL, "text", "treat binary files as text" },
{ OP_NUMBER, 'B', &before_context, "before-context=number", "set number of prior context lines" },
{ OP_BINFILES, N_BINARY_FILES, NULL, "binary-files=word", "set treatment of binary files" },
- { OP_NUMBER, N_BUFSIZE,&bufthird, "buffer-size=number", "set processing buffer starting size" },
- { OP_NUMBER, N_MAX_BUFSIZE,&max_bufthird, "max-buffer-size=number", "set processing buffer maximum size" },
+ { OP_SIZE, N_BUFSIZE,&bufthird, "buffer-size=number", "set processing buffer starting size" },
+ { OP_SIZE, N_MAX_BUFSIZE,&max_bufthird, "max-buffer-size=number", "set processing buffer maximum size" },
{ OP_OP_STRING, N_COLOUR, &colour_option, "color=option", "matched text color option" },
{ OP_OP_STRING, N_COLOUR, &colour_option, "colour=option", "matched text colour option" },
{ OP_NUMBER, 'C', &both_context, "context=number", "set number of context lines, before & after" },
@@ -1419,10 +1420,10 @@ Returns: the number of characters read, zero at end of file
*/
static PCRE2_SIZE
-read_one_line(char *buffer, int length, FILE *f)
+read_one_line(char *buffer, PCRE2_SIZE length, FILE *f)
{
int c;
-int yield = 0;
+PCRE2_SIZE yield = 0;
while ((c = fgetc(f)) != EOF)
{
buffer[yield++] = c;
@@ -2468,8 +2469,8 @@ return result != 0;
* Read a portion of the file into buffer *
*************************************************/
-static int
-fill_buffer(void *handle, int frtype, char *buffer, int length,
+static PCRE2_SIZE
+fill_buffer(void *handle, int frtype, char *buffer, PCRE2_SIZE length,
BOOL input_line_buffered)
{
(void)frtype; /* Avoid warning when not used */
@@ -2631,7 +2632,7 @@ while (ptr < endptr)
if (bufthird < max_bufthird)
{
char *new_buffer;
- int new_bufthird = 2*bufthird;
+ PCRE2_SIZE new_bufthird = 2*bufthird;
if (new_bufthird > max_bufthird) new_bufthird = max_bufthird;
new_buffer = (char *)malloc(3*new_bufthird);
@@ -2640,7 +2641,8 @@ while (ptr < endptr)
{
fprintf(stderr,
"pcre2grep: line %lu%s%s is too long for the internal buffer\n"
- "pcre2grep: not enough memory to increase the buffer size to %d\n",
+ "pcre2grep: not enough memory to increase the buffer size to %"
+ SIZ_FORM "\n",
linenumber,
(filename == NULL)? "" : " of file ",
(filename == NULL)? "" : filename,
@@ -2670,7 +2672,7 @@ while (ptr < endptr)
{
fprintf(stderr,
"pcre2grep: line %lu%s%s is too long for the internal buffer\n"
- "pcre2grep: the maximum buffer size is %d\n"
+ "pcre2grep: the maximum buffer size is %" SIZ_FORM "\n"
"pcre2grep: use the --max-buffer-size option to change it\n",
linenumber,
(filename == NULL)? "" : " of file ",
@@ -3153,7 +3155,7 @@ while (ptr < endptr)
if (input_line_buffered && bufflength < (PCRE2_SIZE)bufsize)
{
- int add = read_one_line(ptr, bufsize - (int)(ptr - main_buffer), in);
+ PCRE2_SIZE add = read_one_line(ptr, bufsize - (ptr - main_buffer), in);
bufflength += add;
endptr += add;
}
--
2.27.0

View File

@ -0,0 +1,44 @@
From d07c967b3ac93a9bd8816837053a75b0f8a816c9 Mon Sep 17 00:00:00 2001
From: Zoltan Herczeg <hzmester@freemail.hu>
Date: Thu, 14 Apr 2022 19:09:40 +0000
Subject: [PATCH] Fix recursion issue in JIT
Conflict:NA
Reference:https://github.com/PCRE2Project/pcre2/commit/d07c967b3ac93a9bd8816837053a75b0f8a816c9
---
src/pcre2_jit_compile.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/pcre2_jit_compile.c b/src/pcre2_jit_compile.c
index e47a9f3..b98bf95 100644
--- a/src/pcre2_jit_compile.c
+++ b/src/pcre2_jit_compile.c
@@ -2909,14 +2909,15 @@ while (cc < ccend)
i = 1 + 32 / (int)sizeof(PCRE2_UCHAR);
#endif
if (PRIVATE_DATA(cc) != 0)
+ {
+ private_count = 1;
+ private_srcw[0] = PRIVATE_DATA(cc);
switch(get_class_iterator_size(cc + i))
{
case 1:
- private_srcw[0] = PRIVATE_DATA(cc);
break;
case 2:
- private_srcw[0] = PRIVATE_DATA(cc);
if (recurse_check_bit(common, private_srcw[0]))
{
private_count = 2;
@@ -2929,6 +2930,7 @@ while (cc < ccend)
SLJIT_UNREACHABLE();
break;
}
+ }
cc += i;
break;
--
2.27.0

View File

@ -0,0 +1,62 @@
From 4851890ede31313655e19180f4959ed348fee580 Mon Sep 17 00:00:00 2001
From: Zoltan Herczeg <zherczeg.u-szeged@partner.samsung.com>
Date: Thu, 14 Jul 2022 05:25:39 +0200
Subject: [PATCH] Fixed an issue in the backtracking optimization of character
repeats in JIT (#135)
Conflict:adjust changelog
Reference:https://github.com/PCRE2Project/pcre2/commit/4851890ede31313655e19180f4959ed348fee580
---
src/pcre2_jit_compile.c | 20 ++++++++++----------
src/pcre2_jit_test.c | 1 +
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/pcre2_jit_compile.c b/src/pcre2_jit_compile.c
index 8f6c090..75ba610 100644
--- a/src/pcre2_jit_compile.c
+++ b/src/pcre2_jit_compile.c
@@ -11357,19 +11357,19 @@ if (exact > 1)
}
}
else if (exact == 1)
- {
compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks, TRUE);
- if (early_fail_type == type_fail_range)
- {
- OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), early_fail_ptr);
- OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), early_fail_ptr + (int)sizeof(sljit_sw));
- OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, TMP2, 0);
- OP2(SLJIT_SUB, TMP2, 0, STR_PTR, 0, TMP2, 0);
- add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_LESS_EQUAL, TMP2, 0, TMP1, 0));
+if (early_fail_type == type_fail_range)
+ {
+ /* Range end first, followed by range start. */
+ OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), early_fail_ptr);
+ OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), early_fail_ptr + (int)sizeof(sljit_sw));
+ OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, TMP2, 0);
+ OP2(SLJIT_SUB, TMP2, 0, STR_PTR, 0, TMP2, 0);
+ add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_LESS_EQUAL, TMP2, 0, TMP1, 0));
- OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), early_fail_ptr + (int)sizeof(sljit_sw), STR_PTR, 0);
- }
+ OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), early_fail_ptr, STR_PTR, 0);
+ OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), early_fail_ptr + (int)sizeof(sljit_sw), STR_PTR, 0);
}
switch(opcode)
diff --git a/src/pcre2_jit_test.c b/src/pcre2_jit_test.c
index f7b9f6d..e1f0bbc 100644
--- a/src/pcre2_jit_test.c
+++ b/src/pcre2_jit_test.c
@@ -354,6 +354,7 @@ static struct regression_test_case regression_test_cases[] = {
{ MU, A, 0, 0, "_[ab]+_*a", "_aa" },
{ MU, A, 0, 0, "#(A+)#\\d+", "#A#A#0" },
{ MU, A, 0, 0, "(?P<size>\\d+)m|M", "4M" },
+ { M, PCRE2_NEWLINE_CRLF, 0, 0, "\\n?.+#", "\n,\n,#" },
/* Bracket repeats with limit. */
{ MU, A, 0, 0, "(?:(ab){2}){5}M", "abababababababababababM" },
--
2.27.0

View File

@ -0,0 +1,56 @@
From 45af1203bdb5d1ccccc27526ce38c36f49196ccc Mon Sep 17 00:00:00 2001
From: larinsv <97248465+larinsv@users.noreply.github.com>
Date: Wed, 18 May 2022 13:16:00 +0300
Subject: [PATCH] Fixed race condition that occurs when initializing the
executable_allocator_is_working variable in the pcre2_jit_compile function
(#91)
Conflict:NA
Reference:https://github.com/PCRE2Project/pcre2/commit/45af1203bdb5d1ccccc27526ce38c36f49196ccc
---
src/pcre2_jit_compile.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/src/pcre2_jit_compile.c b/src/pcre2_jit_compile.c
index b6b1313..e638c24 100644
--- a/src/pcre2_jit_compile.c
+++ b/src/pcre2_jit_compile.c
@@ -14384,7 +14384,7 @@ pcre2_jit_compile(pcre2_code *code, uint32_t options)
pcre2_real_code *re = (pcre2_real_code *)code;
#ifdef SUPPORT_JIT
executable_functions *functions;
-static int executable_allocator_is_working = 0;
+static int executable_allocator_is_working = -1;
#endif
if (code == NULL)
@@ -14447,23 +14447,21 @@ return PCRE2_ERROR_JIT_BADOPTION;
if ((re->flags & PCRE2_NOJIT) != 0) return 0;
-if (executable_allocator_is_working == 0)
+if (executable_allocator_is_working == -1)
{
/* Checks whether the executable allocator is working. This check
might run multiple times in multi-threaded environments, but the
result should not be affected by it. */
void *ptr = SLJIT_MALLOC_EXEC(32, NULL);
-
- executable_allocator_is_working = -1;
-
if (ptr != NULL)
{
SLJIT_FREE_EXEC(((sljit_u8*)(ptr)) + SLJIT_EXEC_OFFSET(ptr), NULL);
executable_allocator_is_working = 1;
}
+ else executable_allocator_is_working = 0;
}
-if (executable_allocator_is_working < 0)
+if (!executable_allocator_is_working)
return PCRE2_ERROR_NOMEMORY;
if ((re->overall_options & PCRE2_MATCH_INVALID_UTF) != 0)
--
2.27.0

View File

@ -0,0 +1,42 @@
From d144199dfbefd276669a138b042f559b687b8bc8 Mon Sep 17 00:00:00 2001
From: Zoltan Herczeg <zherczeg.u-szeged@partner.samsung.com>
Date: Wed, 24 Nov 2021 17:58:30 +0100
Subject: [PATCH] Revert an unintended change in JIT repeat detection. (#58)
Co-authored-by: Zoltan Herczeg <hzmester@freemail.hu>
Conflict:delete changelog
Reference:https://github.com/PCRE2Project/pcre2/commit/d144199dfbefd276669a138b042f559b687b8bc8
---
src/pcre2_jit_compile.c | 2 +-
src/pcre2_jit_test.c | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/pcre2_jit_compile.c b/src/pcre2_jit_compile.c
index 6c42318..ac75c7f 100644
--- a/src/pcre2_jit_compile.c
+++ b/src/pcre2_jit_compile.c
@@ -1624,7 +1624,7 @@ if (end[-(1 + LINK_SIZE)] != OP_KET || PRIVATE_DATA(begin) != 0)
/* /(?:AB){4,6}/ is currently converted to /(?:AB){3}(?AB){1,3}/
* Skip the check of the second part. */
-if (PRIVATE_DATA(end - LINK_SIZE) == 0)
+if (PRIVATE_DATA(end - LINK_SIZE) != 0)
return TRUE;
next = end;
diff --git a/src/pcre2_jit_test.c b/src/pcre2_jit_test.c
index 26de6c7..f7b9f6d 100644
--- a/src/pcre2_jit_test.c
+++ b/src/pcre2_jit_test.c
@@ -291,6 +291,7 @@ static struct regression_test_case regression_test_cases[] = {
{ MU, A, 0, 0, "(a(?:bc|cb|b|c)+?|ss)+e", "accssabccbcacbccbbXaccssabccbcacbccbbe" },
{ MU, A, 0, 0, "(a(?:bc|cb|b|c)+|ss)+?e", "accssabccbcacbccbbXaccssabccbcacbccbbe" },
{ MU, A, 0, 0, "(?:(b(c)+?)+)?\?(?:(bc)+|(cb)+)+(?:m)+", "bccbcccbcbccbcbPbccbcccbcbccbcbmmn" },
+ { MU, A, 0, 0, "(aa|bb){8,1000}", "abaabbaabbaabbaab_aabbaabbaabbaabbaabbaabb_" },
/* Greedy and non-greedy * operators */
{ CMU, A, 0, 0, "(?:AA)*AB", "aaaaaaamaaaaaaab" },
--
2.27.0

View File

@ -0,0 +1,55 @@
From b52d055d1b8feb6e56804c2062de65d50a5601e2 Mon Sep 17 00:00:00 2001
From: Philip Hazel <Philip.Hazel@gmail.com>
Date: Fri, 22 Apr 2022 18:02:14 +0100
Subject: [PATCH] Update HTML docs
Conflict:NA
Reference:https://github.com/PCRE2Project/pcre2/commit/b52d055d1b8feb6e56804c2062de65d50a5601e2
---
doc/html/pcre2_serialize_decode.html | 2 +-
doc/html/pcre2serialize.html | 2 +-
doc/pcre2.txt | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/doc/html/pcre2_serialize_decode.html b/doc/html/pcre2_serialize_decode.html
index cff6e6c..618ffa9 100644
--- a/doc/html/pcre2_serialize_decode.html
+++ b/doc/html/pcre2_serialize_decode.html
@@ -48,7 +48,7 @@ the following negative error codes:
PCRE2_ERROR_BADDATA <i>number_of_codes</i> is zero or less
PCRE2_ERROR_BADMAGIC mismatch of id bytes in <i>bytes</i>
PCRE2_ERROR_BADMODE mismatch of variable unit size or PCRE version
- PCRE2_ERROR_MEMORY memory allocation failed
+ PCRE2_ERROR_NOMEMORY memory allocation failed
PCRE2_ERROR_NULL <i>codes</i> or <i>bytes</i> is NULL
</pre>
PCRE2_ERROR_BADMAGIC may mean that the data is corrupt, or that it was compiled
diff --git a/doc/html/pcre2serialize.html b/doc/html/pcre2serialize.html
index df4098e..a492305 100644
--- a/doc/html/pcre2serialize.html
+++ b/doc/html/pcre2serialize.html
@@ -94,7 +94,7 @@ of serialized patterns, or one of the following negative error codes:
<pre>
PCRE2_ERROR_BADDATA the number of patterns is zero or less
PCRE2_ERROR_BADMAGIC mismatch of id bytes in one of the patterns
- PCRE2_ERROR_MEMORY memory allocation failed
+ PCRE2_ERROR_NOMEMORY memory allocation failed
PCRE2_ERROR_MIXEDTABLES the patterns do not all use the same tables
PCRE2_ERROR_NULL the 1st, 3rd, or 4th argument is NULL
</pre>
diff --git a/doc/pcre2.txt b/doc/pcre2.txt
index c318432..c70fb9b 100644
--- a/doc/pcre2.txt
+++ b/doc/pcre2.txt
@@ -10436,7 +10436,7 @@ SAVING COMPILED PATTERNS
PCRE2_ERROR_BADDATA the number of patterns is zero or less
PCRE2_ERROR_BADMAGIC mismatch of id bytes in one of the patterns
- PCRE2_ERROR_MEMORY memory allocation failed
+ PCRE2_ERROR_NOMEMORY memory allocation failed
PCRE2_ERROR_MIXEDTABLES the patterns do not all use the same tables
PCRE2_ERROR_NULL the 1st, 3rd, or 4th argument is NULL
--
2.27.0

View File

@ -0,0 +1,43 @@
From a4ac97fea8a2d802985d1f5b298ede2cb07cc8cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= <carenas@gmail.com>
Date: Fri, 22 Apr 2022 09:59:44 -0700
Subject: [PATCH] doc: avoid nonexistent PCRE2_ERROR_MEMORY error (#107)
5438fc8a (Add serialization functions and tests with updated pcre2test.
Fix PCRE2_INFO_SIZE issues., 2015-01-23) introduced the typo.
Reported-by: @sjshuck
Fixes: #106
Conflict:NA
Reference:https://github.com/PCRE2Project/pcre2/commit/a4ac97fea8a2d802985d1f5b298ede2cb07cc8cd
diff --git a/doc/pcre2_serialize_decode.3 b/doc/pcre2_serialize_decode.3
index b67a112..611113f 100644
--- a/doc/pcre2_serialize_decode.3
+++ b/doc/pcre2_serialize_decode.3
@@ -36,7 +36,7 @@ the following negative error codes:
PCRE2_ERROR_BADDATA \fInumber_of_codes\fP is zero or less
PCRE2_ERROR_BADMAGIC mismatch of id bytes in \fIbytes\fP
PCRE2_ERROR_BADMODE mismatch of variable unit size or PCRE version
- PCRE2_ERROR_MEMORY memory allocation failed
+ PCRE2_ERROR_NOMEMORY memory allocation failed
PCRE2_ERROR_NULL \fIcodes\fP or \fIbytes\fP is NULL
.sp
PCRE2_ERROR_BADMAGIC may mean that the data is corrupt, or that it was compiled
diff --git a/doc/pcre2serialize.3 b/doc/pcre2serialize.3
index 987bc3a..a94f13b 100644
--- a/doc/pcre2serialize.3
+++ b/doc/pcre2serialize.3
@@ -81,7 +81,7 @@ of serialized patterns, or one of the following negative error codes:
.sp
PCRE2_ERROR_BADDATA the number of patterns is zero or less
PCRE2_ERROR_BADMAGIC mismatch of id bytes in one of the patterns
- PCRE2_ERROR_MEMORY memory allocation failed
+ PCRE2_ERROR_NOMEMORY memory allocation failed
PCRE2_ERROR_MIXEDTABLES the patterns do not all use the same tables
PCRE2_ERROR_NULL the 1st, 3rd, or 4th argument is NULL
.sp
--
2.27.0

View File

@ -0,0 +1,60 @@
From eb42305f072549facb3293f392f25768f35fa218 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= <carenas@gmail.com>
Date: Fri, 19 Nov 2021 00:23:46 -0800
Subject: [PATCH] jit: avoid integer wraparound in stack size definition (#42)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
pcre2_jit_stack_create() allows the user to indicate how big of a
stack size JIT should be able to allocate and use, using a size_t
variable which should be able to hold bigger values than reasonable.
Internally, the value is rounded to the next 8K, but if the value
is unreasonable large, would overflow and could result in a smaller
than expected stack or a maximun size that is smaller than the
minimum..
Avoid the overflow by checking the value and failing early, and
while at it make the check clearer while documenting the failure
mode.
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Conflict:NA
Reference:https://github.com/PCRE2Project/pcre2/commit/eb42305f072549facb3293f392f25768f35fa218
---
doc/pcre2_jit_stack_create.3 | 3 ++-
src/pcre2_jit_misc.c | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/doc/pcre2_jit_stack_create.3 b/doc/pcre2_jit_stack_create.3
index f0b29f0..d332b72 100644
--- a/doc/pcre2_jit_stack_create.3
+++ b/doc/pcre2_jit_stack_create.3
@@ -22,7 +22,8 @@ allocation. The result can be passed to the JIT run-time code by calling
\fBpcre2_jit_stack_assign()\fP to associate the stack with a compiled pattern,
which can then be processed by \fBpcre2_match()\fP or \fBpcre2_jit_match()\fP.
A maximum stack size of 512KiB to 1MiB should be more than enough for any
-pattern. For more details, see the
+pattern. If the stack couldn't be allocated or the values passed were not
+reasonable, NULL will be returned. For more details, see the
.\" HREF
\fBpcre2jit\fP
.\"
diff --git a/src/pcre2_jit_misc.c b/src/pcre2_jit_misc.c
index ec924e0..d532df9 100644
--- a/src/pcre2_jit_misc.c
+++ b/src/pcre2_jit_misc.c
@@ -135,7 +135,7 @@ return NULL;
pcre2_jit_stack *jit_stack;
-if (startsize < 1 || maxsize < 1)
+if (startsize == 0 || maxsize == 0 || maxsize > PCRE2_SIZE_MAX - STACK_GROWTH_RATE)
return NULL;
if (startsize > maxsize)
startsize = maxsize;
--
2.27.0

View File

@ -0,0 +1,45 @@
From 14dbc6e6ec9900b2e06a04d2612de37ccd564dfc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= <carenas@gmail.com>
Date: Thu, 6 Jan 2022 05:46:43 -0800
Subject: [PATCH] jit: use correct type when checking for max value (#73)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
eb42305f (jit: avoid integer wraparound in stack size definition (#42),
2021-11-19) introduces a check to avoid an integer overflow when
allocating stack size for JIT.
Unfortunately the maximum value was using PCRE2_SIZE_MAX, eventhough
the variable is of type size_t, so correct it.
Practically; the issue shouldn't affect the most common configurations
where both values are the same, and it will be unlikely that there would
be a configuration where PCRE2_SIZE_MAX > SIZE_MAX, hence the mistake
is unlikely to have reintroduced the original bug and this change should
be therefore mostly equivalent.
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Conflict:NA
Reference:https://github.com/PCRE2Project/pcre2/commit/14dbc6e6ec9900b2e06a04d2612de37ccd564dfc
---
src/pcre2_jit_misc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/pcre2_jit_misc.c b/src/pcre2_jit_misc.c
index d532df9..e57afad 100644
--- a/src/pcre2_jit_misc.c
+++ b/src/pcre2_jit_misc.c
@@ -135,7 +135,7 @@ return NULL;
pcre2_jit_stack *jit_stack;
-if (startsize == 0 || maxsize == 0 || maxsize > PCRE2_SIZE_MAX - STACK_GROWTH_RATE)
+if (startsize == 0 || maxsize == 0 || maxsize > SIZE_MAX - STACK_GROWTH_RATE)
return NULL;
if (startsize > maxsize)
startsize = maxsize;
--
2.27.0

View File

@ -0,0 +1,193 @@
From ae4e6261e5681658f88a0dff8eb2d60112bd7e54 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= <carenas@gmail.com>
Date: Sat, 27 Nov 2021 08:49:31 -0800
Subject: [PATCH] match: avoid crash if subject NULL and PCRE2_ZERO_TERMINATED
(#53)
* pcre2_match: avoid crash if subject NULL and PCRE2_ZERO_TERMINATED
When length of subject is PCRE2_ZERO_TERMINATED strlen is used
to calculate its size, which will trigger a crash if subject is
also NULL.
Move the NULL check before strlen on it would be used, and make
sure or dependent variables are set after the NULL validation
as well.
While at it, fix a typo in a debug flag in the same file, which
is otherwise unrelated and make sure the full section of constrain
checks can be identified clearly using the leading comment alone.
* pcre2_dfa_match: avoid crash if subject NULL and PCRE2_ZERO_TERMINATED
When length of subject is PCRE2_ZERO_TERMINATED strlen is used
to calculate its size, which will trigger a crash if subject is
also NULL.
Move the NULL check before the detection for subject sizes to
avoid this issue.
* pcre2_substitute: avoid crash if subject or replacement are NULL
The underlying pcre2_match() function will validate the subject if
needed, but will crash when length is PCRE2_ZERO_TERMINATED or if
subject == NULL and pcre2_match() is not being called because
match_data was provided.
The replacement parameter is missing NULL checks, and so currently
allows for an equivalent response to "" if rlength == 0.
Restrict all other cases to avoid strlen(NULL) crashes in the same
way that is done for subject, but also make sure to reject invalid
length values as early as possible.
Conflict:NA
Reference:https://github.com/PCRE2Project/pcre2/commit/ae4e6261e5681658f88a0dff8eb2d60112bd7e54
---
doc/pcre2api.3 | 4 +++-
src/pcre2_dfa_match.c | 12 +++++-------
src/pcre2_match.c | 20 ++++++++++----------
src/pcre2_substitute.c | 15 ++++++++++-----
4 files changed, 28 insertions(+), 23 deletions(-)
diff --git a/doc/pcre2api.3 b/doc/pcre2api.3
index 1caccbb..fe84fa4 100644
--- a/doc/pcre2api.3
+++ b/doc/pcre2api.3
@@ -3649,7 +3649,9 @@ needed is returned via \fIoutlengthptr\fP. Note that this does not happen by
default.
.P
PCRE2_ERROR_NULL is returned if PCRE2_SUBSTITUTE_MATCHED is set but the
-\fImatch_data\fP argument is NULL.
+\fImatch_data\fP argument is NULL or if the \fIsubject\fP or \fIreplacement\fP
+arguments are NULL. For backward compatibility reasons an exception is made for
+the \fIreplacement\fP argument if the \fIrlength\fP argument is also 0.
.P
PCRE2_ERROR_BADREPLACEMENT is used for miscellaneous syntax errors in the
replacement string, with more particular errors being PCRE2_ERROR_BADREPESCAPE
diff --git a/src/pcre2_dfa_match.c b/src/pcre2_dfa_match.c
index 060dc76..a97e071 100644
--- a/src/pcre2_dfa_match.c
+++ b/src/pcre2_dfa_match.c
@@ -3285,8 +3285,11 @@ rws->next = NULL;
rws->size = RWS_BASE_SIZE;
rws->free = RWS_BASE_SIZE - RWS_ANCHOR_SIZE;
-/* A length equal to PCRE2_ZERO_TERMINATED implies a zero-terminated
-subject string. */
+/* Plausibility checks */
+
+if ((options & ~PUBLIC_DFA_MATCH_OPTIONS) != 0) return PCRE2_ERROR_BADOPTION;
+if (re == NULL || subject == NULL || workspace == NULL || match_data == NULL)
+ return PCRE2_ERROR_NULL;
if (length == PCRE2_ZERO_TERMINATED)
{
@@ -3294,11 +3297,6 @@ if (length == PCRE2_ZERO_TERMINATED)
was_zero_terminated = 1;
}
-/* Plausibility checks */
-
-if ((options & ~PUBLIC_DFA_MATCH_OPTIONS) != 0) return PCRE2_ERROR_BADOPTION;
-if (re == NULL || subject == NULL || workspace == NULL || match_data == NULL)
- return PCRE2_ERROR_NULL;
if (wscount < 20) return PCRE2_ERROR_DFA_WSSIZE;
if (start_offset > length) return PCRE2_ERROR_BADOFFSET;
diff --git a/src/pcre2_match.c b/src/pcre2_match.c
index f28cdbb..ea8ca5d 100644
--- a/src/pcre2_match.c
+++ b/src/pcre2_match.c
@@ -49,7 +49,7 @@ POSSIBILITY OF SUCH DAMAGE.
/* #define DEBUG_SHOW_OPS */
/* #define DEBUG_SHOW_RMATCH */
-#ifdef DEBUG_FRAME_DISPLAY
+#ifdef DEBUG_FRAMES_DISPLAY
#include <stdarg.h>
#endif
@@ -6129,8 +6129,8 @@ PCRE2_UCHAR req_cu2 = 0;
PCRE2_SPTR bumpalong_limit;
PCRE2_SPTR end_subject;
PCRE2_SPTR true_end_subject;
-PCRE2_SPTR start_match = subject + start_offset;
-PCRE2_SPTR req_cu_ptr = start_match - 1;
+PCRE2_SPTR start_match;
+PCRE2_SPTR req_cu_ptr;
PCRE2_SPTR start_partial;
PCRE2_SPTR match_partial;
@@ -6170,9 +6170,14 @@ PCRE2_SPTR stack_frames_vector[START_FRAMES_SIZE/sizeof(PCRE2_SPTR)]
PCRE2_KEEP_UNINITIALIZED;
mb->stack_frames = (heapframe *)stack_frames_vector;
-/* A length equal to PCRE2_ZERO_TERMINATED implies a zero-terminated
-subject string. */
+/* Plausibility checks */
+
+if ((options & ~PUBLIC_MATCH_OPTIONS) != 0) return PCRE2_ERROR_BADOPTION;
+if (code == NULL || subject == NULL || match_data == NULL)
+ return PCRE2_ERROR_NULL;
+start_match = subject + start_offset;
+req_cu_ptr = start_match - 1;
if (length == PCRE2_ZERO_TERMINATED)
{
length = PRIV(strlen)(subject);
@@ -6180,11 +6185,6 @@ if (length == PCRE2_ZERO_TERMINATED)
}
true_end_subject = end_subject = subject + length;
-/* Plausibility checks */
-
-if ((options & ~PUBLIC_MATCH_OPTIONS) != 0) return PCRE2_ERROR_BADOPTION;
-if (code == NULL || subject == NULL || match_data == NULL)
- return PCRE2_ERROR_NULL;
if (start_offset > length) return PCRE2_ERROR_BADOFFSET;
/* Check that the first field in the block is the magic number. */
diff --git a/src/pcre2_substitute.c b/src/pcre2_substitute.c
index 981a106..7aefb60 100644
--- a/src/pcre2_substitute.c
+++ b/src/pcre2_substitute.c
@@ -260,6 +260,12 @@ PCRE2_UNSET, so as not to imply an offset in the replacement. */
if ((options & (PCRE2_PARTIAL_HARD|PCRE2_PARTIAL_SOFT)) != 0)
return PCRE2_ERROR_BADOPTION;
+/* Validate length and find the end of the replacement. */
+if (replacement == NULL && rlength > 0) return PCRE2_ERROR_NULL;
+else if (rlength == PCRE2_ZERO_TERMINATED)
+ rlength = PRIV(strlen)(replacement);
+repend = replacement + rlength;
+
/* Check for using a match that has already happened. Note that the subject
pointer in the match data may be NULL after a no-match. */
@@ -292,6 +298,7 @@ else if (use_existing_match)
(pcre2_general_context *)mcontext;
int pairs = (code->top_bracket + 1 < match_data->oveccount)?
code->top_bracket + 1 : match_data->oveccount;
+ if (subject == NULL) return PCRE2_ERROR_NULL;
internal_match_data = pcre2_match_data_create(match_data->oveccount,
gcontext);
if (internal_match_data == NULL) return PCRE2_ERROR_NOMEMORY;
@@ -312,11 +319,9 @@ scb.input = subject;
scb.output = (PCRE2_SPTR)buffer;
scb.ovector = ovector;
-/* Find lengths of zero-terminated strings and the end of the replacement. */
-
-if (length == PCRE2_ZERO_TERMINATED) length = PRIV(strlen)(subject);
-if (rlength == PCRE2_ZERO_TERMINATED) rlength = PRIV(strlen)(replacement);
-repend = replacement + rlength;
+/* Find lengths of zero-terminated subject */
+if (length == PCRE2_ZERO_TERMINATED)
+ length = subject? PRIV(strlen)(subject) : 0;
/* Check UTF replacement string if necessary. */
--
2.27.0

View File

@ -0,0 +1,120 @@
From 7db87842963394d250b8405cdb513a502b479005 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= <carenas@gmail.com>
Date: Tue, 9 Nov 2021 08:57:48 -0800
Subject: [PATCH] pcre2grep: correctly handle multiple passes (#35)
* tests: use a explicit filehandle to share in testing -m
The way stdin is shared to all participants of a subshell varies
per shell, and at least the standard /bin/sh in Solaris seem to
create a new copy for each command, defeating the purpose of the
test.
Use instead exec to create a filehandle that could then be used
explicitly in the test to confirm that the stream is set.
* pcre2grep: correctly handle multiple passes
When the -m option is used, pcre2grep is meant to exit after enough
matches are found but while leaving the stream pinned to the next position
after the last match.
Unfortunately, it wasn't tracking correctly the beginning of the stream
on subsequent passes, and therefore it will fail to use the right seek
value.
Grab the position of the stream at the beginning and while at it, make
sure that the stream passed hasn't been consumed already.
Conflict:NA
Reference:https://github.com/PCRE2Project/pcre2/commit/7db87842963394d250b8405cdb513a502b479005
---
RunGrepTest | 6 +++++-
src/pcre2grep.c | 15 ++++++++++++---
testdata/grepoutput | 11 +++++++++++
3 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/RunGrepTest b/RunGrepTest
index 25f69bd..9682c5f 100755
--- a/RunGrepTest
+++ b/RunGrepTest
@@ -674,10 +674,14 @@ echo "---------------------------- Test 131 -----------------------------" >>tes
echo "RC=$?" >>testtrygrep
echo "---------------------------- Test 132 -----------------------------" >>testtrygrep
-(cd $srcdir; $valgrind $vjs $pcre2grep -m1 -A3 '^match'; echo '---'; head -1) <$srcdir/testdata/grepinput >>testtrygrep 2>&1
+(cd $srcdir; exec 3<$srcdir/testdata/grepinput; $valgrind $vjs $pcre2grep -m1 -A3 '^match' <&3; echo '---'; head -1 <&3; exec 3<&-) >>testtrygrep 2>&1
echo "RC=$?" >>testtrygrep
echo "---------------------------- Test 133 -----------------------------" >>testtrygrep
+(cd $srcdir; exec 3<$srcdir/testdata/grepinput; $valgrind $vjs $pcre2grep -m1 -A3 '^match' <&3; echo '---'; $valgrind $vjs $pcre2grep -m1 -A3 '^match' <&3; exec 3<&-) >>testtrygrep 2>&1
+echo "RC=$?" >>testtrygrep
+
+echo "---------------------------- Test 134 -----------------------------" >>testtrygrep
(cd $srcdir; $valgrind $vjs $pcre2grep -m1 -O '=$x{41}$x423$o{103}$o1045=' 'fox') <$srcdir/testdata/grepinputv >>testtrygrep 2>&1
echo "RC=$?" >>testtrygrep
diff --git a/src/pcre2grep.c b/src/pcre2grep.c
index aa84ea7..519346b 100644
--- a/src/pcre2grep.c
+++ b/src/pcre2grep.c
@@ -2538,6 +2538,7 @@ BOOL endhyphenpending = FALSE;
BOOL lines_printed = FALSE;
BOOL input_line_buffered = line_buffered;
FILE *in = NULL; /* Ensure initialized */
+long stream_start = -1; /* Only non-negative if relevant */
/* Do the first read into the start of the buffer and set up the pointer to end
of what we have. In the case of libz, a non-zipped .gz file will be read as a
@@ -2547,7 +2548,15 @@ fail. */
if (frtype != FR_LIBZ && frtype != FR_LIBBZ2)
{
in = (FILE *)handle;
- if (is_file_tty(in)) input_line_buffered = TRUE;
+ if (feof(in))
+ return 1;
+ if (is_file_tty(in))
+ input_line_buffered = TRUE;
+ else
+ {
+ if (count_limit >= 0 && filename == stdin_name)
+ stream_start = ftell(in);
+ }
}
else input_line_buffered = FALSE;
@@ -2594,8 +2603,8 @@ while (ptr < endptr)
if (count_limit >= 0 && count_matched_lines >= count_limit)
{
- if (frtype == FR_PLAIN && filename == stdin_name && !is_file_tty(handle))
- (void)fseek(handle, (long int)filepos, SEEK_SET);
+ if (stream_start >= 0)
+ (void)fseek(handle, stream_start + (long int)filepos, SEEK_SET);
rc = (count_limit == 0)? 1 : 0;
break;
}
diff --git a/testdata/grepoutput b/testdata/grepoutput
index 5f3b97c..66af4cf 100644
--- a/testdata/grepoutput
+++ b/testdata/grepoutput
@@ -978,5 +978,16 @@ match 2:
a
RC=0
---------------------------- Test 133 -----------------------------
+match 1:
+ a
+match 2:
+ b
+---
+match 2:
+ b
+match 3:
+ c
+RC=0
+---------------------------- Test 134 -----------------------------
=AB3CD5=
RC=0
--
2.27.0

View File

@ -1,16 +1,28 @@
Name: pcre2
Version: 10.39
Release: 2
Release: 3
Summary: Perl Compatible Regular Expressions
License: BSD
URL: http://www.pcre.org/
Source0: https://ftp.pcre.org/pub/pcre/%{name}-%{version}.tar.bz2
# Do no set RPATH if libdir is not /usr/lib
Patch0: backport-pcre2-10.10-Fix-multilib.patch
Patch1: backport-CVE-2022-1586-1.patch
Patch2: backport-CVE-2022-1586-2.patch
Patch3: backport-CVE-2022-1587.patch
Patch6000: backport-pcre2-10.10-Fix-multilib.patch
Patch6001: backport-CVE-2022-1586-1.patch
Patch6002: backport-CVE-2022-1586-2.patch
Patch6003: backport-CVE-2022-1587.patch
Patch6004: backport-pcre2grep-correctly-handle-multiple-passes-35.patch
Patch6005: backport-jit-avoid-integer-wraparound-in-stack-size-definitio.patch
Patch6006: backport-Revert-an-unintended-change-in-JIT-repeat-detection.patch
Patch6007: backport-match-avoid-crash-if-subject-NULL-and-PCRE2_ZERO_TER.patch
Patch6008: backport-jit-use-correct-type-when-checking-for-max-value-73.patch
Patch6009: backport-Fix-recursion-issue-in-JIT.patch
Patch6010: backport-doc-avoid-nonexistent-PCRE2_ERROR_MEMORY-error-107.patch
Patch6011: backport-Update-HTML-docs.patch
Patch6012: backport-Fixed-race-condition-that-occurs-when-initializing-t.patch
Patch6013: backport-Change-length-variables-in-pcre2grep-from-int-to-siz.patch
Patch6014: backport-Add-an-ifdef-to-avoid-the-need-even-to-link-with-pcr.patch
Patch6015: backport-Fixed-an-issue-in-the-backtracking-optimization-of-c.patch
BuildRequires: autoconf libtool automake coreutils gcc make readline-devel
Obsoletes: pcre2-utf16 pcre2-utf32 pcre2-tools
@ -127,6 +139,9 @@ make check
%{_pkgdocdir}/html/
%changelog
* Tue Oct 18 2022 yangmingtai <yangmingtai@huawei.com> - 10.39-3
- DESC:sync community patchs
* Sat May 28 2022 yangmingtai <yangmingtai@huawei.com> - 10.39-2
- DESC:fix CVE-2022-1586 and CVE-2022-1587