diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2001-08-22 05:34:55 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2001-08-22 05:34:55 +0000 |
commit | f26b1c80c3f81bfcc31314b8c572952f05de8693 (patch) | |
tree | 9870e2ac86627fe5854fbda6c07843756471ba07 /usr.sbin/rtsold/dump.c | |
parent | 0fc3ca7ddfeb031be48404c0c22d0fce5291149a (diff) |
snprintf() return audit. sync with kame
Diffstat (limited to 'usr.sbin/rtsold/dump.c')
-rw-r--r-- | usr.sbin/rtsold/dump.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/usr.sbin/rtsold/dump.c b/usr.sbin/rtsold/dump.c index ddbb0ec441a..3769d11e1f0 100644 --- a/usr.sbin/rtsold/dump.c +++ b/usr.sbin/rtsold/dump.c @@ -1,5 +1,5 @@ -/* $OpenBSD: dump.c,v 1.5 2000/10/06 02:46:58 itojun Exp $ */ -/* $KAME: dump.c,v 1.8 2000/10/05 22:20:39 itojun Exp $ */ +/* $OpenBSD: dump.c,v 1.6 2001/08/22 05:34:54 itojun Exp $ */ +/* $KAME: dump.c,v 1.9 2001/08/20 06:55:54 itojun Exp $ */ /* * Copyright (C) 1999 WIDE Project. @@ -117,6 +117,8 @@ sec2str(total) int days, hours, mins, secs; int first = 1; char *p = result; + char *ep = &result[sizeof(result)]; + int n; days = total / 3600 / 24; hours = (total / 3600) % 24; @@ -125,17 +127,26 @@ sec2str(total) if (days) { first = 0; - p += sprintf(p, "%dd", days); + n = snprintf(p, ep - p, "%dd", days); + if (n < 0 || n >= ep - p) + return "?"; + p += n; } if (!first || hours) { first = 0; - p += sprintf(p, "%dh", hours); + n = snprintf(p, ep - p, "%dh", hours); + if (n < 0 || n >= ep - p) + return "?"; + p += n; } if (!first || mins) { first = 0; - p += sprintf(p, "%dm", mins); + n = snprintf(p, ep - p, "%dm", mins); + if (n < 0 || n >= ep - p) + return "?"; + p += n; } - sprintf(p, "%ds", secs); + snprintf(p, ep - p, "%ds", secs); return(result); } |