Skip to content

Commit

Permalink
unix: zero epoll_event before use
Browse files Browse the repository at this point in the history
Valgrind will emit the following error on a system where `int` is 32
bits:

==21616== Syscall param epoll_ctl(event) points to uninitialised byte(s)
==21616==    at 0x693E06A: epoll_ctl (syscall-template.S:84)
==21616==    by 0x529F35B: uv__io_poll (in .../libuv/libuv.so)
==21616==    by 0x528AE62: uv_run (in .../libuv/libuv.so)
[...]
==21616==  Address 0x1ffeffc8ec is on thread 1's stack
==21616==  in frame libuv#1, created by uv__io_poll (???:)

We only initialise e.events and e.data.fd, meaning half of
e.data (the 32 bits not covered by the 4-byte `fd`) is
uninitialised.

PR-URL: libuv#1996
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
  • Loading branch information
kivikakk authored and cjihrig committed Nov 21, 2018
1 parent a24e8a1 commit 0813f5b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/unix/linux-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ int uv__io_check_fd(uv_loop_t* loop, int fd) {
struct epoll_event e;
int rc;

memset(&e, 0, sizeof(e));
e.events = POLLIN;
e.data.fd = -1;

Expand Down Expand Up @@ -218,6 +219,8 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
return;
}

memset(&e, 0, sizeof(e));

while (!QUEUE_EMPTY(&loop->watcher_queue)) {
q = QUEUE_HEAD(&loop->watcher_queue);
QUEUE_REMOVE(q);
Expand Down

0 comments on commit 0813f5b

Please sign in to comment.