pfalcon / re1.5

re1, the unbloated regexp engine by Russ Cox, elaborated to be useful for real-world applications
BSD 3-Clause "New" or "Revised" License
42 stars 4 forks source link

compilecode: Reject escaped end of string. #21

Closed ampli closed 9 years ago

ampli commented 9 years ago

Patterns with odd number of backslashes at their end are invalid.

What happens currently:

$ ./re -d '\'  test | cat -v
Precalculated size: 20
 0: rsplit 5 (3)
 2: any
 3: jmp 0 (-5)
 5: save 0
 7: char ^@
 9: char t
11: char e
13: char s
15: char t
17: save 1
19: match
Bytes: 20, insts: 11

Note that the end NUL byte is what is actually escaped, and then compilecode() misses the end of string (a kind of a buffer overflow) and continue to compile the subject string...

After this fix:

$ ./re -ed pike 'a\' test
Precalculated size: -1
fatal error: Error in regexp

In python3:

...
sre_constants.error: bogus escape (end of line)
pfalcon commented 9 years ago

Merged, thanks. Probably would make sense to have a testcase for this (dunno if we support "nagative" tests ;-) ).

dpgeorge commented 9 years ago

dunno if we support "nagative" tests

Yes, see #23.