Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix two small issues with substitution nulls #501

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading