Skip to content

Commit c68f6e7

Browse files
authored
Add stack-overflow check to 'lexer_construct_function_object' (#4965)
This patch fixes #4887. JerryScript-DCO-1.0-Signed-off-by: Martin Negyokru [email protected]
1 parent 57547d1 commit c68f6e7

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

jerry-core/parser/js/js-lexer.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2799,6 +2799,12 @@ uint16_t
27992799
lexer_construct_function_object (parser_context_t *context_p, /**< context */
28002800
uint32_t extra_status_flags) /**< extra status flags */
28012801
{
2802+
#if (JERRY_STACK_LIMIT != 0)
2803+
if (JERRY_UNLIKELY (ecma_get_current_stack_usage () > CONFIG_MEM_STACK_LIMIT))
2804+
{
2805+
parser_raise_error (context_p, PARSER_ERR_STACK_OVERFLOW);
2806+
}
2807+
#endif /* JERRY_STACK_LIMIT != 0 */
28022808
ecma_compiled_code_t *compiled_code_p;
28032809
lexer_literal_t *literal_p;
28042810
uint16_t result_index;

jerry-core/parser/js/js-parser.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,6 +2506,13 @@ parser_parse_source (void *source_p, /**< source code */
25062506
jcontext_raise_exception (ECMA_VALUE_NULL);
25072507
return NULL;
25082508
}
2509+
#if (JERRY_STACK_LIMIT != 0)
2510+
if (context.error == PARSER_ERR_STACK_OVERFLOW)
2511+
{
2512+
ecma_raise_standard_error (JERRY_ERROR_RANGE, ECMA_ERR_MAXIMUM_CALL_STACK_SIZE_EXCEEDED);
2513+
return NULL;
2514+
}
2515+
#endif /* JERRY_STACK_LIMIT != 0 */
25092516

25102517
#if JERRY_ERROR_MESSAGES
25112518
ecma_string_t *err_str_p;

jerry-core/parser/js/parser-errors.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ typedef enum
3232
/** @endcond */
3333
PARSER_ERR_OUT_OF_MEMORY,
3434
PARSER_ERR_INVALID_REGEXP,
35-
PARSER_ERR_NO_ERROR
35+
#if (JERRY_STACK_LIMIT != 0)
36+
PARSER_ERR_STACK_OVERFLOW,
37+
#endif /* JERRY_STACK_LIMIT != 0 */
38+
PARSER_ERR_NO_ERROR,
3639
} parser_error_msg_t;
3740

3841
const lit_utf8_byte_t* parser_get_error_utf8 (uint32_t id);

0 commit comments

Comments
 (0)