-
Notifications
You must be signed in to change notification settings - Fork 682
Fix free of NULL value in function ecma_typedarray_helper_dispatch_construct #4473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix free of NULL value in function ecma_typedarray_helper_dispatch_construct #4473
Conversation
b1208f8
to
285461b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have a JS test case of this?
285461b
to
5ea1bba
Compare
|
||
if (JERRY_CONTEXT (current_new_target)) | ||
if (current_new_target) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current_new_target != NULL
@@ -40,11 +41,20 @@ ecma_typedarray_helper_dispatch_construct (const ecma_value_t *arguments_list_p, | |||
{ | |||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); | |||
ecma_builtin_id_t proto_id = ecma_typedarray_helper_get_prototype_id (typedarray_id); | |||
ecma_object_t *prototype_obj_p = ecma_builtin_get (proto_id); | |||
ecma_object_t *current_new_target = JERRY_CONTEXT (current_new_target); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current_new_target_p
@@ -53,7 +63,7 @@ ecma_typedarray_helper_dispatch_construct (const ecma_value_t *arguments_list_p, | |||
ecma_typedarray_helper_get_shift_size (typedarray_id), | |||
typedarray_id); | |||
|
|||
if (JERRY_CONTEXT (current_new_target)) | |||
if (current_new_target) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current_new_target != NULL
Not sure about that, this tends to be un-implement feature, just not crash it. |
d0f7aea
to
6593ccc
Compare
You are right, test case are needed:) I've add one, |
jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-helpers.c
Show resolved
Hide resolved
prototype_obj_p = ecma_builtin_get (proto_id); | ||
} | ||
|
||
if (prototype_obj_p == NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if is not needed, since ecma_builtin_get (proto_id);
never returns NULL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, then I nested into the if statement
8401c63
to
9a5254e
Compare
{ | ||
prototype_obj_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target), proto_id); | ||
prototype_obj_p = ecma_op_get_prototype_from_constructor (current_new_target_p, proto_id); | ||
if (jcontext_has_pending_exception ()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if is unneccessary. If ecma_op_get_prototype_from_constructor return NULL it means there is already a raised exception on the context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what should I do, like this?
if (prototype_obj_p == NULL)
{
return ECMA_VALUE_ERROR;
}
9a5254e
to
8e216a2
Compare
@@ -20,6 +20,7 @@ | |||
#include "ecma-builtins.h" | |||
#include "ecma-gc.h" | |||
#include "ecma-objects.h" | |||
#include "ecma-exceptions.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not include
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's unnecessary. But please for the lord use whole sentences and punctuation marks rather than halfwords.
6c9f073
to
f292b4c
Compare
…nstruct 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 luoyonggang@gmail.com
f292b4c
to
0c52980
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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 the esnext tests
NOTE:This depeds on #4478 (review)
JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo luoyonggang@gmail.com