Add size checks before using JERRY_VLA in unittests (#4601)
JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.usz@partner.samsung.com
This commit is contained in:
@@ -55,7 +55,8 @@ assert_handler (const jerry_call_info_t *call_info_p, /**< call information */
|
||||
&& jerry_value_is_string (args_p[1]))
|
||||
{
|
||||
jerry_length_t utf8_sz = jerry_get_string_size (args_p[1]);
|
||||
JERRY_VLA (char, string_from_utf8, utf8_sz);
|
||||
TEST_ASSERT (utf8_sz <= 127); /* 127 is the expected max assert fail message size. */
|
||||
JERRY_VLA (char, string_from_utf8, utf8_sz + 1);
|
||||
string_from_utf8[utf8_sz] = 0;
|
||||
|
||||
jerry_string_to_char_buffer (args_p[1], (jerry_char_t *) string_from_utf8, utf8_sz);
|
||||
|
||||
@@ -53,6 +53,7 @@ main (void)
|
||||
TEST_ASSERT (jerry_value_is_string (name_value) == true);
|
||||
|
||||
jerry_size_t name_size = jerry_get_string_size (name_value);
|
||||
TEST_ASSERT (name_size == 4);
|
||||
JERRY_VLA (jerry_char_t, name_data, name_size + 1);
|
||||
jerry_size_t copied = jerry_string_to_char_buffer (name_value, name_data, name_size);
|
||||
name_data[name_size] = '\0';
|
||||
@@ -127,12 +128,13 @@ main (void)
|
||||
|
||||
jerry_release_value (obj);
|
||||
|
||||
const char check_value[] = "{\"name\":\"John\",\"age\":32}";
|
||||
jerry_size_t json_size = jerry_get_string_size (json_string);
|
||||
TEST_ASSERT (json_size == strlen (check_value));
|
||||
JERRY_VLA (jerry_char_t, json_data, json_size + 1);
|
||||
jerry_string_to_char_buffer (json_string, json_data, json_size);
|
||||
json_data[json_size] = '\0';
|
||||
|
||||
const char check_value[] = "{\"name\":\"John\",\"age\":32}";
|
||||
TEST_ASSERT_STR (check_value, json_data);
|
||||
|
||||
jerry_release_value (json_string);
|
||||
|
||||
@@ -47,12 +47,14 @@ main (void)
|
||||
jerry_value_t is_multiline = jerry_get_property_by_index (res, 1);
|
||||
jerry_value_t is_global = jerry_get_property_by_index (res, 2);
|
||||
|
||||
const char expected_result[] = "something";
|
||||
jerry_size_t str_size = jerry_get_string_size (regex_res_str);
|
||||
TEST_ASSERT (str_size == (sizeof (expected_result) - 1));
|
||||
|
||||
JERRY_VLA (jerry_char_t, res_buff, str_size);
|
||||
jerry_size_t res_size = jerry_string_to_char_buffer (regex_res_str, res_buff, str_size);
|
||||
|
||||
const char expected_result[] = "something";
|
||||
TEST_ASSERT (res_size == (sizeof (expected_result) - 1));
|
||||
TEST_ASSERT (res_size == str_size);
|
||||
TEST_ASSERT (strncmp (expected_result, (const char *) res_buff, res_size) == 0);
|
||||
TEST_ASSERT (jerry_get_boolean_value (is_multiline));
|
||||
TEST_ASSERT (jerry_get_boolean_value (is_global));
|
||||
|
||||
@@ -67,7 +67,8 @@ assert_handler (const jerry_call_info_t *call_info_p, /**< call information */
|
||||
&& jerry_value_is_string (args_p[1]))
|
||||
{
|
||||
jerry_length_t utf8_sz = jerry_get_string_size (args_p[1]);
|
||||
JERRY_VLA (char, string_from_utf8, utf8_sz);
|
||||
TEST_ASSERT (utf8_sz <= 127); /* 127 is the expected max assert fail message size. */
|
||||
JERRY_VLA (char, string_from_utf8, utf8_sz + 1);
|
||||
string_from_utf8[utf8_sz] = 0;
|
||||
|
||||
jerry_string_to_char_buffer (args_p[1], (jerry_char_t *) string_from_utf8, utf8_sz);
|
||||
|
||||
Reference in New Issue
Block a user