Skip to content

Commit

Permalink
Fix a further batch of bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
NWilson committed Nov 30, 2024
1 parent 7056cdf commit 2a5727f
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 521 deletions.
4 changes: 2 additions & 2 deletions src/pcre2_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -6292,7 +6292,7 @@ for (;; pptr++)
/* Next do the memmove before any writes. */
memmove(
code + 1 + LINK_SIZE + 1 + (need_map? 32/sizeof(PCRE2_UCHAR) : 0),
rest, rest_len*sizeof(PCRE2_UCHAR));
rest, CU2BYTES(rest_len));

/* Finally write the header data. */
*code++ = OP_XCLASS;
Expand Down Expand Up @@ -6333,7 +6333,7 @@ for (;; pptr++)
PCRE2_UCHAR *map_start = previous + 1 + LINK_SIZE + 1;
previous[1 + LINK_SIZE] |= ECL_MAP;
memmove(map_start + 32/sizeof(PCRE2_UCHAR), map_start,
(code - map_start) * sizeof(PCRE2_UCHAR));
CU2BYTES(code - map_start));
memcpy(map_start, op_info.bits.classbits, 32);
code += 32 / sizeof(PCRE2_UCHAR);
}
Expand Down
19 changes: 11 additions & 8 deletions src/pcre2_compile_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ while (TRUE)
local_negate = (meta == META_POSIX_NEG);
posix_class = *(pptr++);

should_flip_negation = local_negate; /* Note negative special */
if (local_negate) should_flip_negation = TRUE; /* Note negative special */

/* If matching is caseless, upper and lower are converted to alpha.
This relies on the fact that the class table starts with alpha,
Expand All @@ -1133,6 +1133,9 @@ while (TRUE)
XCL_PROP/XCL_NOTPROP directly, which is done here. */

#ifdef SUPPORT_UNICODE
/* TODO This entire block of code here appears to be unreachable!? I simply
can't see how it can be hit, given that the frontend parser doesn't emit
META_POSIX for GRAPH/PRINT/PUNCT when UCP is set. */
if ((options & PCRE2_UCP) != 0 &&
(xoptions & PCRE2_EXTRA_ASCII_POSIX) == 0)
{
Expand All @@ -1146,7 +1149,7 @@ while (TRUE)
ptype = (posix_class == PC_GRAPH)? PT_PXGRAPH :
(posix_class == PC_PRINT)? PT_PXPRINT : PT_PXPUNCT;

PRIV(update_classbits)(ptype, 0, !local_negate, classbits);
PRIV(update_classbits)(ptype, 0, local_negate, classbits);

if ((xclass_props & XCLASS_HIGH_ANY) == 0)
{
Expand Down Expand Up @@ -1226,7 +1229,7 @@ while (TRUE)

if (local_negate)
for (int i = 0; i < 8; i++)
classwords[i] |= (uint8_t)(~pbits.classwords[i]);
classwords[i] |= (uint32_t)(~pbits.classwords[i]);
else
for (int i = 0; i < 8; i++)
classwords[i] |= pbits.classwords[i];
Expand Down Expand Up @@ -1865,7 +1868,7 @@ else if (lhs_op_info->op_single_type == ECL_ANY)
/* no-op: drop the LHS, and memmove the RHS into its place */
if (lengthptr == NULL)
memmove(lhs_op_info->code_start, rhs_op_info->code_start,
rhs_op_info->length);
CU2BYTES(rhs_op_info->length));
lhs_op_info->length = rhs_op_info->length;
lhs_op_info->op_single_type = rhs_op_info->op_single_type;
}
Expand Down Expand Up @@ -1921,7 +1924,7 @@ else if (lhs_op_info->op_single_type == ECL_NONE)
/* no-op: drop the LHS, and memmove the RHS into its place */
if (lengthptr == NULL)
memmove(lhs_op_info->code_start, rhs_op_info->code_start,
rhs_op_info->length);
CU2BYTES(rhs_op_info->length));
lhs_op_info->length = rhs_op_info->length;
lhs_op_info->op_single_type = rhs_op_info->op_single_type;
}
Expand Down Expand Up @@ -1977,7 +1980,7 @@ else if (lhs_op_info->op_single_type == ECL_NONE)
/* no-op: drop the LHS, and memmove the RHS into its place */
if (lengthptr == NULL)
memmove(lhs_op_info->code_start, rhs_op_info->code_start,
rhs_op_info->length);
CU2BYTES(rhs_op_info->length));
lhs_op_info->length = rhs_op_info->length;
lhs_op_info->op_single_type = rhs_op_info->op_single_type;
}
Expand All @@ -1992,7 +1995,7 @@ else if (lhs_op_info->op_single_type == ECL_ANY)
fold in the negation */
if (lengthptr == NULL)
memmove(lhs_op_info->code_start, rhs_op_info->code_start,
rhs_op_info->length);
CU2BYTES(rhs_op_info->length));
lhs_op_info->length = rhs_op_info->length;
lhs_op_info->op_single_type = rhs_op_info->op_single_type;

Expand Down Expand Up @@ -2157,7 +2160,7 @@ switch (meta)
map_start = code_start + 1 + LINK_SIZE + 1;
data_start = map_start + 32 / sizeof(PCRE2_UCHAR);
memcpy(pop_info->bits.classbits, map_start, 32);
memmove(map_start, data_start, (code - data_start) * sizeof(PCRE2_UCHAR));
memmove(map_start, data_start, CU2BYTES(code - data_start));

/* Rewind the code pointer, but make sure we adjust *lengthptr, because we
do need to reserve that space (even though we only use it temporarily). */
Expand Down
30 changes: 15 additions & 15 deletions testdata/testoutput11-32
Original file line number Diff line number Diff line change
Expand Up @@ -903,9 +903,9 @@ No match
------------------------------------------------------------------
Bra
eclass[
cls:[\x{80000000}-\x{8000000f}]
cls:[\x{80000002}]
op: --
xclass: [\x{80000000}-\x{8000000f}]
xclass: [^\x{80000002}]
AND
]
Ket
End
Expand All @@ -922,9 +922,9 @@ No match
------------------------------------------------------------------
Bra
eclass[
cls:[\x{80000000}-\x{8000000f}]
cls:[\x{80000002}]
op: --
xclass: [\x{80000000}-\x{8000000f}]
xclass: [^\x{80000002}]
AND
]
Ket
End
Expand All @@ -947,9 +947,9 @@ No match
------------------------------------------------------------------
Bra
eclass[
cls:[\x{80000000}-\x{8000000f}]
cls:[\x{8fffffff}]
op: ||
xclass: [\x{80000000}-\x{8000000f}]
xclass: [\x{8fffffff}]
OR
]
Ket
End
Expand All @@ -968,9 +968,9 @@ No match
------------------------------------------------------------------
Bra
eclass[
cls:[\x{80000000}-\x{8000000f}]
cls:[\x{80000002}]
op: --
xclass: [\x{80000000}-\x{8000000f}]
xclass: [^\x{80000002}]
AND
]
Ket
End
Expand All @@ -987,9 +987,9 @@ No match
------------------------------------------------------------------
Bra
eclass[
cls:[\x{80000000}-\x{8000000f}]
cls:[\x{80000002}]
op: --
xclass: [\x{80000000}-\x{8000000f}]
xclass: [^\x{80000002}]
AND
]
Ket
End
Expand Down
Loading

0 comments on commit 2a5727f

Please sign in to comment.