chiark / gitweb /
Poll loop: fix read of unused fds[]
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 1 Jul 2011 22:47:10 +0000 (23:47 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 1 Jul 2011 22:47:13 +0000 (23:47 +0100)
Commit 29672515
 portability: Work around Apple's bizarrely deficient poll() implementation
introduced a read of unitialised data in fds[], because it failed to
honour i->nfds which is 0 on the first iteration.

The symptom is that secnet may, on the first iteration, die due to
mistakenly seeing POLLNVAL.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
secnet.c

index 2bf50fd40992406108e297cb0dd63cbfe0d24244..36750ec39ae4ffd51979f375d3c37fb9d00e1747 100644 (file)
--- a/secnet.c
+++ b/secnet.c
@@ -309,8 +309,11 @@ static void run(void)
                   ((uint64_t)tv_now_global.tv_usec/(uint64_t)1000);
        idx=0;
        for (i=reg; i; i=i->next) {
                   ((uint64_t)tv_now_global.tv_usec/(uint64_t)1000);
        idx=0;
        for (i=reg; i; i=i->next) {
-           if(fds[idx].revents & POLLNVAL) {
-               fatal("run: poll (%s) set POLLNVAL", i->desc);
+           int check;
+           for (check=0; check<i->nfds; check++) {
+               if(fds[idx+check].revents & POLLNVAL) {
+                   fatal("run: poll (%s#%d) set POLLNVAL", i->desc, check);
+               }
            }
            i->after(i->state, fds+idx, i->nfds);
            idx+=i->nfds;
            }
            i->after(i->state, fds+idx, i->nfds);
            idx+=i->nfds;