diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2003-03-04 00:29:18 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2003-03-04 00:29:18 +0000 |
commit | 798906b736c5b108d3db2cb493e03a474c6cc059 (patch) | |
tree | 3405246fba7774d279c3cf33f29686575de27ae7 | |
parent | 11c9efbb72c43c56f695bc0936a159533cf6a8e8 (diff) |
strlcpy, check retval from sprintf
-rw-r--r-- | lib/libc/net/getaddrinfo.c | 4 | ||||
-rw-r--r-- | lib/libc/net/gethostnamadr.c | 17 | ||||
-rw-r--r-- | lib/libc/net/res_debug.c | 8 |
3 files changed, 18 insertions, 11 deletions
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index 7406f107145..241c5b17aee 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getaddrinfo.c,v 1.44 2003/01/28 04:58:00 marc Exp $ */ +/* $OpenBSD: getaddrinfo.c,v 1.45 2003/03/04 00:29:17 itojun Exp $ */ /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ /* @@ -1137,7 +1137,7 @@ getanswer(answer, anslen, qname, qtype, pai) had_error++; continue; } - strcpy(bp, tbuf); + strlcpy(bp, tbuf, ep - bp); canonname = bp; bp += n; continue; diff --git a/lib/libc/net/gethostnamadr.c b/lib/libc/net/gethostnamadr.c index 5211f423c60..7cf419fdb1c 100644 --- a/lib/libc/net/gethostnamadr.c +++ b/lib/libc/net/gethostnamadr.c @@ -52,7 +52,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.54 2003/01/28 04:58:00 marc Exp $"; +static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.55 2003/03/04 00:29:17 itojun Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -664,7 +664,7 @@ gethostbyaddr(addr, len, af) int n, size, i; querybuf *buf; register struct hostent *hp; - char qbuf[MAXDNAME+1], *qp; + char qbuf[MAXDNAME+1], *qp, *ep; extern struct hostent *_gethtbyaddr(), *_yp_gethtbyaddr(); char lookups[MAXDNSLUS]; struct hostent *res; @@ -706,6 +706,7 @@ gethostbyaddr(addr, len, af) h_errno = NETDB_INTERNAL; return (NULL); } + ep = qbuf + sizeof(qbuf); switch (af) { case AF_INET: (void) snprintf(qbuf, sizeof qbuf, "%u.%u.%u.%u.in-addr.arpa", @@ -715,8 +716,14 @@ gethostbyaddr(addr, len, af) case AF_INET6: qp = qbuf; for (n = IN6ADDRSZ - 1; n >= 0; n--) { - qp += sprintf(qp, "%x.%x.", + i = snprintf(qp, ep - qp, "%x.%x.", uaddr[n] & 0xf, (uaddr[n] >> 4) & 0xf); + if (i <= 0) { + errno = EINVAL; + h_errno = NETDB_INTERNAL; + return (NULL); + } + qp += i; } break; } @@ -737,14 +744,14 @@ gethostbyaddr(addr, len, af) #endif case 'b': if (af == AF_INET6) - strcpy(qp, "ip6.arpa"); + strlcpy(qp, "ip6.arpa", ep - qp); buf = malloc(sizeof(*buf)); if (!buf) break; n = res_query(qbuf, C_IN, T_PTR, buf->buf, sizeof(buf->buf)); if (n < 0 && af == AF_INET6) { - strcpy(qp, "ip6.int"); + strlcpy(qp, "ip6.int", ep - qp); n = res_query(qbuf, C_IN, T_PTR, buf->buf, sizeof(buf->buf)); } diff --git a/lib/libc/net/res_debug.c b/lib/libc/net/res_debug.c index f4e4c271ed2..b39e9a3b14f 100644 --- a/lib/libc/net/res_debug.c +++ b/lib/libc/net/res_debug.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_debug.c,v 1.15 2003/01/28 04:58:00 marc Exp $ */ +/* $OpenBSD: res_debug.c,v 1.16 2003/03/04 00:29:17 itojun Exp $ */ /* * ++Copyright++ 1985, 1990, 1993 @@ -82,7 +82,7 @@ static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; static char rcsid[] = "$From: res_debug.c,v 8.19 1996/11/26 10:11:23 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: res_debug.c,v 1.15 2003/01/28 04:58:00 marc Exp $"; +static char rcsid[] = "$OpenBSD: res_debug.c,v 1.16 2003/03/04 00:29:17 itojun Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -448,10 +448,10 @@ __p_fqnname(cp, msg, msglen, name, namelen) return (NULL); newlen = strlen(name); if (newlen == 0 || name[newlen - 1] != '.') { - if (newlen+1 >= namelen) /* Lack space for final dot */ + if (newlen + 1 >= namelen) /* Lack space for final dot */ return (NULL); else - strcpy(name + newlen, "."); + strlcpy(name + newlen, ".", namelen - newlen); } return (cp + n); } |