From ace05b182d683f63c387d1a394c3ad70a942b44f Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Mon, 17 Oct 2022 22:45:10 +0800 Subject: [PATCH] Fix possible non null-terminated string issue in socket sample (#1612) --- samples/socket-api/wasm-src/multicast_client.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/socket-api/wasm-src/multicast_client.c b/samples/socket-api/wasm-src/multicast_client.c index 0f0fa062..43201dcb 100644 --- a/samples/socket-api/wasm-src/multicast_client.c +++ b/samples/socket-api/wasm-src/multicast_client.c @@ -53,7 +53,7 @@ main(int argc, char *argv[]) struct ip_mreq ipv4_group; int sd; int datalen; - char databuf[1024]; + char databuf[1024] = { 0 }; char multicast_addr_buffer[16]; struct sockaddr_storage local_address = { 0 }; int addr_type = -1; @@ -116,7 +116,7 @@ main(int argc, char *argv[]) printf("Joined multicast group. Waiting for datagram...\n"); - datalen = sizeof(databuf); + datalen = sizeof(databuf) - 1; read_result = read(sd, databuf, datalen); if (read_result < 0) { @@ -132,4 +132,4 @@ main(int argc, char *argv[]) fail: close(sd); return EXIT_FAILURE; -} \ No newline at end of file +}