diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-json.c b/jerry-core/ecma/builtin-objects/ecma-builtin-json.c index 22ce41b5a6..0e0112798a 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-json.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-json.c @@ -161,6 +161,12 @@ ecma_builtin_json_parse_string (ecma_json_token_t *token_p) /**< token argument current_p++; has_escape_sequence = true; + /* If there is an escape sequence but there's no escapable character just return */ + if (current_p >= end_p) + { + return; + } + switch (*current_p) { case LIT_CHAR_DOUBLE_QUOTE: @@ -177,8 +183,7 @@ ecma_builtin_json_parse_string (ecma_json_token_t *token_p) /**< token argument case LIT_CHAR_LOWERCASE_U: { ecma_char_t code_unit; - - if (!(lit_read_code_unit_from_hex (current_p + 1, 4, &code_unit))) + if ((end_p - current_p >= 2) && !(lit_read_code_unit_from_hex (current_p + 1, 4, &code_unit))) { return; } diff --git a/tests/jerry/fail/regression-test-issue-2180.js b/tests/jerry/fail/regression-test-issue-2180.js new file mode 100644 index 0000000000..a72e27b48e --- /dev/null +++ b/tests/jerry/fail/regression-test-issue-2180.js @@ -0,0 +1,15 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +JSON.parse('"' + '\\'); diff --git a/tests/jerry/fail/regression-test-issue-2192.js b/tests/jerry/fail/regression-test-issue-2192.js new file mode 100644 index 0000000000..563ba8b42c --- /dev/null +++ b/tests/jerry/fail/regression-test-issue-2192.js @@ -0,0 +1,15 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +JSON.parse('"' + '\\u');