mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-08 12:46:14 +00:00
Fix possible non null-terminated string issue in socket sample (#1612)
This commit is contained in:
parent
7cc7b56f88
commit
ace05b182d
|
@ -53,7 +53,7 @@ main(int argc, char *argv[])
|
||||||
struct ip_mreq ipv4_group;
|
struct ip_mreq ipv4_group;
|
||||||
int sd;
|
int sd;
|
||||||
int datalen;
|
int datalen;
|
||||||
char databuf[1024];
|
char databuf[1024] = { 0 };
|
||||||
char multicast_addr_buffer[16];
|
char multicast_addr_buffer[16];
|
||||||
struct sockaddr_storage local_address = { 0 };
|
struct sockaddr_storage local_address = { 0 };
|
||||||
int addr_type = -1;
|
int addr_type = -1;
|
||||||
|
@ -116,7 +116,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
printf("Joined multicast group. Waiting for datagram...\n");
|
printf("Joined multicast group. Waiting for datagram...\n");
|
||||||
|
|
||||||
datalen = sizeof(databuf);
|
datalen = sizeof(databuf) - 1;
|
||||||
read_result = read(sd, databuf, datalen);
|
read_result = read(sd, databuf, datalen);
|
||||||
|
|
||||||
if (read_result < 0) {
|
if (read_result < 0) {
|
||||||
|
@ -132,4 +132,4 @@ main(int argc, char *argv[])
|
||||||
fail:
|
fail:
|
||||||
close(sd);
|
close(sd);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user