From e452420d5f8212125c0c0e574be50c5f954e0fa2 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 28 Jun 2009 11:17:06 +0300 Subject: [PATCH] Debian bug 534835: Don't assert ecmascript_reset_state succeeds After the recent ecmascript_get_interpreter change, I got an assertion failure in render_document, which calls ecmascript_reset_state and then asserts that it has set vs->ecmascript != NULL. ecmascript_reset_state cannot guarantee that because there might not even be enough free memory for mem_calloc(1, sizeof(struct ecmascript_interpreter). So, replace the assertion in render_document with error handling, and likewise in call_onsubmit_and_submit. --- src/document/renderer.c | 26 ++++++++++++++++---------- src/viewer/text/link.c | 10 +++++++++- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/document/renderer.c b/src/document/renderer.c index e860a9249..55c175c4a 100644 --- a/src/document/renderer.c +++ b/src/document/renderer.c @@ -392,17 +392,23 @@ render_document(struct view_state *vs, struct document_view *doc_view, && vs->ecmascript->onload_snippets_cache_id && document->cache_id != vs->ecmascript->onload_snippets_cache_id)) ecmascript_reset_state(vs); - assert(vs->ecmascript); - vs->ecmascript->onload_snippets_cache_id = document->cache_id; + /* If ecmascript_reset_state cannot construct a new + * ECMAScript interpreter, it sets vs->ecmascript = + * NULL and vs->ecmascript_fragile = 1. */ + if (vs->ecmascript) { + vs->ecmascript->onload_snippets_cache_id = document->cache_id; - /* Passing of the onload_snippets pointers gives *_snippets() - * some feeling of universality, shall we ever get any other - * snippets (?). */ - add_snippets(vs->ecmascript, - &document->onload_snippets, - &vs->ecmascript->onload_snippets); - process_snippets(vs->ecmascript, &vs->ecmascript->onload_snippets, - &vs->ecmascript->current_onload_snippet); + /* Passing of the onload_snippets pointers + * gives *_snippets() some feeling of + * universality, shall we ever get any other + * snippets (?). */ + add_snippets(vs->ecmascript, + &document->onload_snippets, + &vs->ecmascript->onload_snippets); + process_snippets(vs->ecmascript, + &vs->ecmascript->onload_snippets, + &vs->ecmascript->current_onload_snippet); + } } #endif diff --git a/src/viewer/text/link.c b/src/viewer/text/link.c index 543a5a868..7250a4367 100644 --- a/src/viewer/text/link.c +++ b/src/viewer/text/link.c @@ -923,7 +923,15 @@ call_onsubmit_and_submit(struct session *ses, struct document_view *doc_view, if (vs->ecmascript_fragile) ecmascript_reset_state(vs); interpreter = vs->ecmascript; - assert(interpreter); + /* If there is an onsubmit script and we want + * to run it, but the ECMAScript interpreter + * cannot be initialized, then don't submit. */ + if (!interpreter) { + done_string(&code); + /* See the comment below for the + * return value. */ + return 1; + } add_to_string(&code, fc->form->onsubmit); res = ecmascript_eval_boolback(interpreter, &code);