diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2000-09-25 22:52:58 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2000-09-25 22:52:58 +0000 |
commit | 134de69912207e006793085866ab05fc0dc38076 (patch) | |
tree | aa4a5dd97e81139dc71a224ba5ec74f9c5458b22 | |
parent | 67aba26dcb68e888a18c0b195adc5685ac27e75b (diff) |
fix off-by-1 error.
From: Pavel Kankovsky <peak@argo.troja.mff.cuni.cz>
-rw-r--r-- | lib/libc/net/getnameinfo.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/libc/net/getnameinfo.c b/lib/libc/net/getnameinfo.c index 1cabee6b976..0906686fa63 100644 --- a/lib/libc/net/getnameinfo.c +++ b/lib/libc/net/getnameinfo.c @@ -1,5 +1,5 @@ -/* $OpenBSD: getnameinfo.c,v 1.17 2000/06/12 04:28:22 itojun Exp $ */ -/* $KAME: getnameinfo.c,v 1.43 2000/06/12 04:27:03 itojun Exp $ */ +/* $OpenBSD: getnameinfo.c,v 1.18 2000/09/25 22:52:57 itojun Exp $ */ +/* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -33,11 +33,9 @@ /* * Issues to be discussed: * - Thread safe-ness must be checked - * - Return values. There seems to be no standard for return value (RFC2553) - * but INRIA implementation returns EAI_xxx defined for getaddrinfo(). * - RFC2553 says that we should raise error on short buffer. X/Open says * we need to truncate the result. We obey RFC2553 (and X/Open should be - * modified). + * modified). ipngwg rough consensus seems to follow RFC2553. * - What is "local" in NI_FQDN? * - NI_NAMEREQD and NI_NUMERICHOST conflict with each other. * - (KAME extension) NI_WITHSCOPEID when called with global address, @@ -91,6 +89,7 @@ static int ip6_parsenumeric __P((const struct sockaddr *, const char *, char *, static int ip6_sa2str __P((const struct sockaddr_in6 *, char *, size_t, int)); #endif +/* 2553bis: use EAI_xx for getnameinfo */ #define ENI_NOSOCKET EAI_FAIL /*XXX*/ #define ENI_NOSERVNAME EAI_NONAME #define ENI_NOHOSTNAME EAI_NONAME @@ -157,12 +156,12 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) (flags & NI_DGRAM) ? "udp" : "tcp"); } if (sp) { - if (strlen(sp->s_name) > servlen) + if (strlen(sp->s_name) + 1 > servlen) return ENI_MEMORY; strcpy(serv, sp->s_name); } else { snprintf(numserv, sizeof(numserv), "%d", ntohs(port)); - if (strlen(numserv) > servlen) + if (strlen(numserv) + 1 > servlen) return ENI_MEMORY; strcpy(serv, numserv); } @@ -257,7 +256,7 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) *p = '\0'; } #endif - if (strlen(hp->h_name) > hostlen) { + if (strlen(hp->h_name) + 1 > hostlen) { return ENI_MEMORY; } strcpy(host, hp->h_name); @@ -319,7 +318,7 @@ ip6_parsenumeric(sa, addr, host, hostlen, flags) /* ip6_sa2str never fails */ scopelen = ip6_sa2str((const struct sockaddr_in6 *)sa, scopebuf, sizeof(scopebuf), - 0); + flags); if (scopelen + 1 + numaddrlen + 1 > hostlen) return ENI_MEMORY; /* |