Fix inotify segfault (sf.net #2804886).
authorBrenden Matthews <brenden@rty.ca>
Sat, 13 Jun 2009 19:17:18 +0000 (13:17 -0600)
committerBrenden Matthews <brenden@rty.ca>
Sat, 13 Jun 2009 19:17:18 +0000 (13:17 -0600)
Fix segfault due to bad checking of return values for inotify code
(sf.net #2804886)

ChangeLog
src/conky.c
src/llua.c

index fa0bcd6..350dafb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2009-06-13
        * Added support for $to_bytes
+       * Fix segfault due to bad checking of return values for inotify code
+       (sf.net #2804886)
 
 2009-06-12
        * Added support for per-task I/O statistics - $top_io
index ae85777..fbfe76c 100644 (file)
@@ -6851,7 +6851,7 @@ static void main_loop(void)
 #endif
        double t;
 #ifdef HAVE_SYS_INOTIFY_H
-       int inotify_config_wd = 0;
+       int inotify_config_wd = -1;
 #define INOTIFY_EVENT_SIZE  (sizeof(struct inotify_event))
 #define INOTIFY_BUF_LEN     (20 * (INOTIFY_EVENT_SIZE + 16))
        char inotify_buff[INOTIFY_BUF_LEN];
@@ -7184,12 +7184,12 @@ static void main_loop(void)
                                break;
                }
 #ifdef HAVE_SYS_INOTIFY_H
-               if (inotify_fd && !inotify_config_wd) {
+               if (inotify_fd != -1 && inotify_config_wd != -1) {
                        inotify_config_wd = inotify_add_watch(inotify_fd,
                                        current_config,
                                        IN_MODIFY);
                }
-               if (inotify_fd && inotify_config_wd) {
+               if (inotify_fd != -1 && inotify_config_wd != -1) {
                        int len = 0, idx = 0;
                        fd_set descriptors;
                        struct timeval time_to_wait;
@@ -7232,7 +7232,7 @@ static void main_loop(void)
        }
 
 #ifdef HAVE_SYS_INOTIFY_H
-       if (inotify_fd) {
+       if (inotify_fd != -1) {
                inotify_rm_watch(inotify_fd, inotify_config_wd);
                close(inotify_fd);
                inotify_fd = inotify_config_wd = 0;
index 10f0c84..1f5479f 100644 (file)
@@ -52,7 +52,7 @@ void llua_load(const char *script)
                ERR("llua_load: %s", lua_tostring(lua_L, -1));
                lua_pop(lua_L, 1);
 #ifdef HAVE_SYS_INOTIFY_H
-       } else if (!llua_block_notify && inotify_fd) {
+       } else if (!llua_block_notify && inotify_fd != -1) {
                llua_append_notify(script);
 #endif /* HAVE_SYS_INOTIFY_H */
        }