diff options
author | Bastien Nocera <hadess@hadess.net> | 2003-12-23 10:43:41 +0000 |
---|---|---|
committer | Bastien Nocera <hadess@src.gnome.org> | 2003-12-23 10:43:41 +0000 |
commit | 9968f74a054fb91b3881de729aa99b71c7f0d730 (patch) | |
tree | 57ea8e42a6589e28878a424c7cee52f973322006 | |
parent | 84962b23015a0eceafae6eab76fa4c1cef1d4959 (diff) | |
download | libgtop-9968f74a054fb91b3881de729aa99b71c7f0d730.tar.gz |
Apply patch from Benoît Dejean <bnet@ifrance.com> to fix overflow issues
2003-12-23 Bastien Nocera <hadess@hadess.net>
* cpu.c: (glibtop_get_cpu_s):
* glibtop_server.h:
* loadavg.c: (glibtop_get_loadavg_s):
* mem.c: (glibtop_get_mem_s):
* netload.c: (glibtop_get_netload_s):
* prockernel.c: (glibtop_get_proc_kernel_s):
* procmem.c: (glibtop_get_proc_mem_s):
* procsegment.c: (glibtop_get_proc_segment_s):
* procsignal.c: (glibtop_get_proc_signal_s):
* proctime.c: (glibtop_get_proc_time_s):
* procuid.c: (glibtop_get_proc_uid_s):
* swap.c: (glibtop_get_swap_s): Apply patch from Benoît Dejean
<bnet@ifrance.com> to fix overflow issues using strtol
(Closes: #129881)
-rw-r--r-- | sysdeps/linux/ChangeLog | 17 | ||||
-rw-r--r-- | sysdeps/linux/cpu.c | 16 | ||||
-rw-r--r-- | sysdeps/linux/glibtop_server.h | 6 | ||||
-rw-r--r-- | sysdeps/linux/loadavg.c | 12 | ||||
-rw-r--r-- | sysdeps/linux/mem.c | 2 | ||||
-rw-r--r-- | sysdeps/linux/netload.c | 24 | ||||
-rw-r--r-- | sysdeps/linux/prockernel.c | 16 | ||||
-rw-r--r-- | sysdeps/linux/procmem.c | 18 | ||||
-rw-r--r-- | sysdeps/linux/procsegment.c | 14 | ||||
-rw-r--r-- | sysdeps/linux/procsignal.c | 8 | ||||
-rw-r--r-- | sysdeps/linux/proctime.c | 22 | ||||
-rw-r--r-- | sysdeps/linux/procuid.c | 24 | ||||
-rw-r--r-- | sysdeps/linux/swap.c | 4 |
13 files changed, 100 insertions, 83 deletions
diff --git a/sysdeps/linux/ChangeLog b/sysdeps/linux/ChangeLog index 1fd3cdd6..c3944912 100644 --- a/sysdeps/linux/ChangeLog +++ b/sysdeps/linux/ChangeLog @@ -1,5 +1,22 @@ 2003-12-23 Bastien Nocera <hadess@hadess.net> + * cpu.c: (glibtop_get_cpu_s): + * glibtop_server.h: + * loadavg.c: (glibtop_get_loadavg_s): + * mem.c: (glibtop_get_mem_s): + * netload.c: (glibtop_get_netload_s): + * prockernel.c: (glibtop_get_proc_kernel_s): + * procmem.c: (glibtop_get_proc_mem_s): + * procsegment.c: (glibtop_get_proc_segment_s): + * procsignal.c: (glibtop_get_proc_signal_s): + * proctime.c: (glibtop_get_proc_time_s): + * procuid.c: (glibtop_get_proc_uid_s): + * swap.c: (glibtop_get_swap_s): Apply patch from Benoît Dejean + <bnet@ifrance.com> to fix overflow issues using strtol + (Closes: #129881) + +2003-12-23 Bastien Nocera <hadess@hadess.net> + * mem.c: (glibtop_get_mem_s): Fix calculation of used memory, patch by Benoît Dejean, <bnet@ifrance.com> (Closes: #129863) diff --git a/sysdeps/linux/cpu.c b/sysdeps/linux/cpu.c index 012670ad..92f593a5 100644 --- a/sysdeps/linux/cpu.c +++ b/sysdeps/linux/cpu.c @@ -75,10 +75,10 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf) p = skip_token (buffer); /* "cpu" */ - buf->user = strtoul (p, &p, 0); - buf->nice = strtoul (p, &p, 0); - buf->sys = strtoul (p, &p, 0); - buf->idle = strtoul (p, &p, 0); + buf->user = strtoull (p, &p, 0); + buf->nice = strtoull (p, &p, 0); + buf->sys = strtoull (p, &p, 0); + buf->idle = strtoull (p, &p, 0); total = buf->user; total += buf->nice; @@ -94,10 +94,10 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf) break; p += 6; - buf->xcpu_user [i] = strtoul (p, &p, 0); - buf->xcpu_nice [i] = strtoul (p, &p, 0); - buf->xcpu_sys [i] = strtoul (p, &p, 0); - buf->xcpu_idle [i] = strtoul (p, &p, 0); + buf->xcpu_user [i] = strtoull (p, &p, 0); + buf->xcpu_nice [i] = strtoull (p, &p, 0); + buf->xcpu_sys [i] = strtoull (p, &p, 0); + buf->xcpu_idle [i] = strtoull (p, &p, 0); total = buf->xcpu_user [i]; total += buf->xcpu_nice [i]; diff --git a/sysdeps/linux/glibtop_server.h b/sysdeps/linux/glibtop_server.h index ee923676..aba64b52 100644 --- a/sysdeps/linux/glibtop_server.h +++ b/sysdeps/linux/glibtop_server.h @@ -57,17 +57,17 @@ skip_line (const char *p) return (char *) ++p; } -static inline unsigned long +static inline unsigned long long get_scaled(const char *buffer, const char *key) { const char *ptr; char *next; - unsigned long value = 0; + unsigned long long value = 0; if ((ptr = strstr(buffer, key))) { ptr += strlen(key); - value = strtoul(ptr, &next, 0); + value = strtoull(ptr, &next, 0); if (strchr(next, 'k')) value *= 1024; else if (strchr(next, 'M')) diff --git a/sysdeps/linux/loadavg.c b/sysdeps/linux/loadavg.c index aedff8ca..84622e41 100644 --- a/sysdeps/linux/loadavg.c +++ b/sysdeps/linux/loadavg.c @@ -67,9 +67,9 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf) buffer [len] = '\0'; - buf->loadavg [0] = (float) strtod (buffer, &p); - buf->loadavg [1] = (float) strtod (p, &p); - buf->loadavg [2] = (float) strtod (p, &p); + buf->loadavg [0] = strtod (buffer, &p); + buf->loadavg [1] = strtod (p, &p); + buf->loadavg [2] = strtod (p, &p); buf->flags = _glibtop_sysdeps_loadavg; @@ -86,9 +86,9 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf) p++; } - buf->nr_running = strtoul (old, &p, 0); p++; - buf->nr_tasks = strtoul (p, &p, 0); - buf->last_pid = strtoul (p, &p, 0); + buf->nr_running = strtoull (old, &p, 0); p++; + buf->nr_tasks = strtoull (p, &p, 0); + buf->last_pid = strtoull (p, &p, 0); buf->flags |= _glibtop_sysdeps_loadavg_tasks; } diff --git a/sysdeps/linux/mem.c b/sysdeps/linux/mem.c index a0c7e7f0..a969d61b 100644 --- a/sysdeps/linux/mem.c +++ b/sysdeps/linux/mem.c @@ -46,7 +46,7 @@ glibtop_init_mem_s (glibtop *server) void glibtop_get_mem_s (glibtop *server, glibtop_mem *buf) { - char buffer [BUFSIZ], *p; + char buffer [BUFSIZ]; int fd, len; glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0); diff --git a/sysdeps/linux/netload.c b/sysdeps/linux/netload.c index 75cd1ab6..f73c8b90 100644 --- a/sysdeps/linux/netload.c +++ b/sysdeps/linux/netload.c @@ -112,7 +112,7 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf, skfd = socket (AF_INET, SOCK_DGRAM, 0); if (skfd) { struct ifreq ifr; - unsigned flags; + unsigned long long flags; strcpy (ifr.ifr_name, interface); if (!ioctl (skfd, SIOCGIFFLAGS, &ifr)) { @@ -197,7 +197,7 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf, fgets (buffer, BUFSIZ-1, f); while (fgets (buffer, BUFSIZ-1, f)) { - unsigned long flags, packets, bytes; + unsigned long long flags, packets, bytes; char *p, *dev; /* Skip over the network thing. */ @@ -212,12 +212,12 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf, p = skip_token (p); - flags = strtoul (p, &p, 16); + flags = strtoull (p, &p, 16); p = skip_multiple_token (p, 2); - packets = strtoul (p, &p, 0); - bytes = strtoul (p, &p, 0); + packets = strtoull (p, &p, 0); + bytes = strtoull (p, &p, 0); if (flags & _GLIBTOP_IP_FW_ACCTIN) { /* Incoming packets only. */ @@ -317,24 +317,24 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf, /* Only read byte counts if we really have them. */ if (have_bytes) { - buf->bytes_in = strtoul (p, &p, 0); + buf->bytes_in = strtoull (p, &p, 0); fields--; } - buf->packets_in = strtoul (p, &p, 0); - buf->errors_in = strtoul (p, &p, 0); + buf->packets_in = strtoull (p, &p, 0); + buf->errors_in = strtoull (p, &p, 0); p = skip_multiple_token (p, fields); if (have_bytes) - buf->bytes_out = strtoul (p, &p, 0); + buf->bytes_out = strtoull (p, &p, 0); - buf->packets_out = strtoul (p, &p, 0); - buf->errors_out = strtoul (p, &p, 0); + buf->packets_out = strtoull (p, &p, 0); + buf->errors_out = strtoull (p, &p, 0); p = skip_multiple_token (p, 2); - buf->collisions = strtoul (p, &p, 0); + buf->collisions = strtoull (p, &p, 0); /* Compute total valules. */ diff --git a/sysdeps/linux/prockernel.c b/sysdeps/linux/prockernel.c index 46a82ec6..6fa34ce6 100644 --- a/sysdeps/linux/prockernel.c +++ b/sysdeps/linux/prockernel.c @@ -58,20 +58,20 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid) p = skip_multiple_token (p, 6); - buf->k_flags = strtoul (p, &p, 0); - buf->min_flt = strtoul (p, &p, 0); - buf->cmin_flt = strtoul (p, &p, 0); - buf->maj_flt = strtoul (p, &p, 0); - buf->cmaj_flt = strtoul (p, &p, 0); + buf->k_flags = strtoull (p, &p, 0); + buf->min_flt = strtoull (p, &p, 0); + buf->cmin_flt = strtoull (p, &p, 0); + buf->maj_flt = strtoull (p, &p, 0); + buf->cmaj_flt = strtoull (p, &p, 0); p = skip_multiple_token (p, 15); - buf->kstk_esp = strtoul (p, &p, 0); - buf->kstk_eip = strtoul (p, &p, 0); + buf->kstk_esp = strtoull (p, &p, 0); + buf->kstk_eip = strtoull (p, &p, 0); p = skip_multiple_token (p, 4); - buf->nwchan = strtoul (p, &p, 0); + buf->nwchan = strtoull (p, &p, 0); buf->flags = _glibtop_sysdeps_proc_kernel; } diff --git a/sysdeps/linux/procmem.c b/sysdeps/linux/procmem.c index 3e868ee8..313ed0a5 100644 --- a/sysdeps/linux/procmem.c +++ b/sysdeps/linux/procmem.c @@ -82,23 +82,23 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid) p = skip_multiple_token (p, 20); - buf->vsize = strtoul (p, &p, 0); - buf->rss = strtoul (p, &p, 0); - buf->rss_rlim = strtoul (p, &p, 0); + buf->vsize = strtoull (p, &p, 0); + buf->rss = strtoull (p, &p, 0); + buf->rss_rlim = strtoull (p, &p, 0); buf->flags = _glibtop_sysdeps_proc_mem; if (proc_statm_to_buffer (buffer, pid)) return; - buf->size = strtoul (buffer, &p, 0); - buf->resident = strtoul (p, &p, 0); - buf->share = strtoul (p, &p, 0); + buf->size = strtoull (buffer, &p, 0); + buf->resident = strtoull (p, &p, 0); + buf->share = strtoull (p, &p, 0); - buf->size <<= pageshift; + buf->size <<= pageshift; buf->resident <<= pageshift; - buf->share <<= pageshift; - buf->rss <<= pageshift; + buf->share <<= pageshift; + buf->rss <<= pageshift; buf->flags |= _glibtop_sysdeps_proc_mem_statm; } diff --git a/sysdeps/linux/procsegment.c b/sysdeps/linux/procsegment.c index 3179ae40..48fd0f59 100644 --- a/sysdeps/linux/procsegment.c +++ b/sysdeps/linux/procsegment.c @@ -87,9 +87,9 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf, p = skip_multiple_token (p, 23); - buf->start_code = strtoul (p, &p, 0); - buf->end_code = strtoul (p, &p, 0); - buf->start_stack = strtoul (p, &p, 0); + buf->start_code = strtoull (p, &p, 0); + buf->end_code = strtoull (p, &p, 0); + buf->start_stack = strtoull (p, &p, 0); buf->flags = _glibtop_sysdeps_proc_segment; @@ -101,10 +101,10 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf, /* This doesn't work very well due to a bug in the Linux kernel. * I'll submit a patch to the kernel mailing list soon. */ - buf->text_rss = strtoul (p, &p, 0); - buf->shlib_rss = strtoul (p, &p, 0); - buf->data_rss = strtoul (p, &p, 0); - buf->dirty_size = strtoul (p, &p, 0); + buf->text_rss = strtoull (p, &p, 0); + buf->shlib_rss = strtoull (p, &p, 0); + buf->data_rss = strtoull (p, &p, 0); + buf->dirty_size = strtoull (p, &p, 0); buf->text_rss <<= pageshift; buf->shlib_rss <<= pageshift; diff --git a/sysdeps/linux/procsignal.c b/sysdeps/linux/procsignal.c index 7d8fa56c..6260428d 100644 --- a/sysdeps/linux/procsignal.c +++ b/sysdeps/linux/procsignal.c @@ -56,10 +56,10 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid) p = skip_multiple_token (p, 28); - buf->signal [0] = strtoul (p, &p, 0); - buf->blocked [0] = strtoul (p, &p, 0); - buf->sigignore [0] = strtoul (p, &p, 0); - buf->sigcatch [0] = strtoul (p, &p, 0); + buf->signal [0] = strtoull (p, &p, 0); + buf->blocked [0] = strtoull (p, &p, 0); + buf->sigignore [0] = strtoull (p, &p, 0); + buf->sigcatch [0] = strtoull (p, &p, 0); buf->flags = _glibtop_sysdeps_proc_signal; } diff --git a/sysdeps/linux/proctime.c b/sysdeps/linux/proctime.c index 83ea92b8..e1f500fa 100644 --- a/sysdeps/linux/proctime.c +++ b/sysdeps/linux/proctime.c @@ -65,16 +65,16 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid) p = skip_multiple_token (p, 11); - buf->utime = strtoul (p, &p, 0); - buf->stime = strtoul (p, &p, 0); - buf->cutime = strtoul (p, &p, 0); - buf->cstime = strtoul (p, &p, 0); + buf->utime = strtoull (p, &p, 0); + buf->stime = strtoull (p, &p, 0); + buf->cutime = strtoull (p, &p, 0); + buf->cstime = strtoull (p, &p, 0); p = skip_multiple_token (p, 2); - buf->timeout = strtoul (p, &p, 0); - buf->it_real_value = strtoul (p, &p, 0); - buf->start_time = strtoul (p, &p, 0); + buf->timeout = strtoull (p, &p, 0); + buf->it_real_value = strtoull (p, &p, 0); + buf->start_time = strtoull (p, &p, 0); buf->frequency = 100; @@ -87,16 +87,16 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid) return; p = skip_token (buffer); - buf->utime = strtoul (p, &p, 0); - buf->stime = strtoul (p, &p, 0); + buf->utime = strtoull (p, &p, 0); + buf->stime = strtoull (p, &p, 0); for (i = 0; i < GLIBTOP_NCPU; i++) { if (strncmp (p+1, "cpu", 3) || !isdigit (p [4])) break; p += 6; - buf->xcpu_utime [i] = strtoul (p, &p, 0); - buf->xcpu_stime [i] = strtoul (p, &p, 0); + buf->xcpu_utime [i] = strtoull (p, &p, 0); + buf->xcpu_stime [i] = strtoull (p, &p, 0); } buf->flags |= _glibtop_sysdeps_proc_time_smp; diff --git a/sysdeps/linux/procuid.c b/sysdeps/linux/procuid.c index a7585dcc..4ba09139 100644 --- a/sysdeps/linux/procuid.c +++ b/sysdeps/linux/procuid.c @@ -66,10 +66,10 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid) if (!p) return; p = skip_token (p); /* "Pid:" */ - buf->pid = strtoul (p, &p, 0); + buf->pid = strtol (p, &p, 0); p = skip_token (p); /* "PPid:" */ - buf->ppid = strtoul (p, &p, 0); + buf->ppid = strtol (p, &p, 0); /* Maybe future Linux versions place something between * "PPid" and "Uid", so we catch this here. */ @@ -77,8 +77,8 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid) if (!p) return; p = skip_token (p); /* "Uid:" */ - buf->uid = strtoul (p, &p, 0); - buf->euid = strtoul (p, &p, 0); + buf->uid = strtol (p, &p, 0); + buf->euid = strtol (p, &p, 0); /* We don't know how many entries on the "Uid:" line * future Linux version will have, so we catch this here. */ @@ -86,8 +86,8 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid) if (!p) return; p = skip_token (p); /* "Gid:" */ - buf->gid = strtoul (p, &p, 0); - buf->egid = strtoul (p, &p, 0); + buf->gid = strtol (p, &p, 0); + buf->egid = strtol (p, &p, 0); buf->flags = _glibtop_sysdeps_proc_uid; @@ -99,15 +99,15 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid) p = skip_multiple_token (p, 2); - buf->pgrp = strtoul (p, &p, 0); - buf->session = strtoul (p, &p, 0); - buf->tty = strtoul (p, &p, 0); - buf->tpgid = strtoul (p, &p, 0); + buf->pgrp = strtol (p, &p, 0); + buf->session = strtol (p, &p, 0); + buf->tty = strtol (p, &p, 0); + buf->tpgid = strtol (p, &p, 0); p = skip_multiple_token (p, 9); - buf->priority = strtoul (p, &p, 0); - buf->nice = strtoul (p, &p, 0); + buf->priority = strtol (p, &p, 0); + buf->nice = strtol (p, &p, 0); if (buf->tty == 0) /* the old notty val, update elsewhere bef. moving to 0 */ diff --git a/sysdeps/linux/swap.c b/sysdeps/linux/swap.c index 70e5bb61..eb018123 100644 --- a/sysdeps/linux/swap.c +++ b/sysdeps/linux/swap.c @@ -95,8 +95,8 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf) p = skip_token (p); - buf->pagein = strtoul (p, &p, 0); - buf->pageout = strtoul (p, &p, 0); + buf->pagein = strtoull (p, &p, 0); + buf->pageout = strtoull (p, &p, 0); buf->flags |= _glibtop_sysdeps_swap_paging; } |