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

Thomas Zimmermann <[email protected]>
Newsgroups gmane.comp.freedesktop.dbus
Message-ID <[email protected]>
Signed-off-by: Thomas Zimmermann <[email protected]>
---
 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

_______________________________________________
dbus mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dbus
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.