diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-08-18 20:39:44 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-08-18 20:39:44 +0000 |
commit | 5c8c22d61aadea94296688843aceebea419e7f38 (patch) | |
tree | 0c502f1731d5c5c267cc08292705b1197156c4b6 /sbin | |
parent | 0d3662ae94e9970d0836ca94cb251b967b54f305 (diff) |
more careful with snprintf result code
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/ifconfig/ifconfig.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index c9414be532d..494f29b771e 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifconfig.c,v 1.50 2001/07/25 17:41:06 itojun Exp $ */ +/* $OpenBSD: ifconfig.c,v 1.51 2001/08/18 20:39:43 deraadt Exp $ */ /* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */ /* @@ -81,7 +81,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94"; #else -static char rcsid[] = "$OpenBSD: ifconfig.c,v 1.50 2001/07/25 17:41:06 itojun Exp $"; +static char rcsid[] = "$OpenBSD: ifconfig.c,v 1.51 2001/08/18 20:39:43 deraadt Exp $"; #endif #endif /* not lint */ @@ -2372,6 +2372,7 @@ sec2str(total) int first = 1; char *p = result; char *end = &result[sizeof(result)]; + int n; if (0) { /*XXX*/ days = total / 3600 / 24; @@ -2381,15 +2382,24 @@ sec2str(total) if (days) { first = 0; - p += snprintf(p, end - p, "%dd", days); + n = snprintf(p, end - p, "%dd", days); + if (n < 0 || n >= end - p) + return(result); + p -= n; } if (!first || hours) { first = 0; - p += snprintf(p, end - p, "%dh", hours); + n = snprintf(p, end - p, "%dh", hours); + if (n < 0 || n >= end - p) + return(result); + p -= n; } if (!first || mins) { first = 0; - p += snprintf(p, end - p, "%dm", mins); + n = snprintf(p, end - p, "%dm", mins); + if (n < 0 || n >= end - p) + return(result); + p -= n; } snprintf(p, end - p, "%ds", secs); } else |