From f689f208af8d19203e48a9387101b7853d8e8706 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Tue, 9 Aug 2016 18:19:56 +0200 Subject: Protect 'i' in |_handle_inotify_watch| by DBUS_ENABLE_VERBOSE_MODE Signed-off-by: Thomas Zimmermann --- bus/dir-watch-inotify.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/bus/dir-watch-inotify.c b/bus/dir-watch-inotify.c index e9ea0ed..53ed8ab 100644 --- a/bus/dir-watch-inotify.c +++ b/bus/dir-watch-inotify.c @@ -59,7 +59,6 @@ _handle_inotify_watch (DBusWatch *passed_watch, unsigned int flags, void *data) { char buffer[INOTIFY_BUF_LEN]; ssize_t ret = 0; - int i = 0; ret = read (inotify_fd, buffer, INOTIFY_BUF_LEN); if (ret < 0) @@ -73,16 +72,20 @@ _handle_inotify_watch (DBusWatch *passed_watch, unsigned int flags, void *data) } #ifdef DBUS_ENABLE_VERBOSE_MODE - while (i < ret) - { - struct inotify_event *ev; + { + int i = 0; - ev = (struct inotify_event *) &buffer[i]; - i += INOTIFY_EVENT_SIZE + ev->len; - if (ev->len) - _dbus_verbose ("event name: '%s'\n", ev->name); - _dbus_verbose ("inotify event: wd=%d mask=%u cookie=%u len=%u\n", ev->wd, ev->mask, ev->cookie, ev->len); - } + while (i < ret) + { + struct inotify_event *ev; + + ev = (struct inotify_event *) &buffer[i]; + i += INOTIFY_EVENT_SIZE + ev->len; + if (ev->len) + _dbus_verbose ("event name: '%s'\n", ev->name); + _dbus_verbose ("inotify event: wd=%d mask=%u cookie=%u len=%u\n", ev->wd, ev->mask, ev->cookie, ev->len); + } + } #endif return TRUE; -- 2.7.4