Bugfix: gw_iface with a empty routingtable no longer causes a crash
authorNikolas Garofil <ngarofil@users.sourceforge.net>
Wed, 4 Jun 2008 08:09:49 +0000 (08:09 +0000)
committerNikolas Garofil <ngarofil@users.sourceforge.net>
Wed, 4 Jun 2008 08:09:49 +0000 (08:09 +0000)
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1124 7f574dfc-610e-0410-a909-a81674777703

AUTHORS
ChangeLog
src/linux.c

diff --git a/AUTHORS b/AUTHORS
index 9cf8097..8e27fe8 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -62,6 +62,9 @@ Dave Clark <clarkd at skynet dot ca>
 David McCabe
   utime
 
+garo <nikolas at garofil dot be>
+  gw_iface fix
+
 Ram Yalamanchili
   tztime
 
index e904736..78eca40 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 # $Id$
 
+2008-06-04
+       * Fix bug where conky tries to free a already freed pointer when you
+       use gw_iface with a empty routingtable in linux
+
 2008-06-03
        * Added NVIDIA Graficcard support patch (thanks meissna)
        * Added --quiet patch (thanks sceptik)
index 9baffff..4576c93 100644 (file)
@@ -261,6 +261,16 @@ END_TRUE:
                x = strndup(y, text_buffer_size); \
        }
 
+void update_gateway_info_failure(char *reason)
+{
+       if(reason != NULL) {
+               perror(reason);
+       }
+       //2 pointers to 1 location causes a crash when we try to free them both
+       info.gw_info.iface = strndup("failed", text_buffer_size);
+       info.gw_info.ip = strndup("failed", text_buffer_size);
+}
+
 void update_gateway_info(void)
 {
        FILE *fp;
@@ -277,14 +287,13 @@ void update_gateway_info(void)
        gw_info->count = 0;
 
        if ((fp = fopen("/proc/net/route", "r")) == NULL) {
-               perror("fopen()");
-               info.gw_info.iface = info.gw_info.ip = strndup("failed", text_buffer_size);
-               return;
+               update_gateway_info_failure("fopen()");
+               return;
        }
        if (fscanf(fp, "%*[^\n]\n") == EOF) {
-               perror("fscanf()");
+               //NULL because a empty table is not a error
+               update_gateway_info_failure(NULL);
                fclose(fp);
-               info.gw_info.iface = info.gw_info.ip = strndup("failed", text_buffer_size);
                return;
        }
        while (!feof(fp)) {
@@ -292,9 +301,8 @@ void update_gateway_info(void)
                if(fscanf(fp, "%63s %lx %lx %x %hd %hd %hd %lx %hd %hd %hd\n",
                                        iface, &dest, &gate, &flags, &ref, &use,
                                        &metric, &mask, &mtu, &win, &irtt) != 11) {
-                       perror("fscanf()");
+                       update_gateway_info_failure("fscanf()");
                        fclose(fp);
-                       info.gw_info.iface = info.gw_info.ip = strndup("failed", text_buffer_size);
                        return;
                }
                if (flags & RTF_GATEWAY && dest == 0 && mask == 0) {