Skip to content

Commit d8ad30b

Browse files
committed
Fix free of NULL value in function ecma_typedarray_helper_dispatch_construct
Currently, ecma_op_get_prototype_from_constructor may return NULL and the function didn't raise that exception. Also optimize multiple assignment of prototype_obj_p and multiple access of JERRY_CONTEXT (current_new_target) out. This fixes jerryscript-project#4463 JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo [email protected]
1 parent 44e09f1 commit d8ad30b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-helpers.c

+14-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "ecma-builtins.h"
2121
#include "ecma-gc.h"
2222
#include "ecma-objects.h"
23+
#include "ecma-exceptions.h"
2324
#include "ecma-typedarray-object.h"
2425
#include "ecma-function-object.h"
2526
#include "jcontext.h"
@@ -40,11 +41,20 @@ ecma_typedarray_helper_dispatch_construct (const ecma_value_t *arguments_list_p,
4041
{
4142
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
4243
ecma_builtin_id_t proto_id = ecma_typedarray_helper_get_prototype_id (typedarray_id);
43-
ecma_object_t *prototype_obj_p = ecma_builtin_get (proto_id);
44+
ecma_object_t *current_new_target_p = JERRY_CONTEXT (current_new_target);
45+
ecma_object_t *prototype_obj_p;
4446

45-
if (JERRY_CONTEXT (current_new_target))
47+
if (current_new_target_p != NULL)
4648
{
47-
prototype_obj_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target), proto_id);
49+
prototype_obj_p = ecma_op_get_prototype_from_constructor (current_new_target_p, proto_id);
50+
if (prototype_obj_p == NULL)
51+
{
52+
return ecma_raise_type_error (ECMA_ERR_MSG ("TypedArray constructor should have prototype"));
53+
}
54+
}
55+
else
56+
{
57+
prototype_obj_p = ecma_builtin_get (proto_id);
4858
}
4959

5060
ecma_value_t val = ecma_op_create_typedarray (arguments_list_p,
@@ -53,7 +63,7 @@ ecma_typedarray_helper_dispatch_construct (const ecma_value_t *arguments_list_p,
5363
ecma_typedarray_helper_get_shift_size (typedarray_id),
5464
typedarray_id);
5565

56-
if (JERRY_CONTEXT (current_new_target))
66+
if (current_new_target_p != NULL)
5767
{
5868
ecma_deref_object (prototype_obj_p);
5969
}

0 commit comments

Comments
 (0)