slre: fix matching of escape sequence used inside character class
authorRasmus Villemoes <ravi@prevas.dk>
Tue, 13 May 2025 08:40:30 +0000 (10:40 +0200)
committerTom Rini <trini@konsulko.com>
Thu, 29 May 2025 14:25:18 +0000 (08:25 -0600)
commit5d3f91d6a82386e94c3178721641608563560871
treec8cb3bf9566a102251faa3455ef969add3721704
parent457f19815c8f8b74c36d8cbef454a0b575ea7068
slre: fix matching of escape sequence used inside character class

At the compile stage, the anyof() function clearly intends to handle escape
sequences like \d (for digits) inside square brackets, since the logic
emits a 0 byte followed by the code representing the character
class (NONSPACE, SPACE or DIGIT).

However, this is not handled in the corresponding match helper
is_any_of(); it just naively loops over all the bytes in the ->data
array emitted by anyof() and compares those directly to the current
character. For example, this means that the string "\x11" (containing
the single character with value 17) is matched by the regex "[#%\d]",
because DIGIT happens to be 17.

Fix that by recognizing a zero byte as indicating something special
and act accordingly. In order not to repeat the "increment *ofs and
return 1" in all places, put those two lines after a new match: label.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
lib/slre.c