diff options
author | Hans-Joerg Hoexer <hshoexer@cvs.openbsd.org> | 2005-03-03 15:06:56 +0000 |
---|---|---|
committer | Hans-Joerg Hoexer <hshoexer@cvs.openbsd.org> | 2005-03-03 15:06:56 +0000 |
commit | 5faf44cf10917e8840ebf86938372301a48aad6f (patch) | |
tree | d246beb293bf21c1850c15c908ef7b933c3eacf9 /sbin | |
parent | 6ec5e7090839490c3bcd1d98b98748c97fa51002 (diff) |
handle return value of snprintf more carefully
ok cloder ho
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/isakmpd/policy.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/sbin/isakmpd/policy.c b/sbin/isakmpd/policy.c index 27759454b98..01d7a59200f 100644 --- a/sbin/isakmpd/policy.c +++ b/sbin/isakmpd/policy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: policy.c,v 1.79 2005/02/27 13:12:12 hshoexer Exp $ */ +/* $OpenBSD: policy.c,v 1.80 2005/03/03 15:06:55 hshoexer Exp $ */ /* $EOM: policy.c,v 1.49 2000/10/24 13:33:39 niklas Exp $ */ /* @@ -87,15 +87,17 @@ my_inet_ntop4(const in_addr_t *src, char *dst, size_t size, int normalize) static const char fmt[] = "%03u.%03u.%03u.%03u"; char tmp[sizeof "255.255.255.255"]; in_addr_t src2; + int len; if (normalize) src2 = ntohl(*src); else src2 = *src; - if (snprintf(tmp, sizeof tmp, fmt, ((u_int8_t *)&src2)[0], + len = snprintf(tmp, sizeof tmp, fmt, ((u_int8_t *)&src2)[0], ((u_int8_t *)&src2)[1], ((u_int8_t *)&src2)[2], - ((u_int8_t *)&src2)[3]) > (int)size) { + ((u_int8_t *)&src2)[3]); + if (len == -1 || len > (int)size) { errno = ENOSPC; return 0; } @@ -109,10 +111,12 @@ my_inet_ntop6(const unsigned char *src, char *dst, size_t size) static const char fmt[] = "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x"; char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"]; + int len; - if (snprintf(tmp, sizeof tmp, fmt, src[0], src[1], src[2], src[3], + len = snprintf(tmp, sizeof tmp, fmt, src[0], src[1], src[2], src[3], src[4], src[5], src[6], src[7], src[8], src[9], src[10], src[11], - src[12], src[13], src[14], src[15]) > (int)size) { + src[12], src[13], src[14], src[15]); + if (len == -1 || len > (int)size) { errno = ENOSPC; return 0; } |