Skip to content

Pr1116 symbol replace - #1119

Merged
xeioex merged 3 commits into
nginx:masterfrom
xeioex:pr1116-symbol-replace
Sep 4, 2026
Merged

Pr1116 symbol replace#1119
xeioex merged 3 commits into
nginx:masterfrom
xeioex:pr1116-symbol-replace

Conversation

@xeioex

@xeioex xeioex commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

And extended fix for issue reported in #1116.

Previously, the matched string returned by exec() was assumed to be a
substring of the subject at the reported index.
njs_string_get_substitution() converted "index + matched length" to a byte
offset without a bounds check, and the replace loop advanced the end of the
last match by the byte size of the matched string instead of its character
length.  As a result the $' expansion read outside the subject, and on a
multibyte subject the result could start in the middle of a UTF-8 sequence.

The fix is to pass the head and tail slices of the subject to
njs_string_get_substitution() and to track the end of the last match as a
character index.  The function no longer converts indexes to offsets, so the
out of range conversion is prevented by construction.

This is an extended fix for nginx#1116 pull request on Github.

Reported by Basavaraj S m (basavaraj@digiscrypt.com).
Previously, njs_mp_alloc_large() embedded the block descriptor at the end of
the allocation for sizes which are not a power of two, so a read past the end
of an object stayed inside the malloc()ed region and was not detected by the
address sanitizer.

The fix is to always allocate the descriptor separately when the address
sanitizer is enabled.

@VadimZhestikov VadimZhestikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@github-project-automation github-project-automation Bot moved this from New to In Review in NGINX OSS Unified Workspace Sep 4, 2026
@xeioex
xeioex merged commit 5614d8e into nginx:master Sep 4, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in NGINX OSS Unified Workspace Sep 4, 2026
@xeioex xeioex mentioned this pull request Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants