1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-02-03 20:48:31 +00:00

Bugfix: gw_iface with a empty routingtable no longer causes a crash

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1124 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Nikolas Garofil 2008-06-04 08:09:49 +00:00
parent 8f8d5c1c8c
commit 07269f678d
3 changed files with 22 additions and 7 deletions

View File

@ -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

View File

@ -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)

View 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) {