@@ -150,7 +150,8 @@ lexer_hex_in_braces_to_code_point (const uint8_t *source_p, /**< current source
150150 * @return character value
151151 */
152152static lit_code_point_t
153- lexer_unchecked_hex_to_character (const uint8_t * * source_p ) /**< [in, out] current source position */
153+ lexer_unchecked_hex_to_character (parser_context_t * context_p , /**< context */
154+ const uint8_t * * source_p ) /**< [in, out] current source position */
154155{
155156 lit_code_point_t result = 0 ;
156157 const uint8_t * char_p = * source_p ;
@@ -174,13 +175,19 @@ lexer_unchecked_hex_to_character (const uint8_t **source_p) /**< [in, out] curre
174175 }
175176 else
176177 {
177- JERRY_ASSERT ((byte >= LIT_CHAR_LOWERCASE_A && byte <= LIT_CHAR_LOWERCASE_F )
178- || (byte >= LIT_CHAR_UPPERCASE_A && byte <= LIT_CHAR_UPPERCASE_F ));
178+ if (!((byte >= LIT_CHAR_LOWERCASE_A && byte <= LIT_CHAR_LOWERCASE_F )
179+ || (byte >= LIT_CHAR_UPPERCASE_A && byte <= LIT_CHAR_UPPERCASE_F )))
180+ {
181+ parser_raise_error (context_p , PARSER_ERR_INVALID_UNICODE_ESCAPE_SEQUENCE );
182+ }
179183
180184 result += LEXER_TO_ASCII_LOWERCASE (byte ) - (LIT_CHAR_LOWERCASE_A - 10 );
181185 }
182186
183- JERRY_ASSERT (result <= LIT_UNICODE_CODE_POINT_MAX );
187+ if (result > LIT_UNICODE_CODE_POINT_MAX )
188+ {
189+ parser_raise_error (context_p , PARSER_ERR_INVALID_UNICODE_ESCAPE_SEQUENCE );
190+ }
184191
185192 if (length == 0 )
186193 {
@@ -713,7 +720,7 @@ lexer_parse_identifier (parser_context_t *context_p, /**< context */
713720
714721 if (JERRY_UNLIKELY (context_p -> token .lit_location .status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE ))
715722 {
716- lexer_convert_ident_to_cesu8 (buffer_p , ident_start_p , (prop_length_t ) length );
723+ lexer_convert_ident_to_cesu8 (context_p , buffer_p , ident_start_p , (prop_length_t ) length );
717724 ident_start_p = buffer_p ;
718725 }
719726
@@ -2070,7 +2077,8 @@ lexer_scan_private_identifier (parser_context_t *context_p) /**< context */
20702077 * Convert an ident with escapes to a utf8 string.
20712078 */
20722079void
2073- lexer_convert_ident_to_cesu8 (uint8_t * destination_p , /**< destination string */
2080+ lexer_convert_ident_to_cesu8 (parser_context_t * context_p , /**< context */
2081+ uint8_t * destination_p , /**< destination string */
20742082 const uint8_t * source_p , /**< source string */
20752083 prop_length_t length ) /**< length of destination string */
20762084{
@@ -2083,7 +2091,8 @@ lexer_convert_ident_to_cesu8 (uint8_t *destination_p, /**< destination string */
20832091 if (* source_p == LIT_CHAR_BACKSLASH )
20842092 {
20852093 source_p += 2 ;
2086- destination_p += lit_code_point_to_cesu8_bytes (destination_p , lexer_unchecked_hex_to_character (& source_p ));
2094+ destination_p +=
2095+ lit_code_point_to_cesu8_bytes (destination_p , lexer_unchecked_hex_to_character (context_p , & source_p ));
20872096 continue ;
20882097 }
20892098
@@ -2130,7 +2139,7 @@ lexer_convert_literal_to_chars (parser_context_t *context_p, /**< context */
21302139
21312140 if (literal_p -> type == LEXER_IDENT_LITERAL )
21322141 {
2133- lexer_convert_ident_to_cesu8 (destination_start_p , literal_p -> char_p , literal_p -> length );
2142+ lexer_convert_ident_to_cesu8 (context_p , destination_start_p , literal_p -> char_p , literal_p -> length );
21342143 return destination_start_p ;
21352144 }
21362145
@@ -2229,7 +2238,8 @@ lexer_convert_literal_to_chars (parser_context_t *context_p, /**< context */
22292238 if (* source_p == LIT_CHAR_LOWERCASE_X || * source_p == LIT_CHAR_LOWERCASE_U )
22302239 {
22312240 source_p ++ ;
2232- destination_p += lit_code_point_to_cesu8_bytes (destination_p , lexer_unchecked_hex_to_character (& source_p ));
2241+ destination_p +=
2242+ lit_code_point_to_cesu8_bytes (destination_p , lexer_unchecked_hex_to_character (context_p , & source_p ));
22332243 continue ;
22342244 }
22352245
@@ -3286,7 +3296,8 @@ lexer_check_property_modifier (parser_context_t *context_p) /**< context */
32863296 * @return true if the two identifiers are the same
32873297 */
32883298static bool
3289- lexer_compare_identifier_to_chars (const uint8_t * left_p , /**< left identifier */
3299+ lexer_compare_identifier_to_chars (parser_context_t * context_p , /**< context */
3300+ const uint8_t * left_p , /**< left identifier */
32903301 const uint8_t * right_p , /**< right identifier string */
32913302 size_t size ) /**< byte size of the two identifiers */
32923303{
@@ -3307,7 +3318,7 @@ lexer_compare_identifier_to_chars (const uint8_t *left_p, /**< left identifier *
33073318 if (* left_p == LIT_CHAR_BACKSLASH )
33083319 {
33093320 left_p += 2 ;
3310- lit_code_point_t code_point = lexer_unchecked_hex_to_character (& left_p );
3321+ lit_code_point_t code_point = lexer_unchecked_hex_to_character (context_p , & left_p );
33113322
33123323 escape_size = lit_code_point_to_cesu8_bytes (utf8_buf , code_point );
33133324 }
@@ -3346,7 +3357,8 @@ lexer_compare_identifier_to_chars (const uint8_t *left_p, /**< left identifier *
33463357 * @return true if the identifier equals to string
33473358 */
33483359bool
3349- lexer_compare_identifier_to_string (const lexer_lit_location_t * left_p , /**< left literal */
3360+ lexer_compare_identifier_to_string (parser_context_t * context_p , /**< context */
3361+ const lexer_lit_location_t * left_p , /**< left literal */
33503362 const uint8_t * right_p , /**< right identifier string */
33513363 size_t size ) /**< byte size of the right identifier */
33523364{
@@ -3360,7 +3372,7 @@ lexer_compare_identifier_to_string (const lexer_lit_location_t *left_p, /**< lef
33603372 return memcmp (left_p -> char_p , right_p , size ) == 0 ;
33613373 }
33623374
3363- return lexer_compare_identifier_to_chars (left_p -> char_p , right_p , size );
3375+ return lexer_compare_identifier_to_chars (context_p , left_p -> char_p , right_p , size );
33643376} /* lexer_compare_identifier_to_string */
33653377
33663378/**
@@ -3385,25 +3397,25 @@ lexer_compare_identifiers (parser_context_t *context_p, /**< context */
33853397
33863398 if (!(left_p -> status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE ))
33873399 {
3388- return lexer_compare_identifier_to_chars (right_p -> char_p , left_p -> char_p , length );
3400+ return lexer_compare_identifier_to_chars (context_p , right_p -> char_p , left_p -> char_p , length );
33893401 }
33903402
33913403 if (!(right_p -> status_flags & LEXER_LIT_LOCATION_HAS_ESCAPE ))
33923404 {
3393- return lexer_compare_identifier_to_chars (left_p -> char_p , right_p -> char_p , length );
3405+ return lexer_compare_identifier_to_chars (context_p , left_p -> char_p , right_p -> char_p , length );
33943406 }
33953407
33963408 if (length <= 64 )
33973409 {
33983410 uint8_t buf_p [64 ];
3399- lexer_convert_ident_to_cesu8 (buf_p , left_p -> char_p , length );
3400- return lexer_compare_identifier_to_chars (right_p -> char_p , buf_p , length );
3411+ lexer_convert_ident_to_cesu8 (context_p , buf_p , left_p -> char_p , length );
3412+ return lexer_compare_identifier_to_chars (context_p , right_p -> char_p , buf_p , length );
34013413 }
34023414
34033415 uint8_t * dynamic_buf_p = parser_malloc (context_p , length );
34043416
3405- lexer_convert_ident_to_cesu8 (dynamic_buf_p , left_p -> char_p , length );
3406- bool result = lexer_compare_identifier_to_chars (right_p -> char_p , dynamic_buf_p , length );
3417+ lexer_convert_ident_to_cesu8 (context_p , dynamic_buf_p , left_p -> char_p , length );
3418+ bool result = lexer_compare_identifier_to_chars (context_p , right_p -> char_p , dynamic_buf_p , length );
34073419 parser_free (dynamic_buf_p , length );
34083420
34093421 return result ;
0 commit comments