Commit Graph

38 Commits

Author SHA1 Message Date
Philip Hazel d90fb23878 Refactor match_data() to always use the heap instead of having an initial frames vector on the stack; some consequential adjustmentsneeded. 2022-07-27 17:44:55 +01:00
Philip Hazel 1c41a5b815 Fix minor issues raised by Clang sanitize 2021-12-14 15:52:24 +00:00
Philip Hazel 4ef0c51d2b Interpret NULL pointer, zero length as an empty string for subjects and replacements. 2021-11-30 16:34:39 +00:00
Philip Hazel 7ab2769728 Check for NULL replacement in pcre2_substitute() 2021-11-28 17:19:17 +00:00
Carlo Marcelo Arenas Belón ae4e6261e5
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.
2021-11-27 16:49:31 +00:00
Philip.Hazel 4a7dfab0ec Unicode upper/lower casing is now used when UCP is set, even if UTF is not set.
This is not yet documented, and it not yet implemented in JIT.
2020-02-23 16:40:05 +00:00
Philip.Hazel a57787b7cd Fix problems with new PCRE2_SUBSTITUTE_MATCHED code. 2020-02-16 17:46:40 +00:00
Philip.Hazel e8d70e2459 Implement PCRE2_SUBSTITUTE_REPLACEMENT_ONLY. 2020-01-22 17:50:12 +00:00
Philip.Hazel d170829b26 Implement PCRE2_SUBSTITUTE_MATCHED. 2019-12-27 13:35:17 +00:00
Philip.Hazel f3fd8b18cb Implement PCRE2_SUBSTITUTE_LITERAL. 2019-12-26 14:53:24 +00:00
Philip.Hazel 95c9d011e3 Change a number of expressions like 1<<10 to 1u<<10. 2019-04-12 14:40:27 +00:00
Philip.Hazel e85de98d0a Fix crash in pcre2_substitute() with NULL match context. 2019-03-11 17:29:08 +00:00
Philip.Hazel 8c8deae8eb Implement PCRE2_EXTRA_ALT_BSUX to support ECMAscript 6's \u{hhh..} syntax. 2019-02-12 17:50:19 +00:00
Philip.Hazel cd73c9319e Fix two instances of <= 0 being applied to unsigned integers. 2018-11-17 16:59:39 +00:00
Philip.Hazel 9bc81d5229 Upgrade the as yet unreleased substitute callout facility. 2018-11-12 16:02:01 +00:00
Philip.Hazel a69267246f Implement callouts from pcre2_substitute(). 2018-09-18 16:31:30 +00:00
Philip.Hazel 1c79bdf36f Fix global search/replace in pcre2test and pcre2_substitute() when the pattern
matches an empty string, but never at the starting offset.
2018-07-02 10:54:03 +00:00
Philip.Hazel 89c2a02027 Fix bug when \K is used in a lookbehind in a substitute pattern. 2018-06-22 16:29:56 +00:00
Philip.Hazel 7914fa82a9 Fix OOB error in substitute with start offset longer than length. 2016-12-09 18:19:38 +00:00
Philip.Hazel 99264dfc23 Major refactoring of pcre2_compile.c; see ChangeLog and HACKING. 2016-10-02 16:01:01 +00:00
Philip.Hazel bebd2d48bf Final file updates for 10.21 release. 2016-01-12 14:44:34 +00:00
Philip.Hazel 35e0f55783 Implement PCRE2_SUBSTITUTE_{OVERFLOW_LENGTH,UNKNOWN_UNSET}. 2015-12-12 18:45:40 +00:00
Philip.Hazel 2f684a60ed Implement PCRE2_SUBSTITUTE_UNSET_EMPTY. 2015-12-04 18:39:08 +00:00
Philip.Hazel 299e587f9b Don't split CRLF in pcre2_substitute() when it's a valid newline sequence. 2015-11-13 16:52:26 +00:00
Philip.Hazel 9c5958fbe6 Check for too many replacements (more than INT_MAX) in pcre2_substitute() 2015-11-11 18:35:14 +00:00
Philip.Hazel 2caf22dc61 Forbid \K patterns that end before they start in pcre2_substitute(). 2015-11-03 17:38:00 +00:00
Philip.Hazel a0d04b9fa3 Fix off-by-one bug in pcre2_substitute(). 2015-11-01 16:36:20 +00:00
Philip.Hazel 284d42fa7e Avoid the need for an integer overflow check in pcre2_substitute() by adding a
check for a number greater than the largest capturing group.
2015-10-30 18:25:19 +00:00
Philip.Hazel 890250535b Use PCRE2_NO_UTF_CHECK for the second and subsequent matches in
pcre2_substitute().
2015-10-30 17:41:56 +00:00
Philip.Hazel efccea98f1 Fix pcre2_substitute(): set zero-terminated length before UTF validity check. 2015-10-30 17:30:03 +00:00
Philip.Hazel 836fbb1148 Fix erroneous "\ at end of pattern" errors, introduced by
PCRE2_SUBSTITUTE_EXTENDED patch.
2015-10-17 18:29:01 +00:00
Philip.Hazel 6ae5c36e83 Implement PCRE2_SUBSTITUTE_EXTENDED. 2015-10-07 17:32:48 +00:00
Philip.Hazel 170644eca3 Add ${*MARK} feature to pcre2_substitute(). 2015-08-29 17:13:09 +00:00
Philip.Hazel 154bc83cb5 Fix replacement bug in pcre2_substitute(). 2015-02-10 12:48:45 +00:00
Philip.Hazel 07f8372202 Further substitution tests (code and data), and more documentation. 2014-11-14 18:41:20 +00:00
Philip.Hazel b3ac0ffb32 Substitute code update and documentation. 2014-11-11 16:51:07 +00:00
Philip.Hazel f1c6ee730a Code for pcre2_substitute(), and tests. 2014-11-11 10:19:23 +00:00
Philip.Hazel a9f31c3377 Preliminary substitute function (not yet tested or documented). 2014-11-08 16:09:24 +00:00