File tree Expand file tree Collapse file tree 2 files changed +39
-3
lines changed
jerry-core/ecma/builtin-objects Expand file tree Collapse file tree 2 files changed +39
-3
lines changed Original file line number Diff line number Diff line change 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 (i.e. \ud801)
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 + 1 )) {
191
+ return ;
192
+ }
193
+
185
194
ecma_char_t code_unit ;
186
195
if ((end_p - current_p >= 2 ) && !(lit_read_code_unit_from_hex (current_p + 1 , 4 , & 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
}
Original file line number Diff line number Diff line change
1
+ // Copyright JS Foundation and other contributors, http://js.foundation
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ [
16
+ // This input caused a buffer overrun,
17
+ // see https://github.com/jerryscript-project/jerryscript/issues/2200
18
+ '"\\ubad' ,
19
+ // Test similar malformations as well:
20
+ '"\\ubad"' ,
21
+ '"\\u' ,
22
+ ] . forEach ( function ( badJson ) {
23
+ try {
24
+ JSON . parse ( badJson ) ;
25
+ } catch ( e ) {
26
+ }
27
+ } ) ;
You can’t perform that action at this time.
0 commit comments