Skip to content

Commit ca54bf4

Browse files
committed
Add input validation to 'jerry_parse' and 'jerry_parse_and_save_snapshot'
Fixes #1549 JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]
1 parent 32674ff commit ca54bf4

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

jerry-core/jerry-snapshot.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,11 @@ jerry_parse_and_save_snapshot (const jerry_char_t *source_p, /**< script source
458458
size_t buffer_size) /**< the buffer's size */
459459
{
460460
#ifdef JERRY_ENABLE_SNAPSHOT_SAVE
461+
if (!lit_is_utf8_string_valid ((lit_utf8_byte_t *) source_p, (lit_utf8_size_t) source_size))
462+
{
463+
return 0;
464+
}
465+
461466
snapshot_globals_t globals;
462467
ecma_value_t parse_status;
463468
ecma_compiled_code_t *bytecode_data_p;

jerry-core/jerry.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ jerry_parse (const jerry_char_t *source_p, /**< script source */
256256
#ifdef JERRY_JS_PARSER
257257
jerry_assert_api_available ();
258258

259+
if (!lit_is_utf8_string_valid ((lit_utf8_byte_t *) source_p, (lit_utf8_size_t) source_size))
260+
{
261+
return ecma_raise_syntax_error (ECMA_ERR_MSG ("Input must be a valid UTF-8 string."));
262+
}
263+
259264
ecma_compiled_code_t *bytecode_data_p;
260265
ecma_value_t parse_status;
261266

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
va'Ôc=

0 commit comments

Comments
 (0)