Conversation
process_generate() reads the entries of a --load-literals-list-format file into the fixed-size globals magic_string_items[JERRY_LITERAL_LENGTH] and magic_string_lengths[JERRY_LITERAL_LENGTH] (4096 entries). The parse loop increments num_of_lit without bounding it against the array capacity, so the 4097th entry writes past the end of both arrays. Reject a literals-list that would exceed JERRY_LITERAL_LENGTH before writing the entry. Fixes jerryscript-project#5293 JerryScript-DCO-1.0-Signed-off-by: PGZXB <pgzxb@qq.com>
This branch has not been deployed
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.
process_generate()in the jerry-snapshot tool reads the literal entries of a--load-literals-list-formatfile into two fixed-size globals,magic_string_items[JERRY_LITERAL_LENGTH]andmagic_string_lengths[JERRY_LITERAL_LENGTH](JERRY_LITERAL_LENGTHis 4096).The parse loop increments
num_of_litfor every entry with a positive size butnever checks it against the array capacity, so the 4097th entry writes
magic_string_items[4096]andmagic_string_lengths[4096]past the end of botharrays:
This is a global out-of-bounds write of an 8-byte pointer plus a
fully-controlled 4-byte value into the adjacent globals. A literals-list with
4097 entries and a one-line script is enough to trigger it:
The parser now rejects a list that would exceed the fixed capacity: when
num_of_lithas reachedJERRY_LITERAL_LENGTHit logs the error, cleans up andreturns a failure exit code instead of writing past the arrays.
Verification with the documented
--jerry-cmdline-snapshot=onbuild:SUMMARY: AddressSanitizer: global-buffer-overflow ... in process_generate(exit 1)Error: Too many literals in the list (maximum: 4096), no sanitizer reportCreated snapshot file: 'o4096.snapshot' (70 bytes), exit 0Fixes #5293
JerryScript-DCO-1.0-Signed-off-by: PGZXB pgzxb@qq.com