|
40 | 40 | #define BUILTIN_UNDERSCORED_ID json
|
41 | 41 | #include "ecma-builtin-internal-routines-template.inc.h"
|
42 | 42 |
|
| 43 | +/** |
| 44 | + * The number of expected hexidecimal characters in a hex escape sequence |
| 45 | + */ |
| 46 | +#define ECMA_JSON_HEX_ESCAPE_SEQUENCE_LENGTH (4) |
| 47 | + |
43 | 48 | /** \addtogroup ecma ECMA
|
44 | 49 | * @{
|
45 | 50 | *
|
@@ -182,13 +187,17 @@ ecma_builtin_json_parse_string (ecma_json_token_t *token_p) /**< token argument
|
182 | 187 | }
|
183 | 188 | case LIT_CHAR_LOWERCASE_U:
|
184 | 189 | {
|
| 190 | + if ((end_p - current_p <= ECMA_JSON_HEX_ESCAPE_SEQUENCE_LENGTH)) { |
| 191 | + return; |
| 192 | + } |
| 193 | + |
185 | 194 | ecma_char_t code_unit;
|
186 |
| - if ((end_p - current_p >= 2) && !(lit_read_code_unit_from_hex (current_p + 1, 4, &code_unit))) |
| 195 | + if (!(lit_read_code_unit_from_hex (current_p + 1, ECMA_JSON_HEX_ESCAPE_SEQUENCE_LENGTH, &code_unit))) |
187 | 196 | {
|
188 | 197 | return;
|
189 | 198 | }
|
190 | 199 |
|
191 |
| - current_p += 5; |
| 200 | + current_p += ECMA_JSON_HEX_ESCAPE_SEQUENCE_LENGTH + 1; |
192 | 201 |
|
193 | 202 | lit_utf8_byte_t char_buffer[LIT_UTF8_MAX_BYTES_IN_CODE_UNIT];
|
194 | 203 | buffer_size += lit_code_unit_to_utf8 (code_unit, char_buffer);
|
@@ -258,9 +267,9 @@ ecma_builtin_json_parse_string (ecma_json_token_t *token_p) /**< token argument
|
258 | 267 | {
|
259 | 268 | ecma_char_t code_unit;
|
260 | 269 |
|
261 |
| - lit_read_code_unit_from_hex (current_p + 1, 4, &code_unit); |
| 270 | + lit_read_code_unit_from_hex (current_p + 1, ECMA_JSON_HEX_ESCAPE_SEQUENCE_LENGTH, &code_unit); |
262 | 271 |
|
263 |
| - current_p += 5; |
| 272 | + current_p += ECMA_JSON_HEX_ESCAPE_SEQUENCE_LENGTH + 1; |
264 | 273 | write_p += lit_code_unit_to_utf8 (code_unit, write_p);
|
265 | 274 | continue;
|
266 | 275 | }
|
|
0 commit comments