Browse Source

Fix segfault in call setup when valstack limit hit

v2-maintenance
Sami Vaarala 3 years ago
parent
commit
a851d8a568
  1. 14
      src-input/duk_js_call.c
  2. 35
      tests/ecmascript/test-bug-scope-segv-gh2448.js

14
src-input/duk_js_call.c

@ -2146,6 +2146,15 @@ DUK_LOCAL duk_int_t duk__handle_call_raw(duk_hthread *thr, duk_idx_t idx_func, d
/* [ ... func this arg1 ... argN ] */
/*
* Grow value stack to required size before env setup. This
* must happen before env setup to handle some corner cases
* correctly, e.g. test-bug-scope-segv-gh2448.js.
*/
duk_valstack_grow_check_throw(thr, vs_min_bytes);
act->reserve_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack);
/*
* Environment record creation and 'arguments' object creation.
* Named function expression name binding is handled by the
@ -2167,13 +2176,8 @@ DUK_LOCAL duk_int_t duk__handle_call_raw(duk_hthread *thr, duk_idx_t idx_func, d
* Setup value stack: clamp to 'nargs', fill up to 'nregs',
* ensure value stack size matches target requirements, and
* switch value stack bottom. Valstack top is kept.
*
* Value stack can only grow here.
*/
duk_valstack_grow_check_throw(thr, vs_min_bytes);
act->reserve_byteoff = (duk_size_t) ((duk_uint8_t *) thr->valstack_end - (duk_uint8_t *) thr->valstack);
if (use_tailcall) {
DUK_ASSERT(nregs >= 0);
DUK_ASSERT(nregs >= nargs);

35
tests/ecmascript/test-bug-scope-segv-gh2448.js

@ -0,0 +1,35 @@
// https://github.com/svaarala/duktape/issues/2448
/*===
RangeError
===*/
function JSEtest() {
var src = [];
var i;
src.push('(function test() {');
for (i = 0; i < 1e4; i++) {
src.push('var x' + i + ' = ' + i + ';');
}
src.push('var arguments = test(); return "dummy"; })');
src = src.join('');
//print(src);
var f = eval(src)(src);
try {
f();
} catch (e) {
print(e.name + ': ' + e.message);
}
print('still here');
}
try {
JSEtest();
} catch (e) {
//print(e.stack || e);
print(e.name);
}
Loading…
Cancel
Save