Repository navigation
match_next: validate pointer arguments and pattern reference in pcre2_next_match - #1053
akashdeshmukh-git wants to merge 1 commit into
Conversation
| if (match_data == NULL || pstart_offset == NULL || poptions == NULL) | ||
| return FALSE; |
There was a problem hiding this comment.
We should not add runtime checks for preconditions.
| PCRE2_SIZE subject_length = match_data->subject_length; | ||
| #ifdef SUPPORT_UNICODE | ||
| BOOL utf = (match_data->code->overall_options & PCRE2_UTF) != 0; | ||
| BOOL utf = (match_data->code != NULL && (match_data->code->overall_options & PCRE2_UTF) != 0); |
There was a problem hiding this comment.
Interesting - elsewhere in PCRE2, do we make the assumption that ->code fields are non-null if match_data->rc is a success?
It's possible that we do. What was the scenario that you wanted to guard against here, in terms of a practical use-case?
I can only imagine here that the match_data has simply not even been passed to pcre2_match.
2c20ce5 to
b49f32a
Compare
|
@NWilson Thanks. You're right: after a successful match |
pcre2_next_match()unconditionally dereferenced its pointer arguments (match_data->start_offset,match_data->ovector) without validating thatmatch_data,pstart_offset, orpoptionswere non-NULL. Additionally, the internaldo_bumpalong()helper dereferencedmatch_data->codeto query newline and UTF options without verifying thatmatch_data->codeis non-NULL.This change:
PCRE2_ASSERT()preconditions and returnsFALSEearly ifmatch_data,pstart_offset, orpoptionsis NULL.match_data->codeandmatch_data->subjectindo_bumpalong()when inspecting newline conventions and advancing across code units.unittest()insrc/pcre2test_inc.hwith test coverage verifying that NULL arguments safely returnFALSE.doc/pcre2api.adocanddoc/pcre2_next_match.adoc.