Skip to content

Commit

Permalink
prevent 0 length allocation in js_worker_postMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
chqrlie committed Mar 3, 2024
1 parent e17cb9f commit 1a5333b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions quickjs-libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3527,10 +3527,12 @@ static JSValue js_worker_postMessage(JSContext *ctx, JSValueConst this_val,
memcpy(msg->data, data, data_len);
msg->data_len = data_len;

msg->sab_tab = malloc(sizeof(msg->sab_tab[0]) * sab_tab_len);
if (!msg->sab_tab)
goto fail;
memcpy(msg->sab_tab, sab_tab, sizeof(msg->sab_tab[0]) * sab_tab_len);
if (sab_tab_len > 0) {
msg->sab_tab = malloc(sizeof(msg->sab_tab[0]) * sab_tab_len);
if (!msg->sab_tab)
goto fail;
memcpy(msg->sab_tab, sab_tab, sizeof(msg->sab_tab[0]) * sab_tab_len);
}
msg->sab_tab_len = sab_tab_len;

js_free(ctx, data);
Expand Down

0 comments on commit 1a5333b

Please sign in to comment.