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)
This commit is contained in:
Bastien Nocera
2003-12-23 10:43:41 +00:00
committed by Bastien Nocera
parent 84962b2301
commit 9968f74a05
13 changed files with 100 additions and 83 deletions

View File

@@ -1,3 +1,20 @@
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,

View File

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

View File

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

View File

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

View File

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

View File

@@ -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. */

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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