Zero out unused bytes in snapshots (#1980)

Compiled code blocks are sized in multiples of JMEM_ALIGNMENT,
but it's possible that some bytes at the end remain unused and get filled
with junk. This causes snapshot output to become nondeterministic.
To fix this, zero out the compiled code buffer before using it.

JerryScript-DCO-1.0-Signed-off-by: Martijn The [email protected]
This commit is contained in:
Martijn Thé authored and László Langó committed 2018-01-26 08:26:09 +01:00
1 parent 4b699e997a
commit 0d04c805ac
2 files changed
+34

No files matched your search

+20
View File
@@ -123,6 +123,26 @@ main (void)
global_mode_snapshot_buffer,
SNAPSHOT_BUFFER_SIZE);
TEST_ASSERT (global_mode_snapshot_size != 0);
/* Check the snapshot data. Unused bytes should be filled with zeroes */
const uint8_t expected_data[] =
{
0x4A, 0x52, 0x52, 0x59, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
0x03, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x28, 0x00,
0xB7, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x01, 0x00, 0x21, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x47, 0x00,
0x1C, 0x00, 0x00, 0x00, 0x14, 0x00, 0x73, 0x74,
0x72, 0x69, 0x6E, 0x67, 0x20, 0x66, 0x72, 0x6F,
0x6D, 0x20, 0x73, 0x6E, 0x61, 0x70, 0x73, 0x68,
0x6F, 0x74, 0x00, 0x00,
};
TEST_ASSERT (sizeof (expected_data) == global_mode_snapshot_size);
TEST_ASSERT (0 == memcmp (expected_data, global_mode_snapshot_buffer, sizeof (expected_data)));
jerry_cleanup ();
jerry_init (JERRY_INIT_EMPTY);