diff options
author | ume <ume@FreeBSD.org> | 2003-08-11 15:49:47 +0000 |
---|---|---|
committer | ume <ume@FreeBSD.org> | 2003-08-11 15:49:47 +0000 |
commit | 44f95bb1cf973ee7e97882481b4462f246d78836 (patch) | |
tree | 1c20b2e94f632085097f94556620788a63d45a06 /usr.sbin/rtsold/dump.c | |
parent | b984cea4428252c6c92362d4e353c589314d8887 (diff) | |
download | FreeBSD-src-44f95bb1cf973ee7e97882481b4462f246d78836.zip FreeBSD-src-44f95bb1cf973ee7e97882481b4462f246d78836.tar.gz |
use strlcpy() and snprintf().
Obtained from: KAME
MFC after: 1 week
Diffstat (limited to 'usr.sbin/rtsold/dump.c')
-rw-r--r-- | usr.sbin/rtsold/dump.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/usr.sbin/rtsold/dump.c b/usr.sbin/rtsold/dump.c index 72d31b9..3902fc0 100644 --- a/usr.sbin/rtsold/dump.c +++ b/usr.sbin/rtsold/dump.c @@ -1,4 +1,4 @@ -/* $KAME: dump.c,v 1.8 2000/10/05 22:20:39 itojun Exp $ */ +/* $KAME: dump.c,v 1.12 2003/04/11 10:14:55 jinmei 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,16 +127,25 @@ 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); } |