From 5c8c22d61aadea94296688843aceebea419e7f38 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Sat, 18 Aug 2001 20:39:44 +0000 Subject: more careful with snprintf result code --- sbin/ifconfig/ifconfig.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'sbin/ifconfig') 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 -- cgit v1.2.3