@@ -1159,6 +1159,9 @@ wasi_sock_accept(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_fdflags_t flags,
1159
1159
if (!wasi_ctx )
1160
1160
return __WASI_EACCES ;
1161
1161
1162
+ if (!validate_native_addr (fd_new , sizeof (* fd_new )))
1163
+ return __WASI_EINVAL ;
1164
+
1162
1165
curfds = wasi_ctx_get_curfds (wasi_ctx );
1163
1166
1164
1167
return wasi_ssp_sock_accept (exec_env , curfds , fd , flags , fd_new );
@@ -1217,6 +1220,19 @@ wasi_sock_addr_resolve(wasm_exec_env_t exec_env, const char *host,
1217
1220
if (!wasi_ctx )
1218
1221
return __WASI_EACCES ;
1219
1222
1223
+ if (!validate_native_addr (hints , sizeof (* hints )))
1224
+ return __WASI_EINVAL ;
1225
+
1226
+ uint64_t addr_info_byte_size = sizeof (* addr_info ) * addr_info_size ;
1227
+ if (addr_info_byte_size / addr_info_size != sizeof (* addr_info ))
1228
+ return __WASI_EINVAL ;
1229
+
1230
+ if (!validate_native_addr (addr_info , addr_info_byte_size ))
1231
+ return __WASI_EINVAL ;
1232
+
1233
+ if (!validate_native_addr (max_info_size , sizeof (* max_info_size )))
1234
+ return __WASI_EINVAL ;
1235
+
1220
1236
curfds = wasi_ctx_get_curfds (wasi_ctx );
1221
1237
ns_lookup_list = wasi_ctx_get_ns_lookup_list (wasi_ctx );
1222
1238
@@ -1236,6 +1252,9 @@ wasi_sock_bind(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_addr_t *addr)
1236
1252
if (!wasi_ctx )
1237
1253
return __WASI_EACCES ;
1238
1254
1255
+ if (!validate_native_addr (addr , sizeof (* addr )))
1256
+ return __WASI_EINVAL ;
1257
+
1239
1258
curfds = wasi_ctx_get_curfds (wasi_ctx );
1240
1259
addr_pool = wasi_ctx_get_addr_pool (wasi_ctx );
1241
1260
@@ -1262,6 +1281,9 @@ wasi_sock_connect(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_addr_t *addr)
1262
1281
if (!wasi_ctx )
1263
1282
return __WASI_EACCES ;
1264
1283
1284
+ if (!validate_native_addr (addr , sizeof (* addr )))
1285
+ return __WASI_EINVAL ;
1286
+
1265
1287
curfds = wasi_ctx_get_curfds (wasi_ctx );
1266
1288
addr_pool = wasi_ctx_get_addr_pool (wasi_ctx );
1267
1289
@@ -1641,6 +1663,9 @@ wasi_sock_open(wasm_exec_env_t exec_env, wasi_fd_t poolfd,
1641
1663
if (!wasi_ctx )
1642
1664
return __WASI_EACCES ;
1643
1665
1666
+ if (!validate_native_addr (sockfd , sizeof (* sockfd )))
1667
+ return __WASI_EINVAL ;
1668
+
1644
1669
curfds = wasi_ctx_get_curfds (wasi_ctx );
1645
1670
1646
1671
return wasi_ssp_sock_open (exec_env , curfds , poolfd , af , socktype , sockfd );
@@ -2080,6 +2105,10 @@ wasi_sock_recv_from(wasm_exec_env_t exec_env, wasi_fd_t sock,
2080
2105
return __WASI_EINVAL ;
2081
2106
}
2082
2107
2108
+ /* note: src_addr is NULL when called by wasi_sock_recv */
2109
+ if (src_addr != NULL && !validate_native_addr (src_addr , sizeof (* src_addr )))
2110
+ return __WASI_EINVAL ;
2111
+
2083
2112
if (!validate_native_addr (ro_data_len , (uint64 )sizeof (uint32 )))
2084
2113
return __WASI_EINVAL ;
2085
2114
@@ -2118,6 +2147,9 @@ wasi_sock_recv(wasm_exec_env_t exec_env, wasi_fd_t sock, iovec_app_t *ri_data,
2118
2147
wasm_module_inst_t module_inst = get_module_inst (exec_env );
2119
2148
wasi_errno_t error ;
2120
2149
2150
+ if (!validate_native_addr (ro_data_len , sizeof (* ro_data_len )))
2151
+ return __WASI_EINVAL ;
2152
+
2121
2153
if (!validate_native_addr (ro_flags , (uint64 )sizeof (wasi_roflags_t )))
2122
2154
return __WASI_EINVAL ;
2123
2155
@@ -2227,6 +2259,9 @@ wasi_sock_send_to(wasm_exec_env_t exec_env, wasi_fd_t sock,
2227
2259
return __WASI_EINVAL ;
2228
2260
}
2229
2261
2262
+ if (!validate_native_addr ((void * )dest_addr , sizeof (* dest_addr )))
2263
+ return __WASI_EINVAL ;
2264
+
2230
2265
if (!validate_native_addr (so_data_len , (uint64 )sizeof (uint32 )))
2231
2266
return __WASI_EINVAL ;
2232
2267
0 commit comments