Skip to content

Commit 4bb5f7c

Browse files
authored
Merge pull request #5738 from larsewi/package_commands_useshell
Fixed invalid read of size 8 in function FirstBackReference
2 parents 7b73e78 + aecb4a2 commit 4bb5f7c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

libpromises/matching.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ static char *FirstBackReference(Regex *regex, const char *teststring)
5050
* negative numbers are errors (incl. no match). */
5151
if (result > 0)
5252
{
53+
uint32_t num_pairs = pcre2_get_ovector_count(match_data);
54+
if (num_pairs <= 1)
55+
{
56+
/* There was no match */
57+
strlcpy(backreference, "CF_NOMATCH", CF_MAXVARSIZE);
58+
pcre2_match_data_free(match_data);
59+
RegexDestroy(regex);
60+
return backreference;
61+
}
62+
5363
size_t *ovector = pcre2_get_ovector_pointer(match_data);
5464
/* ovector[0] and ovector[1] are for the start and end of the whole
5565
* match, the capture groups follow in [2] and [3], etc. */

0 commit comments

Comments
 (0)