Skip to content

Commit f5afbeb

Browse files
authored
Fixed a couple of double frees.
Specifically, these occured when using PCRE2_COPY_MATCHED_SUBJECT and PCRE2_SUBSTITUTE_MATCHED. (cherry picked from commit dd1a5ed)
1 parent b88fc11 commit f5afbeb

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/pcre2_substitute.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,8 @@ else if (use_existing_match)
852852
+ 2*pairs*sizeof(PCRE2_SIZE));
853853
internal_match_data->heapframes = NULL;
854854
internal_match_data->heapframes_size = 0;
855+
/* Ensure that the subject is not freed when internal_match_data is */
856+
internal_match_data->flags &= ~PCRE2_MD_COPIED_SUBJECT;
855857
match_data = internal_match_data;
856858
}
857859

testdata/testinput2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8108,4 +8108,9 @@ a)"xI
81088108
/x/replace=r,substitute_matched
81098109
x\=null_subject
81108110

8111+
# Test that a couple of double frees have been fixed
8112+
/foo/replace=bar,substitute_matched
8113+
foo\=copy_matched_subject
8114+
foo\=global,copy_matched_subject
8115+
81118116
# End of testinput2

testdata/testoutput2

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23234,6 +23234,13 @@ Failed: error 217 at offset 27: expected capture group number or name
2323423234
x\=null_subject
2323523235
Failed: error -51: NULL argument passed with non-zero length
2323623236

23237+
# Test that a couple of double frees have been fixed
23238+
/foo/replace=bar,substitute_matched
23239+
foo\=copy_matched_subject
23240+
1: bar
23241+
foo\=global,copy_matched_subject
23242+
1: bar
23243+
2323723244
# End of testinput2
2323823245
Error -80: PCRE2_ERROR_BADDATA (unknown error number)
2323923246
Error -62: bad serialized data

0 commit comments

Comments
 (0)