Skip to content

Commit 4fa5b8b

Browse files
committed
Ignore non-significant leading zeros when processing quantifiers in fuzz support
1 parent 2b30cb3 commit 4fa5b8b

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

ChangeLog

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ Version 10.45 xx-xxx-2024
1111
memory size was changed to the entire compiled data block, instead of just the
1212
pattern and tables data, so as to align with the new length restriction.
1313
Because the block's header contains pointers, this meant the pcre2test output
14-
was different in 32-bit mode. A patch by Carlo reverts to the preevious state
14+
was different in 32-bit mode. A patch by Carlo reverts to the previous state
1515
and makes sure that any limit set by pcre2_set_max_pattern_compiled_length()
1616
also avoids the internal struct overhead.
1717

1818
2. Add --posix-pattern-file to pcre2grep to allow processing of empty patterns
19-
through the -f option, as well as patterns that end in space characters for
19+
through the -f option, as well as patterns that end in space characters, for
2020
compatibility with other grep tools.
2121

22+
3. Fix a but in the fuzz support quantifier-limiting code. It ignores strings
23+
of more than 5 digits because they are necessarily numbers greater than 65535,
24+
the largest legal quantifier. However, it wasn't ignoring non-significant
25+
leading zeros.
26+
2227

2328
Version 10.44 07-June-2024
2429
--------------------------

src/pcre2_fuzzsupport.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,24 +328,33 @@ if (size > 3)
328328
continue;
329329
i++; /* Points to '{' */
330330

331-
/* Loop for two values a quantifier. Offset i points to brace or comma at the
332-
start of the loop.*/
331+
/* Loop for two values in a quantifier. Offset i points to brace or comma
332+
at the start of the loop. */
333333

334334
for (int ii = 0; ii < 2; ii++)
335335
{
336336
int q = 0;
337337

338338
if (i >= size - 1) goto END_QSCAN; /* Can happen for , */
339339

340-
/* Ignore leading spaces */
340+
/* Ignore leading spaces. */
341341

342342
while (wdata[i+1] == ' ' || wdata[i+1] == '\t')
343343
{
344344
i++;
345345
if (i >= size - 1) goto END_QSCAN;
346346
}
347347

348-
/* Scan for a number ending in brace or comma in the first iteration,
348+
/* Ignore non-significant leading zeros. */
349+
350+
while (wdata[i+1] == '0' && i+2 < size && wdata[i+2] >= '0' &&
351+
wdata[i+2] <= '9')
352+
{
353+
i++;
354+
if (i >= size - 1) goto END_QSCAN;
355+
}
356+
357+
/* Scan for a number ending in brace, or comma in the first iteration,
349358
optionally preceded by space. */
350359

351360
for (j = i + 1; j < size && j < i + 7; j++)
@@ -358,6 +367,7 @@ if (size > 3)
358367
if (wdata[j] != '}' && wdata[j] != ',') goto OUTERLOOP;
359368
}
360369
if (wdata[j] == '}' || (ii == 0 && wdata[j] == ',')) break;
370+
361371
if (wdata[j] < '0' || wdata[j] > '9')
362372
{
363373
j--; /* Ensure this character is checked next. The */
@@ -368,8 +378,8 @@ if (size > 3)
368378

369379
if (j >= size) goto END_QSCAN; /* End of data */
370380

371-
/* Hit ',' or '}' or read 6 digits. Six digits is a number > 65536 which is
372-
the maximum quantifier. Leave such numbers alone. */
381+
/* Hit ',' or '}' or read 6 digits. Six digits is a number > 65536 which
382+
is the maximum quantifier. Leave such numbers alone. */
373383

374384
if (j >= i + 7 || q > 65535) goto OUTERLOOP;
375385

0 commit comments

Comments
 (0)