This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
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.
Bounty URL: https://huntr.dev/bounties/1-other-mjs/
Description
Fixes how a heap buffer is allocates and properly copies over parsed JSON string to prevent any out-of-bounds read/writes.
It turns out that the culprit for this didn't exist in
json_get_escape_len
, but rather the very first allocation that gets made before copying over the parsed JSON string to begin parsing:https://github.com/cesanta/mjs/blob/4c870e584d2b2a538abcee5307c498cc37e7ef9d/mjs/src/mjs_json.c#L448=L449
Since a string is being copied over, the buffer allocation is made with size
len + 1
, and aftermemcpy
, a null byte is written to the end.Proof of Fix
Without the fix, mjs copies over garbage to the buffer for the previously mentioned test case:
With the fix and the insertion of the null-byte, the buffer points to the correct string being parsed: