prevent 0 length allocation in js_worker_postMessage

This commit is contained in:
Charlie Gordon 2024-03-03 14:42:01 +01:00
parent e17cb9fc7a
commit 1a5333bcb3

View File

@ -3527,10 +3527,12 @@ static JSValue js_worker_postMessage(JSContext *ctx, JSValueConst this_val,
memcpy(msg->data, data, data_len); memcpy(msg->data, data, data_len);
msg->data_len = data_len; msg->data_len = data_len;
if (sab_tab_len > 0) {
msg->sab_tab = malloc(sizeof(msg->sab_tab[0]) * sab_tab_len); msg->sab_tab = malloc(sizeof(msg->sab_tab[0]) * sab_tab_len);
if (!msg->sab_tab) if (!msg->sab_tab)
goto fail; goto fail;
memcpy(msg->sab_tab, sab_tab, sizeof(msg->sab_tab[0]) * sab_tab_len); memcpy(msg->sab_tab, sab_tab, sizeof(msg->sab_tab[0]) * sab_tab_len);
}
msg->sab_tab_len = sab_tab_len; msg->sab_tab_len = sab_tab_len;
js_free(ctx, data); js_free(ctx, data);