[PATCH 4/7] Protect 'i' in |_handle_inotify_watch| by DBUS_ENABLE_VERBOSE_MODE

Thomas Zimmermann tdz at users.sourceforge.net
Tue Aug 9 19:18:29 UTC 2016


Signed-off-by: Thomas Zimmermann <tdz at users.sourceforge.net>
---
 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



More information about the dbus mailing list