@@ -375,6 +375,9 @@ wasi_fd_pread(wasm_exec_env_t exec_env, wasi_fd_t fd, iovec_app_t *iovec_app,
375
375
return (wasi_errno_t )- 1 ;
376
376
377
377
total_size = sizeof (wasi_iovec_t ) * (uint64 )iovs_len ;
378
+ if (total_size == 0 ) {
379
+ total_size = 1 ; /* avoid user-triggered 0-sized allocation */
380
+ }
378
381
if (total_size >= UINT32_MAX
379
382
|| !(iovec_begin = wasm_runtime_malloc ((uint32 )total_size )))
380
383
return (wasi_errno_t )- 1 ;
@@ -430,6 +433,9 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env, wasi_fd_t fd,
430
433
return (wasi_errno_t )- 1 ;
431
434
432
435
total_size = sizeof (wasi_ciovec_t ) * (uint64 )iovs_len ;
436
+ if (total_size == 0 ) {
437
+ total_size = 1 ; /* avoid user-triggered 0-sized allocation */
438
+ }
433
439
if (total_size >= UINT32_MAX
434
440
|| !(ciovec_begin = wasm_runtime_malloc ((uint32 )total_size )))
435
441
return (wasi_errno_t )- 1 ;
@@ -484,6 +490,9 @@ wasi_fd_read(wasm_exec_env_t exec_env, wasi_fd_t fd,
484
490
return (wasi_errno_t )- 1 ;
485
491
486
492
total_size = sizeof (wasi_iovec_t ) * (uint64 )iovs_len ;
493
+ if (total_size == 0 ) {
494
+ total_size = 1 ; /* avoid user-triggered 0-sized allocation */
495
+ }
487
496
if (total_size >= UINT32_MAX
488
497
|| !(iovec_begin = wasm_runtime_malloc ((uint32 )total_size )))
489
498
return (wasi_errno_t )- 1 ;
@@ -654,6 +663,9 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd,
654
663
return (wasi_errno_t )- 1 ;
655
664
656
665
total_size = sizeof (wasi_ciovec_t ) * (uint64 )iovs_len ;
666
+ if (total_size == 0 ) {
667
+ total_size = 1 ; /* avoid user-triggered 0-sized allocation */
668
+ }
657
669
if (total_size >= UINT32_MAX
658
670
|| !(ciovec_begin = wasm_runtime_malloc ((uint32 )total_size )))
659
671
return (wasi_errno_t )- 1 ;
0 commit comments