Skip to content

Commit cefd391

Browse files
authored
Fix rare crash caused by get method of proxy object (#5129)
This fixes #5101 In rare cases the proxy object could get used after being incorrectly removed by the gc Add stack checks to the start of all function calls JerryScript-DCO-1.0-Signed-off-by: Máté Tokodi [email protected]
1 parent bac7ee3 commit cefd391

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

.github/workflows/gh-actions.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ jobs:
171171
- run: >-
172172
$RUNNER -q --jerry-tests
173173
--buildoptions=--stack-limit=0,--compile-flag=-fsanitize=address,--compile-flag=-m32,--compile-flag=-fno-omit-frame-pointer,--compile-flag=-fno-common,--compile-flag=-O2,--debug,--system-allocator=on,--linker-flag=-fuse-ld=gold
174-
--skip-list=parser-oom.js,parser-oom2.js,stack-limit.js,regression-test-issue-4901.js,regression-test-issue-4848.js,regression-test-issue-4890.js,regression-test-issue-2190.js,regression-test-issue-2258-2963.js,regression-test-issue-2448.js,regression-test-issue-2905.js,regression-test-issue-3785.js,proxy-evil-recursion.js
174+
--skip-list=parser-oom.js,parser-oom2.js,stack-limit.js,regression-test-issue-4901.js,regression-test-issue-4848.js,regression-test-issue-4890.js,regression-test-issue-2190.js,regression-test-issue-2258-2963.js,regression-test-issue-2448.js,regression-test-issue-2905.js,regression-test-issue-3785.js,proxy-evil-recursion.js,regression-test-issue-5101.js
175175
176176
ASAN_Tests_Debug:
177177
runs-on: ubuntu-latest
@@ -187,7 +187,7 @@ jobs:
187187
- run: >-
188188
$RUNNER -q --jerry-tests --build-debug
189189
--buildoptions=--stack-limit=0,--compile-flag=-fsanitize=address,--compile-flag=-m32,--compile-flag=-fno-omit-frame-pointer,--compile-flag=-fno-common,--compile-flag=-O2,--debug,--system-allocator=on,--linker-flag=-fuse-ld=gold
190-
--skip-list=parser-oom.js,parser-oom2.js,stack-limit.js,regression-test-issue-4901.js,regression-test-issue-4848.js,regression-test-issue-4890.js,regression-test-issue-2190.js,regression-test-issue-2258-2963.js,regression-test-issue-2448.js,regression-test-issue-2905.js,regression-test-issue-3785.js,proxy-evil-recursion.js
190+
--skip-list=parser-oom.js,parser-oom2.js,stack-limit.js,regression-test-issue-4901.js,regression-test-issue-4848.js,regression-test-issue-4890.js,regression-test-issue-2190.js,regression-test-issue-2258-2963.js,regression-test-issue-2448.js,regression-test-issue-2905.js,regression-test-issue-3785.js,proxy-evil-recursion.js,regression-test-issue-5101.js
191191
192192
UBSAN_Tests:
193193
runs-on: ubuntu-latest

jerry-core/ecma/operations/ecma-function-object.c

+8
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,8 @@ ecma_op_function_call_constructor (vm_frame_ctx_shared_args_t *shared_args_p, /*
10101010
ecma_object_t *scope_p, /**< lexical environment to use */
10111011
ecma_value_t this_binding) /**< value of 'ThisBinding' */
10121012
{
1013+
ECMA_CHECK_STACK_USAGE ();
1014+
10131015
shared_args_p->header.status_flags |= VM_FRAME_CTX_SHARED_NON_ARROW_FUNC;
10141016

10151017
ecma_value_t ret_value;
@@ -1080,6 +1082,8 @@ ecma_op_function_call_simple (ecma_object_t *func_obj_p, /**< Function object */
10801082
{
10811083
JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION);
10821084

1085+
ECMA_CHECK_STACK_USAGE ();
1086+
10831087
vm_frame_ctx_shared_args_t shared_args;
10841088
shared_args.header.status_flags = VM_FRAME_CTX_SHARED_HAS_ARG_LIST;
10851089
shared_args.header.function_object_p = func_obj_p;
@@ -1205,6 +1209,8 @@ ecma_op_function_call_native_built_in (ecma_object_t *func_obj_p, /**< Function
12051209
{
12061210
JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BUILT_IN_FUNCTION);
12071211

1212+
ECMA_CHECK_STACK_USAGE ();
1213+
12081214
#if JERRY_BUILTIN_REALMS
12091215
ecma_global_object_t *saved_global_object_p = JERRY_CONTEXT (global_object_p);
12101216

@@ -1235,6 +1241,8 @@ ecma_op_function_call_native (ecma_object_t *func_obj_p, /**< Function object */
12351241
{
12361242
JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_NATIVE_FUNCTION);
12371243

1244+
ECMA_CHECK_STACK_USAGE ();
1245+
12381246
ecma_native_function_t *native_function_p = (ecma_native_function_t *) func_obj_p;
12391247

12401248
#if JERRY_BUILTIN_REALMS

jerry-core/ecma/operations/ecma-proxy-object.c

+2
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,9 @@ ecma_proxy_object_get (ecma_object_t *obj_p, /**< proxy object */
11701170
ecma_value_t args[] = { proxy_obj_p->target, prop_value, receiver };
11711171

11721172
/* 9. */
1173+
ecma_ref_object (obj_p);
11731174
ecma_value_t trap_result = ecma_op_function_call (func_obj_p, handler, args, 3);
1175+
ecma_deref_object (obj_p);
11741176

11751177
ecma_deref_object (func_obj_p);
11761178

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
var iter = 100;
16+
async function f0() {
17+
iter--;
18+
function f6() {
19+
return f0;
20+
}
21+
var proxy_handler = {
22+
"get": f0,
23+
};
24+
25+
f0.__proto__ = new Proxy(f6, proxy_handler);
26+
27+
if ((iter >= 0)) {
28+
var v12 = f0();
29+
}
30+
return f0;
31+
}
32+
f0();

0 commit comments

Comments
 (0)