Add new input validator API functions (#1576)
Fixes #1549 JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
This commit is contained in:
committed by
Dániel Bátyai
parent
93eb35081f
commit
799726aa42
@@ -151,7 +151,7 @@ ecma_new_ecma_string_from_utf8 (const lit_utf8_byte_t *string_p, /**< utf-8 stri
|
||||
lit_utf8_size_t string_size) /**< string size */
|
||||
{
|
||||
JERRY_ASSERT (string_p != NULL || string_size == 0);
|
||||
JERRY_ASSERT (lit_is_cesu8_string_valid (string_p, string_size));
|
||||
JERRY_ASSERT (lit_is_valid_cesu8_string (string_p, string_size));
|
||||
|
||||
lit_magic_string_id_t magic_string_id = lit_is_utf8_string_magic (string_p, string_size);
|
||||
|
||||
@@ -269,7 +269,7 @@ ecma_new_ecma_string_from_utf8_converted_to_cesu8 (const lit_utf8_byte_t *string
|
||||
{
|
||||
converted_string_size += string_size;
|
||||
|
||||
JERRY_ASSERT (lit_is_utf8_string_valid (string_p, string_size));
|
||||
JERRY_ASSERT (lit_is_valid_utf8_string (string_p, string_size));
|
||||
|
||||
lit_utf8_byte_t *data_p;
|
||||
|
||||
|
||||
@@ -899,7 +899,7 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri, /**< uri argumen
|
||||
}
|
||||
|
||||
if (!is_valid
|
||||
|| !lit_is_utf8_string_valid (octets, bytes_count))
|
||||
|| !lit_is_valid_utf8_string (octets, bytes_count))
|
||||
{
|
||||
ret_value = ecma_raise_uri_error (ECMA_ERR_MSG ("Invalid UTF8 string."));
|
||||
break;
|
||||
@@ -923,7 +923,7 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri, /**< uri argumen
|
||||
{
|
||||
JERRY_ASSERT (output_start_p + output_size == output_char_p);
|
||||
|
||||
if (lit_is_cesu8_string_valid (output_start_p, output_size))
|
||||
if (lit_is_valid_cesu8_string (output_start_p, output_size))
|
||||
{
|
||||
ecma_string_t *output_string_p = ecma_new_ecma_string_from_utf8 (output_start_p, output_size);
|
||||
ret_value = ecma_make_string_value (output_string_p);
|
||||
|
||||
+32
-4
@@ -982,7 +982,7 @@ jerry_create_object (void)
|
||||
} /* jerry_create_object */
|
||||
|
||||
/**
|
||||
* Create string from a valid UTF8 string
|
||||
* Create string from a valid UTF-8 string
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_release_value when it is no longer needed.
|
||||
@@ -996,7 +996,7 @@ jerry_create_string_from_utf8 (const jerry_char_t *str_p) /**< pointer to string
|
||||
} /* jerry_create_string_from_utf8 */
|
||||
|
||||
/**
|
||||
* Create string from a valid UTF8 string
|
||||
* Create string from a valid UTF-8 string
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_release_value when it is no longer needed.
|
||||
@@ -1016,7 +1016,7 @@ jerry_create_string_sz_from_utf8 (const jerry_char_t *str_p, /**< pointer to str
|
||||
} /* jerry_create_string_sz_from_utf8 */
|
||||
|
||||
/**
|
||||
* Create string from a valid CESU8 string
|
||||
* Create string from a valid CESU-8 string
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_release_value, when it is no longer needed.
|
||||
@@ -1030,7 +1030,7 @@ jerry_create_string (const jerry_char_t *str_p) /**< pointer to string */
|
||||
} /* jerry_create_string */
|
||||
|
||||
/**
|
||||
* Create string from a valid CESU8 string
|
||||
* Create string from a valid CESU-8 string
|
||||
*
|
||||
* Note:
|
||||
* returned value must be freed with jerry_release_value when it is no longer needed.
|
||||
@@ -2006,6 +2006,34 @@ jerry_foreach_object_property (const jerry_value_t obj_val, /**< object value */
|
||||
return false;
|
||||
} /* jerry_foreach_object_property */
|
||||
|
||||
/**
|
||||
* Validate UTF-8 string
|
||||
*
|
||||
* @return true - if UTF-8 string is well-formed
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
jerry_is_valid_utf8_string (const jerry_char_t *utf8_buf_p, /**< UTF-8 string */
|
||||
jerry_size_t buf_size) /**< string size */
|
||||
{
|
||||
return lit_is_valid_utf8_string ((lit_utf8_byte_t *) utf8_buf_p,
|
||||
(lit_utf8_size_t) buf_size);
|
||||
} /* jerry_is_valid_utf8_string */
|
||||
|
||||
/**
|
||||
* Validate CESU-8 string
|
||||
*
|
||||
* @return true - if CESU-8 string is well-formed
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
jerry_is_valid_cesu8_string (const jerry_char_t *cesu8_buf_p, /**< CESU-8 string */
|
||||
jerry_size_t buf_size) /**< string size */
|
||||
{
|
||||
return lit_is_valid_cesu8_string ((lit_utf8_byte_t *) cesu8_buf_p,
|
||||
(lit_utf8_size_t) buf_size);
|
||||
} /* jerry_is_valid_cesu8_string */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -329,6 +329,12 @@ void jerry_set_object_native_handle (const jerry_value_t obj_val, uintptr_t hand
|
||||
bool jerry_foreach_object_property (const jerry_value_t obj_val, jerry_object_property_foreach_t foreach_p,
|
||||
void *user_data_p);
|
||||
|
||||
/**
|
||||
* Input validator functions
|
||||
*/
|
||||
bool jerry_is_valid_utf8_string (const jerry_char_t *utf8_buf_p, jerry_size_t buf_size);
|
||||
bool jerry_is_valid_cesu8_string (const jerry_char_t *cesu8_buf_p, jerry_size_t buf_size);
|
||||
|
||||
/**
|
||||
* Snapshot functions
|
||||
*/
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
* false otherwise
|
||||
*/
|
||||
bool
|
||||
lit_is_utf8_string_valid (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string */
|
||||
lit_is_valid_utf8_string (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string */
|
||||
lit_utf8_size_t buf_size) /**< string size */
|
||||
{
|
||||
lit_utf8_size_t idx = 0;
|
||||
@@ -116,7 +116,7 @@ lit_is_utf8_string_valid (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string *
|
||||
}
|
||||
|
||||
return true;
|
||||
} /* lit_is_utf8_string_valid */
|
||||
} /* lit_is_valid_utf8_string */
|
||||
|
||||
/**
|
||||
* Validate cesu-8 string
|
||||
@@ -125,14 +125,14 @@ lit_is_utf8_string_valid (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string *
|
||||
* false otherwise
|
||||
*/
|
||||
bool
|
||||
lit_is_cesu8_string_valid (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string */
|
||||
lit_is_valid_cesu8_string (const lit_utf8_byte_t *cesu8_buf_p, /**< cesu-8 string */
|
||||
lit_utf8_size_t buf_size) /**< string size */
|
||||
{
|
||||
lit_utf8_size_t idx = 0;
|
||||
|
||||
while (idx < buf_size)
|
||||
{
|
||||
lit_utf8_byte_t c = utf8_buf_p[idx++];
|
||||
lit_utf8_byte_t c = cesu8_buf_p[idx++];
|
||||
if ((c & LIT_UTF8_1_BYTE_MASK) == LIT_UTF8_1_BYTE_MARKER)
|
||||
{
|
||||
continue;
|
||||
@@ -166,7 +166,7 @@ lit_is_cesu8_string_valid (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string
|
||||
|
||||
for (lit_utf8_size_t offset = 0; offset < extra_bytes_count; ++offset)
|
||||
{
|
||||
c = utf8_buf_p[idx + offset];
|
||||
c = cesu8_buf_p[idx + offset];
|
||||
if ((c & LIT_UTF8_EXTRA_BYTE_MASK) != LIT_UTF8_EXTRA_BYTE_MARKER)
|
||||
{
|
||||
/* invalid continuation byte */
|
||||
@@ -186,7 +186,7 @@ lit_is_cesu8_string_valid (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string
|
||||
}
|
||||
|
||||
return true;
|
||||
} /* lit_is_cesu8_string_valid */
|
||||
} /* lit_is_valid_cesu8_string */
|
||||
|
||||
/**
|
||||
* Check if the code point is UTF-16 low surrogate
|
||||
|
||||
@@ -85,8 +85,8 @@
|
||||
#define LIT_UTF8_FIRST_BYTE_MAX LIT_UTF8_5_BYTE_MARKER
|
||||
|
||||
/* validation */
|
||||
bool lit_is_utf8_string_valid (const lit_utf8_byte_t *utf8_buf_p, lit_utf8_size_t buf_size);
|
||||
bool lit_is_cesu8_string_valid (const lit_utf8_byte_t *utf8_buf_p, lit_utf8_size_t buf_size);
|
||||
bool lit_is_valid_utf8_string (const lit_utf8_byte_t *utf8_buf_p, lit_utf8_size_t buf_size);
|
||||
bool lit_is_valid_cesu8_string (const lit_utf8_byte_t *cesu8_buf_p, lit_utf8_size_t buf_size);
|
||||
|
||||
/* checks */
|
||||
bool lit_is_code_point_utf16_low_surrogate (lit_code_point_t code_point);
|
||||
|
||||
Reference in New Issue
Block a user