Skip to content

Commit

Permalink
Fix two small issues with substitution nulls (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
NWilson authored Sep 27, 2024
1 parent a79dc73 commit 311eef6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/pcre2_substitute.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,9 @@ do

save_start = start_offset++;
if (subject[start_offset-1] == CHAR_CR &&
code->newline_convention != PCRE2_NEWLINE_CR &&
code->newline_convention != PCRE2_NEWLINE_LF &&
(code->newline_convention == PCRE2_NEWLINE_CRLF ||
code->newline_convention == PCRE2_NEWLINE_ANY ||
code->newline_convention == PCRE2_NEWLINE_ANYCRLF) &&
start_offset < length &&
subject[start_offset] == CHAR_LF)
start_offset++;
Expand Down Expand Up @@ -824,10 +825,10 @@ do
PCRE2_SPTR mark = pcre2_get_mark(match_data);
if (mark != NULL)
{
PCRE2_SPTR mark_start = mark;
while (*mark != 0) mark++;
fraglength = mark - mark_start;
CHECKMEMCPY(mark_start, fraglength);
/* Peek backwards one code unit to obtain the length of the mark.
It can (theoretically) contain an embedded NUL. */
fraglength = mark[-1];
CHECKMEMCPY(mark, fraglength);
}
}
else goto BAD;
Expand Down
3 changes: 3 additions & 0 deletions testdata/testinput2
Original file line number Diff line number Diff line change
Expand Up @@ -4208,6 +4208,9 @@
/(*:pear)apple|(*:orange)lemon|(*:strawberry)blackberry/g,replace=[23]${*MARK}
apple lemon blackberry

/"(*:fruit" 00 "juice)apple"/hex,g,replace=${*MARK}
apple lemon blackberry

/abc/
123abc123\=replace=[9]XYZ
123abc123\=substitute_overflow_length,replace=[9]XYZ
Expand Down
4 changes: 4 additions & 0 deletions testdata/testoutput2
Original file line number Diff line number Diff line change
Expand Up @@ -13860,6 +13860,10 @@ Failed: error -48: no more memory: 23 code units are needed
apple lemon blackberry
3: pear orange strawberry

/"(*:fruit" 00 "juice)apple"/hex,g,replace=${*MARK}
apple lemon blackberry
1: fruit\x00juice lemon blackberry

/abc/
123abc123\=replace=[9]XYZ
Failed: error -48: no more memory
Expand Down

0 comments on commit 311eef6

Please sign in to comment.