fix off-by-one write in c14n namespace prefix list - #1117
Closed
basavaraj-sm05 wants to merge 1 commit into
Closed
Conversation
|
🎉 Thank you for your contribution! It appears you have not yet signed the F5 Contributor License Agreement (CLA), which is required for your changes to be incorporated into an F5 Open Source Software (OSS) project. Please kindly read the F5 CLA and reply on a new comment with the following text to agree: I have hereby read the F5 CLA and agree to its terms You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
Contributor
|
Thank you, This was reported earlier and fixed as a security fix in 1.0.1 njs release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
The C14N helpers (
xml.c14n,xml.exclusiveC14n,xml.serializeToString) take an inclusive-namespaceprefixesstring straight from script and split it into a NULL-terminated pointer array innjs_xml_parse_ns_list(). The array starts at eight slots and doubles whenever the next token would not fit, but the growth check only reserves room for the token itself, never for the terminating NULL. So once the token count reaches the current capacity exactly (8, 16, 32, ...), every slot is filled and the final*out = NULLwrites one element past the end of the allocation. I ran into it while exercisingexclusiveC14nwith longer prefix lists: at 128 tokens the array is a 1 KiB pool allocation and ASAN reports an 8-byte heap-buffer-overflow write at the terminator. Growing one slot earlier (idx + 1 >= size) keeps a spare slot for the terminator and leaves valid-input behavior unchanged. The QuickJS module carries the same helper with the same off-by-one, so I fixed both, and the added c14n case uses a power-of-two prefix count to cover the boundary the existing ten-token test steps over.Checklist
Before creating a PR, run through this checklist and mark each as complete:
CONTRIBUTINGdocument