moonchen opened a new pull request, #13441:
URL: https://github.com/apache/trafficserver/pull/13441

   A capture group that does not participate in a match has unset offsets. 
`RegexMatches::operator[]` only compared the index against the ovector count, 
which is not sufficient: `pcre2_match()` returns one past the highest 
*participating* group, so an optional group that precedes a participating one 
is inside that count with its offsets unset.
   
   For pattern `(a)?(b)` on subject `b`, the match count is 3 and group 1 is 
`PCRE2_UNSET`. The index check passes and the subject pointer is advanced by 
`PCRE2_UNSET`.
   
   The resulting view has length zero, because the length is computed as `end - 
start` and both are unset, so callers see an empty string and nothing 
observably breaks today. The pointer itself is invalid, which is what this 
fixes. `operator[]` now returns a default `std::string_view` for a group that 
did not participate.
   
   Found while reviewing #13352, which works around the same underlying 
behavior in the prefetch plugin. That plugin guards the trailing-optional-group 
case; this is the general fix, and other callers index the ovector the same way 
(`plugins/regex_remap/regex_remap.cc`, `plugins/cachekey/pattern.cc`, 
`plugins/regex_revalidate/regex_revalidate.cc`).
   
   ### Tests
   
   New section in `test_Regex.cc` covering a non-participating group before a 
participating one. It fails on master (the returned pointer is non-null) and 
passes with this change. Full `test_tsutil` suite passes: 458 assertions, 28 
cases.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to