diff options
author | Dave Higton <dave@davehigton.me.uk> | 2015-10-10 11:14:54 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2015-10-10 11:14:54 +0100 |
commit | 9443f201feab3b5db858f9f4990480983812006f (patch) | |
tree | 77754f90005720bb00561f335bd8e78410449e92 /javascript/duktape | |
parent | 0636ee0f209af1bbc080c87058c7e1f8191e8b15 (diff) | |
download | netsurf-9443f201feab3b5db858f9f4990480983812006f.tar.gz netsurf-9443f201feab3b5db858f9f4990480983812006f.tar.bz2 |
fix null dereference in document.writeln
The fix recently applied to document.write() also needs to be applied
to document.writeln() This prevents a null pointer dereference.
Diffstat (limited to 'javascript/duktape')
-rw-r--r-- | javascript/duktape/Document.bnd | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/javascript/duktape/Document.bnd b/javascript/duktape/Document.bnd index 8b39ae414..14412cdfa 100644 --- a/javascript/duktape/Document.bnd +++ b/javascript/duktape/Document.bnd @@ -56,18 +56,27 @@ method Document::writeln() const char nl[] = "\n"; struct html_content *htmlc; duk_size_t text_len; - for (int i = 0; i < duk_get_top(ctx); ++i) + const char *text; + dom_exception err; + + for (int i = 0; i < duk_get_top(ctx); ++i) { duk_safe_to_string(ctx, i); + } duk_concat(ctx, duk_get_top(ctx)); - const char *text = duk_safe_to_lstring(ctx, 0, &text_len); + text = duk_safe_to_lstring(ctx, 0, &text_len); + LOG("Writeln %*s", (int)text_len, text); - dom_exception err; err = dom_node_get_user_data(priv->parent.node, corestring_dom___ns_key_html_content_data, &htmlc); - if (err == DOM_NO_ERR && htmlc->parser != NULL) { + if ((err == DOM_NO_ERR) && + (htmlc != NULL) && + (htmlc->parser != NULL)) { dom_hubbub_parser_insert_chunk(htmlc->parser, (uint8_t *)text, text_len); dom_hubbub_parser_insert_chunk(htmlc->parser, (uint8_t *)nl, SLEN(nl)); + } else { + LOG("error getting htmlc. parent node:%p htmlc:%p", + priv->parent.node, htmlc); } return 0; %} |