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);