Fix invalid calculation of total size of bytes to send and recv (#1162)

The total size of bytes to send and recv should be set to 0 before calculation,
but not including the size of iovec_app_t structure.
This commit is contained in:
liang.he
2022-05-10 10:43:34 +08:00
committed by GitHub
parent 3ba2d7e7de
commit ceaf7dc660
3 changed files with 10 additions and 9 deletions

View File

@ -154,8 +154,8 @@ recvmsg(int sockfd, struct msghdr *msg, int flags)
// Prepare input parameters.
__wasi_iovec_t *ri_data = NULL;
size_t i = 0;
size_t ro_datalen;
__wasi_roflags_t ro_flags;
size_t ro_datalen = 0;
__wasi_roflags_t ro_flags = 0;
if (NULL == msg) {
HANDLE_ERROR(__WASI_ERRNO_INVAL)

View File

@ -1207,7 +1207,7 @@ wasi_sock_recv(wasm_exec_env_t exec_env, wasi_fd_t sock, iovec_app_t *ri_data,
return __WASI_EINVAL;
/* receive and scatter*/
for (i = 0; i < ri_data_len; i++, ri_data++) {
for (total_size = 0, i = 0; i < ri_data_len; i++, ri_data++) {
total_size += ri_data->buf_len;
}
if (total_size >= UINT32_MAX
@ -1286,7 +1286,7 @@ wasi_sock_send(wasm_exec_env_t exec_env, wasi_fd_t sock,
return __WASI_EINVAL;
/* gather and send */
for (i = 0; i < si_data_len; i++, si_data++) {
for (total_size = 0, i = 0; i < si_data_len; i++, si_data++) {
total_size += si_data->buf_len;
}
if (total_size >= UINT32_MAX