mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05:00
Bug 957: Assert that the ECMAScript interpreter is not running.
Add ecmascript_interpreter.backend_nesting, increment it when
beginning to evaluate an expression, and decrement it when evaluation
finishes. Then assert that it is zero in ecmascript_put_interpreter.
This detects bug 957 and similar ones before they corrupt memory.
[ Backported from commit 58e3ebf2e7
in
ELinks 0.12.GIT. --KON ]
This commit is contained in:
parent
0cf60aefb5
commit
13b1d26946
src/ecmascript
@ -99,6 +99,7 @@ void
|
||||
ecmascript_put_interpreter(struct ecmascript_interpreter *interpreter)
|
||||
{
|
||||
assert(interpreter);
|
||||
assert(interpreter->backend_nesting == 0);
|
||||
spidermonkey_put_interpreter(interpreter);
|
||||
free_string_list(&interpreter->onload_snippets);
|
||||
mem_free(interpreter);
|
||||
@ -132,7 +133,9 @@ ecmascript_eval(struct ecmascript_interpreter *interpreter,
|
||||
if (!get_ecmascript_enable())
|
||||
return;
|
||||
assert(interpreter);
|
||||
interpreter->backend_nesting++;
|
||||
spidermonkey_eval(interpreter, code);
|
||||
interpreter->backend_nesting--;
|
||||
}
|
||||
|
||||
|
||||
@ -140,10 +143,15 @@ unsigned char *
|
||||
ecmascript_eval_stringback(struct ecmascript_interpreter *interpreter,
|
||||
struct string *code)
|
||||
{
|
||||
unsigned char *result;
|
||||
|
||||
if (!get_ecmascript_enable())
|
||||
return NULL;
|
||||
assert(interpreter);
|
||||
return spidermonkey_eval_stringback(interpreter, code);
|
||||
interpreter->backend_nesting++;
|
||||
result = spidermonkey_eval_stringback(interpreter, code);
|
||||
interpreter->backend_nesting--;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -151,10 +159,15 @@ int
|
||||
ecmascript_eval_boolback(struct ecmascript_interpreter *interpreter,
|
||||
struct string *code)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (!get_ecmascript_enable())
|
||||
return -1;
|
||||
assert(interpreter);
|
||||
return spidermonkey_eval_boolback(interpreter, code);
|
||||
interpreter->backend_nesting++;
|
||||
result = spidermonkey_eval_boolback(interpreter, code);
|
||||
interpreter->backend_nesting--;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,6 +15,12 @@ struct view_state;
|
||||
struct ecmascript_interpreter {
|
||||
struct view_state *vs;
|
||||
void *backend_data;
|
||||
|
||||
/* Nesting level of calls to backend functions. When this is
|
||||
* nonzero, there are references to backend_data in the C
|
||||
* stack, so it is not safe to free the data yet. */
|
||||
int backend_nesting;
|
||||
|
||||
time_t exec_start;
|
||||
|
||||
/* This is a cross-rerenderings accumulator of
|
||||
|
Loading…
Reference in New Issue
Block a user