Skip to content

Commit ace05b1

Browse files
authored
Fix possible non null-terminated string issue in socket sample (#1612)
1 parent 7cc7b56 commit ace05b1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

samples/socket-api/wasm-src/multicast_client.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ main(int argc, char *argv[])
5353
struct ip_mreq ipv4_group;
5454
int sd;
5555
int datalen;
56-
char databuf[1024];
56+
char databuf[1024] = { 0 };
5757
char multicast_addr_buffer[16];
5858
struct sockaddr_storage local_address = { 0 };
5959
int addr_type = -1;
@@ -116,7 +116,7 @@ main(int argc, char *argv[])
116116

117117
printf("Joined multicast group. Waiting for datagram...\n");
118118

119-
datalen = sizeof(databuf);
119+
datalen = sizeof(databuf) - 1;
120120
read_result = read(sd, databuf, datalen);
121121

122122
if (read_result < 0) {
@@ -132,4 +132,4 @@ main(int argc, char *argv[])
132132
fail:
133133
close(sd);
134134
return EXIT_FAILURE;
135-
}
135+
}

0 commit comments

Comments
 (0)