1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[spidermonkey] Check for NULL in init_string

This commit is contained in:
Witold Filipczyk 2022-01-04 17:14:49 +01:00
parent 87f18b53a0
commit 0477e45e05
6 changed files with 134 additions and 53 deletions

View File

@ -590,8 +590,13 @@ ecmascript_set_timeout(struct ecmascript_interpreter *interpreter, char *code, i
{ {
assert(interpreter && interpreter->vs->doc_view->document); assert(interpreter && interpreter->vs->doc_view->document);
if (!code) return nullptr; if (!code) return nullptr;
if (interpreter->code.source) {
done_string(&interpreter->code); done_string(&interpreter->code);
init_string(&interpreter->code); }
if (!init_string(&interpreter->code)) {
mem_free(code);
return nullptr;
}
add_to_string(&interpreter->code, code); add_to_string(&interpreter->code, code);
mem_free(code); mem_free(code);
if (found_in_map_timer(interpreter->vs->doc_view->document->timeout)) { if (found_in_map_timer(interpreter->vs->doc_view->document->timeout)) {
@ -607,8 +612,13 @@ timer_id_T
ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, JS::HandleValue f, int timeout) ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, JS::HandleValue f, int timeout)
{ {
assert(interpreter && interpreter->vs->doc_view->document); assert(interpreter && interpreter->vs->doc_view->document);
if (interpreter->code.source) {
done_string(&interpreter->code); done_string(&interpreter->code);
init_string(&interpreter->code); }
if (!init_string(&interpreter->code)) {
return TIMER_ID_UNDEF;
}
if (found_in_map_timer(interpreter->vs->doc_view->document->timeout)) { if (found_in_map_timer(interpreter->vs->doc_view->document->timeout)) {
kill_timer(&interpreter->vs->doc_view->document->timeout); kill_timer(&interpreter->vs->doc_view->document->timeout);
} }
@ -625,8 +635,12 @@ timer_id_T
ecmascript_set_timeout2q(struct ecmascript_interpreter *interpreter, JSValueConst fun, int timeout) ecmascript_set_timeout2q(struct ecmascript_interpreter *interpreter, JSValueConst fun, int timeout)
{ {
assert(interpreter && interpreter->vs->doc_view->document); assert(interpreter && interpreter->vs->doc_view->document);
if (interpreter->code.source) {
done_string(&interpreter->code); done_string(&interpreter->code);
init_string(&interpreter->code); }
if (!init_string(&interpreter->code)) {
return TIMER_ID_UNDEF;
}
if (found_in_map_timer(interpreter->vs->doc_view->document->timeout)) { if (found_in_map_timer(interpreter->vs->doc_view->document->timeout)) {
kill_timer(&interpreter->vs->doc_view->document->timeout); kill_timer(&interpreter->vs->doc_view->document->timeout);
} }
@ -694,7 +708,9 @@ document_parse(struct document *document)
} }
struct string str; struct string str;
init_string(&str); if (!init_string(&str)) {
return NULL;
}
add_bytes_to_string(&str, f->data, f->length); add_bytes_to_string(&str, f->data, f->length);

View File

@ -1379,7 +1379,9 @@ document_write_do(JSContext *ctx, unsigned int argc, JS::Value *rval, int newlin
struct string code; struct string code;
init_string(&code); if (!init_string(&code)) {
return false;
}
if (argc >= 1) if (argc >= 1)
{ {
@ -1477,8 +1479,13 @@ document_replace(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct string needle; struct string needle;
struct string heystack; struct string heystack;
init_string(&needle); if (!init_string(&needle)) {
init_string(&heystack); return false;
}
if (!init_string(&heystack)) {
done_string(&needle);
return false;
}
jshandle_value_to_char_string(&needle, ctx, args[0]); jshandle_value_to_char_string(&needle, ctx, args[0]);
jshandle_value_to_char_string(&heystack, ctx, args[1]); jshandle_value_to_char_string(&heystack, ctx, args[1]);
@ -1496,11 +1503,11 @@ document_replace(JSContext *ctx, unsigned int argc, JS::Value *vp)
fd_len=f->length; fd_len=f->length;
struct string f_data; struct string f_data;
init_string(&f_data); if (init_string(&f_data)) {
add_to_string(&f_data,f->data); add_to_string(&f_data,f->data);
struct string nu_str; struct string nu_str;
init_string(&nu_str); if (init_string(&nu_str)) {
string_replace(&nu_str,&f_data,&needle,&heystack); string_replace(&nu_str,&f_data,&needle,&heystack);
nu_len=nu_str.length; nu_len=nu_str.length;
delete_entry_content(cached); delete_entry_content(cached);
@ -1512,7 +1519,11 @@ document_replace(JSContext *ctx, unsigned int argc, JS::Value *vp)
int ret = add_fragment(cached,0,nu_str.source,fd_len); int ret = add_fragment(cached,0,nu_str.source,fd_len);
normalize_cache_entry(cached,nu_len); normalize_cache_entry(cached,nu_len);
document->ecmascript_counter++; document->ecmascript_counter++;
done_string(&nu_str);
}
//DBG("doc replace %s %s\n", needle.source, heystack.source); //DBG("doc replace %s %s\n", needle.source, heystack.source);
done_string(&f_data);
}
} }
done_string(&needle); done_string(&needle);
@ -1554,7 +1565,9 @@ document_createComment(JSContext *ctx, unsigned int argc, JS::Value *vp)
} }
struct string idstr; struct string idstr;
init_string(&idstr); if (!init_string(&idstr)) {
return false;
}
jshandle_value_to_char_string(&idstr, ctx, args[0]); jshandle_value_to_char_string(&idstr, ctx, args[0]);
xmlpp::ustring text = idstr.source; xmlpp::ustring text = idstr.source;
done_string(&idstr); done_string(&idstr);
@ -1648,7 +1661,9 @@ document_createElement(JSContext *ctx, unsigned int argc, JS::Value *vp)
} }
struct string idstr; struct string idstr;
init_string(&idstr); if (!init_string(&idstr)) {
return false;
}
jshandle_value_to_char_string(&idstr, ctx, args[0]); jshandle_value_to_char_string(&idstr, ctx, args[0]);
xmlpp::ustring text = idstr.source; xmlpp::ustring text = idstr.source;
done_string(&idstr); done_string(&idstr);
@ -1697,7 +1712,9 @@ document_createTextNode(JSContext *ctx, unsigned int argc, JS::Value *vp)
} }
struct string idstr; struct string idstr;
init_string(&idstr); if (!init_string(&idstr)) {
return false;
}
jshandle_value_to_char_string(&idstr, ctx, args[0]); jshandle_value_to_char_string(&idstr, ctx, args[0]);
xmlpp::ustring text = idstr.source; xmlpp::ustring text = idstr.source;
done_string(&idstr); done_string(&idstr);
@ -1747,7 +1764,9 @@ document_getElementById(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct string idstr; struct string idstr;
init_string(&idstr); if (!init_string(&idstr)) {
return false;
}
jshandle_value_to_char_string(&idstr, ctx, args[0]); jshandle_value_to_char_string(&idstr, ctx, args[0]);
xmlpp::ustring id = idstr.source; xmlpp::ustring id = idstr.source;
@ -1809,7 +1828,9 @@ document_getElementsByClassName(JSContext *ctx, unsigned int argc, JS::Value *vp
struct string idstr; struct string idstr;
init_string(&idstr); if (!init_string(&idstr)) {
return false;
}
jshandle_value_to_char_string(&idstr, ctx, args[0]); jshandle_value_to_char_string(&idstr, ctx, args[0]);
xmlpp::ustring id = idstr.source; xmlpp::ustring id = idstr.source;
@ -1866,7 +1887,9 @@ document_getElementsByName(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct string idstr; struct string idstr;
init_string(&idstr); if (!init_string(&idstr)) {
return false;
}
jshandle_value_to_char_string(&idstr, ctx, args[0]); jshandle_value_to_char_string(&idstr, ctx, args[0]);
xmlpp::ustring id = idstr.source; xmlpp::ustring id = idstr.source;
@ -1924,7 +1947,9 @@ document_getElementsByTagName(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct string idstr; struct string idstr;
init_string(&idstr); if (!init_string(&idstr)) {
return false;
}
jshandle_value_to_char_string(&idstr, ctx, args[0]); jshandle_value_to_char_string(&idstr, ctx, args[0]);
xmlpp::ustring id = idstr.source; xmlpp::ustring id = idstr.source;
std::transform(id.begin(), id.end(), id.begin(), ::tolower); std::transform(id.begin(), id.end(), id.begin(), ::tolower);
@ -1981,7 +2006,9 @@ document_querySelector(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct string cssstr; struct string cssstr;
init_string(&cssstr); if (!init_string(&cssstr)) {
return false;
}
jshandle_value_to_char_string(&cssstr, ctx, args[0]); jshandle_value_to_char_string(&cssstr, ctx, args[0]);
xmlpp::ustring css = cssstr.source; xmlpp::ustring css = cssstr.source;
@ -2048,7 +2075,9 @@ document_querySelectorAll(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct string cssstr; struct string cssstr;
init_string(&cssstr); if (!init_string(&cssstr)) {
return false;
}
jshandle_value_to_char_string(&cssstr, ctx, args[0]); jshandle_value_to_char_string(&cssstr, ctx, args[0]);
xmlpp::ustring css = cssstr.source; xmlpp::ustring css = cssstr.source;

View File

@ -1730,7 +1730,9 @@ element_get_property_innerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp)
return true; return true;
} }
struct string buf; struct string buf;
init_string(&buf); if (!init_string(&buf)) {
return false;
}
walk_tree(&buf, el); walk_tree(&buf, el);
args.rval().setString(JS_NewStringCopyZ(ctx, buf.source)); args.rval().setString(JS_NewStringCopyZ(ctx, buf.source));
@ -1785,7 +1787,9 @@ element_get_property_outerHtml(JSContext *ctx, unsigned int argc, JS::Value *vp)
return true; return true;
} }
struct string buf; struct string buf;
init_string(&buf); if (!init_string(&buf)) {
return false;
}
walk_tree(&buf, el, false); walk_tree(&buf, el, false);
args.rval().setString(JS_NewStringCopyZ(ctx, buf.source)); args.rval().setString(JS_NewStringCopyZ(ctx, buf.source));
@ -1840,7 +1844,9 @@ element_get_property_textContent(JSContext *ctx, unsigned int argc, JS::Value *v
} }
struct string buf; struct string buf;
init_string(&buf); if (!init_string(&buf)) {
return false;
}
walk_tree_content(&buf, el); walk_tree_content(&buf, el);
@ -2538,7 +2544,9 @@ element_closest(JSContext *ctx, unsigned int argc, JS::Value *vp)
} }
struct string cssstr; struct string cssstr;
init_string(&cssstr); if (!init_string(&cssstr)) {
return false;
}
jshandle_value_to_char_string(&cssstr, ctx, args[0]); jshandle_value_to_char_string(&cssstr, ctx, args[0]);
xmlpp::ustring css = cssstr.source; xmlpp::ustring css = cssstr.source;
xmlpp::ustring xpath = css2xpath(css); xmlpp::ustring xpath = css2xpath(css);
@ -2929,8 +2937,13 @@ element_isEqualNode(JSContext *ctx, unsigned int argc, JS::Value *rval)
struct string first; struct string first;
struct string second; struct string second;
init_string(&first); if (!init_string(&first)) {
init_string(&second); return false;
}
if (!init_string(&second)) {
done_string(&first);
return false;
}
walk_tree(&first, el, false, true); walk_tree(&first, el, false, true);
walk_tree(&second, el2, false, true); walk_tree(&second, el2, false, true);
@ -3014,7 +3027,9 @@ element_matches(JSContext *ctx, unsigned int argc, JS::Value *vp)
} }
struct string cssstr; struct string cssstr;
init_string(&cssstr); if (!init_string(&cssstr)) {
return false;
}
jshandle_value_to_char_string(&cssstr, ctx, args[0]); jshandle_value_to_char_string(&cssstr, ctx, args[0]);
xmlpp::ustring css = cssstr.source; xmlpp::ustring css = cssstr.source;
xmlpp::ustring xpath = css2xpath(css); xmlpp::ustring xpath = css2xpath(css);
@ -3069,7 +3084,9 @@ element_querySelector(JSContext *ctx, unsigned int argc, JS::Value *vp)
} }
struct string cssstr; struct string cssstr;
init_string(&cssstr); if (!init_string(&cssstr)) {
return false;
}
jshandle_value_to_char_string(&cssstr, ctx, args[0]); jshandle_value_to_char_string(&cssstr, ctx, args[0]);
xmlpp::ustring css = cssstr.source; xmlpp::ustring css = cssstr.source;
xmlpp::ustring xpath = css2xpath(css); xmlpp::ustring xpath = css2xpath(css);
@ -3131,7 +3148,9 @@ element_querySelectorAll(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct string cssstr; struct string cssstr;
init_string(&cssstr); if (!init_string(&cssstr)) {
return false;
}
jshandle_value_to_char_string(&cssstr, ctx, args[0]); jshandle_value_to_char_string(&cssstr, ctx, args[0]);
xmlpp::ustring css = cssstr.source; xmlpp::ustring css = cssstr.source;
xmlpp::ustring xpath = css2xpath(css); xmlpp::ustring xpath = css2xpath(css);

View File

@ -246,8 +246,13 @@ localstorage_setitem(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct string key; struct string key;
struct string val; struct string val;
init_string(&key); if (!init_string(&key)) {
init_string(&val); return false;
}
if (!init_string(&val)) {
done_string(&key);
return false;
}
JS::Realm *comp = js::GetContextRealm(ctx); JS::Realm *comp = js::GetContextRealm(ctx);

View File

@ -152,7 +152,9 @@ location_get_property_hash(JSContext *ctx, unsigned int argc, JS::Value *vp)
} }
struct string fragment; struct string fragment;
init_string(&fragment); if (!init_string(&fragment)) {
return false;
}
if (vs->uri->fragmentlen) { if (vs->uri->fragmentlen) {
add_bytes_to_string(&fragment, vs->uri->fragment, vs->uri->fragmentlen); add_bytes_to_string(&fragment, vs->uri->fragment, vs->uri->fragmentlen);
@ -420,7 +422,9 @@ location_get_property_pathname(JSContext *ctx, unsigned int argc, JS::Value *vp)
} }
struct string pathname; struct string pathname;
init_string(&pathname); if (!init_string(&pathname)) {
return false;
}
const char *query = memchr(vs->uri->data, '?', vs->uri->datalen); const char *query = memchr(vs->uri->data, '?', vs->uri->datalen);
int len = (query ? query - vs->uri->data : vs->uri->datalen); int len = (query ? query - vs->uri->data : vs->uri->datalen);
@ -469,7 +473,9 @@ location_get_property_port(JSContext *ctx, unsigned int argc, JS::Value *vp)
} }
struct string port; struct string port;
init_string(&port); if (!init_string(&port)) {
return false;
}
if (vs->uri->portlen) { if (vs->uri->portlen) {
add_bytes_to_string(&port, vs->uri->port, vs->uri->portlen); add_bytes_to_string(&port, vs->uri->port, vs->uri->portlen);
} }
@ -519,7 +525,9 @@ location_get_property_protocol(JSContext *ctx, unsigned int argc, JS::Value *vp)
} }
struct string proto; struct string proto;
init_string(&proto); if (!init_string(&proto)) {
return false;
}
/* Custom or unknown keep the URI untouched. */ /* Custom or unknown keep the URI untouched. */
if (vs->uri->protocol == PROTOCOL_UNKNOWN) { if (vs->uri->protocol == PROTOCOL_UNKNOWN) {
@ -575,7 +583,9 @@ location_get_property_search(JSContext *ctx, unsigned int argc, JS::Value *vp)
} }
struct string search; struct string search;
init_string(&search); if (!init_string(&search)) {
return false;
}
const char *query = memchr(vs->uri->data, '?', vs->uri->datalen); const char *query = memchr(vs->uri->data, '?', vs->uri->datalen);

View File

@ -43,7 +43,9 @@ jsval_to_boolean(JSContext *ctx, JS::Value *vp)
void void
jshandle_value_to_char_string(struct string *string, JSContext *ctx, JS::HandleValue obj) jshandle_value_to_char_string(struct string *string, JSContext *ctx, JS::HandleValue obj)
{ {
init_string(string); if (!init_string(string)) {
return;
}
if (obj.isString()) if (obj.isString())
{ {