Skip to content

Commit

Permalink
Zero-initialise stack-allocated objects in hstox driver.
Browse files Browse the repository at this point in the history
These potentially cause uninitialised reads on some platforms or msgpack
library versions.
  • Loading branch information
iphydf committed Jan 10, 2018
1 parent d604769 commit 22975d8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions testing/hstox/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static int write_sample_input(msgpack_object req)

check_return(E_WRITE, ftruncate(fd, 0));

msgpack_sbuffer sbuf __attribute__((__cleanup__(msgpack_sbuffer_destroy)));
msgpack_sbuffer sbuf __attribute__((__cleanup__(msgpack_sbuffer_destroy))) = {0};
msgpack_sbuffer_init(&sbuf);

msgpack_packer pk;
Expand All @@ -101,7 +101,7 @@ static int handle_request(struct settings cfg, int write_fd, msgpack_object req)
fprintf(stderr, "\n");
}

msgpack_sbuffer sbuf __attribute__((__cleanup__(msgpack_sbuffer_destroy))); /* buffer */
msgpack_sbuffer sbuf __attribute__((__cleanup__(msgpack_sbuffer_destroy))) = {0}; /* buffer */
msgpack_sbuffer_init(&sbuf); /* initialize buffer */

msgpack_packer pk; /* packer */
Expand Down Expand Up @@ -186,7 +186,7 @@ int communicate(struct settings cfg, int read_fd, int write_fd)
memcpy(msgpack_unpacker_buffer(&unp), buf, size);
msgpack_unpacker_buffer_consumed(&unp, size);

msgpack_unpacked req __attribute__((__cleanup__(msgpack_unpacked_destroy)));
msgpack_unpacked req __attribute__((__cleanup__(msgpack_unpacked_destroy))) = {0};
msgpack_unpacked_init(&req);

switch (msgpack_unpacker_next(&unp, &req)) {
Expand Down Expand Up @@ -225,7 +225,7 @@ static int run_tests(struct settings cfg, int port)
1
}, sizeof(int)));

struct sockaddr_in servaddr;
struct sockaddr_in servaddr = {0};
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htons(INADDR_ANY);
servaddr.sin_port = htons(port);
Expand Down

0 comments on commit 22975d8

Please sign in to comment.