Fix prototype chain traversing (#4458)
After the introduction of the Proxy builtin object there was a possibility to traverse the prototype chain with an invalid object. The prototype was freed before it's data/properties were queried resulting in accessing invalid information. By forcing the allocator to always do a gc (`--mem-stres-test=on` build option) it was possible to trigger the issue without complicated tests. New internal method: * `ecma_op_object_get_prototype_of` which always returns the prototype of an object and the return value must be freed (if it is valid). Updated prototype chain traversing in: * `jerry_object_get_property_names` * `ecma_builtin_object_prototype_lookup_getter_setter` * `ecma_op_function_has_instance` * `ecma_op_function_get_super_constructor` * `ecma_op_object_is_prototype_of` * `ecma_op_object_enumerate` Removed method `ecma_proxy_object_prototype_to_cp` JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.usz@partner.samsung.com
This commit is contained in:
@@ -324,11 +324,10 @@ ecma_builtin_object_prototype_lookup_getter_setter (ecma_value_t this_arg, /**<
|
||||
return ECMA_VALUE_ERROR;
|
||||
}
|
||||
|
||||
jmem_cpointer_t obj_cp;
|
||||
ECMA_SET_NON_NULL_POINTER (obj_cp, obj_p);
|
||||
|
||||
ecma_value_t ret_value = ECMA_VALUE_UNDEFINED;
|
||||
|
||||
ecma_ref_object (obj_p);
|
||||
|
||||
/* 3. */
|
||||
while (true)
|
||||
{
|
||||
@@ -339,6 +338,7 @@ ecma_builtin_object_prototype_lookup_getter_setter (ecma_value_t this_arg, /**<
|
||||
if (ECMA_IS_VALUE_ERROR (get_desc))
|
||||
{
|
||||
ret_value = get_desc;
|
||||
ecma_deref_object (obj_p);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -360,35 +360,26 @@ ecma_builtin_object_prototype_lookup_getter_setter (ecma_value_t this_arg, /**<
|
||||
}
|
||||
|
||||
ecma_free_property_descriptor (&desc);
|
||||
ecma_deref_object (obj_p);
|
||||
break;
|
||||
}
|
||||
|
||||
/* 3.c */
|
||||
#if ENABLED (JERRY_BUILTIN_PROXY)
|
||||
if (ECMA_OBJECT_IS_PROXY (obj_p))
|
||||
{
|
||||
ecma_value_t parent = ecma_proxy_object_get_prototype_of (obj_p);
|
||||
ecma_object_t *proto_p = ecma_op_object_get_prototype_of (obj_p);
|
||||
ecma_deref_object (obj_p);
|
||||
|
||||
if (ECMA_IS_VALUE_ERROR (parent))
|
||||
{
|
||||
ret_value = parent;
|
||||
break;
|
||||
}
|
||||
|
||||
obj_cp = ecma_proxy_object_prototype_to_cp (parent);
|
||||
}
|
||||
else
|
||||
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
|
||||
{
|
||||
obj_cp = ecma_op_ordinary_object_get_prototype_of (obj_p);
|
||||
}
|
||||
|
||||
if (obj_cp == JMEM_CP_NULL)
|
||||
if (proto_p == NULL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (JERRY_UNLIKELY (proto_p == ECMA_OBJECT_POINTER_ERROR))
|
||||
{
|
||||
ret_value = ECMA_VALUE_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
obj_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, obj_cp);
|
||||
/* Advance up on prototype chain. */
|
||||
obj_p = proto_p;
|
||||
}
|
||||
|
||||
ecma_free_value (to_obj);
|
||||
|
||||
Reference in New Issue
Block a user