From: Alan T. DeKok Date: Thu, 21 Sep 2017 20:01:26 +0000 (-0400) Subject: ensure we listen only on directories for vnodes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43b4fa7edcffcb87e13b72c0868426b4c77993ab;p=thirdparty%2Ffreeradius-server.git ensure we listen only on directories for vnodes --- diff --git a/src/lib/util/event.c b/src/lib/util/event.c index 1ca60707798..53460bbf261 100644 --- a/src/lib/util/event.c +++ b/src/lib/util/event.c @@ -31,6 +31,7 @@ RCSID("$Id$") #include #include #include +#include #define FR_EV_BATCH_FDS (256) @@ -431,7 +432,28 @@ int fr_event_fd_insert(TALLOC_CTX *ctx, fr_event_list_t *el, int fd, if (read_fn) EV_SET(&evset[count++], fd, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, ef); if (write_fn) EV_SET(&evset[count++], fd, EVFILT_WRITE, EV_ADD | EV_ENABLE, 0, 0, ef); - if (vnode_fn) EV_SET(&evset[count++], fd, EVFILT_VNODE, EV_ADD | EV_ENABLE, NOTE_EXTEND, 0, ef); + if (vnode_fn) { + struct stat buf; + + /* + * Sanity checks. If we care later, we + * can listen on all NOTE_* for FDs which + * are just files. + */ + if (fstat(fd, &buf) < 0) { + fr_strerror_printf("Failed calling stat() on file"); + talloc_free(ef); + return -1; + } + + if (!S_ISDIR(buf.st_mode)) { + fr_strerror_printf("Added vnode handler on non-directory"); + talloc_free(ef); + return -1; + } + + EV_SET(&evset[count++], fd, EVFILT_VNODE, EV_ADD | EV_ENABLE, NOTE_EXTEND, 0, ef); + } if (unlikely(kevent(el->kq, evset, count, NULL, 0, NULL) < 0)) { fr_strerror_printf("Failed adding filter for FD %i: %s", fd, fr_syserror(errno));