Fix integer overflow in sigar_uptime_string

This commit is contained in:
Doug MacEachern 2007-05-10 13:49:03 +00:00
parent 741c1ae7c5
commit 3fe0a04cc5
1 changed files with 3 additions and 2 deletions

View File

@ -279,17 +279,18 @@ SIGAR_DECLARE(int) sigar_uptime_string(sigar_t *sigar,
int buflen)
{
char *ptr = buffer;
int time = (int)uptime->uptime;
int minutes, hours, days, offset = 0;
/* XXX: get rid of sprintf and/or check for overflow */
days = uptime->uptime / (60*60*24);
days = time / (60*60*24);
if (days) {
offset += sprintf(ptr + offset, "%d day%s, ",
days, (days > 1) ? "s" : "");
}
minutes = (int)uptime->uptime / 60;
minutes = time / 60;
hours = minutes / 60;
hours = hours % 24;
minutes = minutes % 60;