match: avoid segmentation fault with no_regex #332
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In f398927 (Use different colors for subpattern matches., 2023-01-09),
match_pattern()
was changed so that thesp
andep
pointers no longer refer to a single start/end but to an array.Unfortunately, the
match()
function that is used in the no-regex case was not adjusted correctly. While it does advancesp
andep
to the next array elements in case of a match, that advancement is only visible to thematch()
function, but not to its caller,match_pattern()
, which subsequently assigns*sp = *ep = NULL
, overwriting the values that were assigned by thematch()
function.As a consequence, the invariant where
search_range()
expects thesp
/ep
values to be non-NULL
ifmatch_pattern()
returns non-zero is violated, and thehilite_line()
function will callcreate_hilites()
with those invalid values and subsequently access memory at an insanely largestart_index
, and crash.Fix this by changing the
match()
function in a way where thesp
/ep
modifications are visible to its caller.