From 734aa10414ca862b145afe3a9448e5c70ded101f Mon Sep 17 00:00:00 2001 From: Hajimu UMEMOTO Date: Sun, 21 May 2006 11:22:31 +0000 Subject: [PATCH] Return EAI_OVERFLOW instead of EAI_MEMORY when the supplied buffer is too short. This conforms to RFC3493, POSIX and XPG6. Obtained from: NetBSD --- include/netdb.h | 7 ++++--- lib/libc/net/gai_strerror.3 | 2 ++ lib/libc/net/gai_strerror.c | 3 ++- lib/libc/net/getnameinfo.c | 6 +++--- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/netdb.h b/include/netdb.h index 6e7d8189695a..33a5051bcbd6 100644 --- a/include/netdb.h +++ b/include/netdb.h @@ -168,9 +168,10 @@ struct addrinfo { #define EAI_SERVICE 9 /* servname not supported for ai_socktype */ #define EAI_SOCKTYPE 10 /* ai_socktype not supported */ #define EAI_SYSTEM 11 /* system error returned in errno */ -#define EAI_BADHINTS 12 -#define EAI_PROTOCOL 13 -#define EAI_MAX 14 +#define EAI_BADHINTS 12 /* invalid value for hints */ +#define EAI_PROTOCOL 13 /* resolved protocol is unknown */ +#define EAI_OVERFLOW 14 /* argument buffer overflow */ +#define EAI_MAX 15 /* * Flag values for getaddrinfo() diff --git a/lib/libc/net/gai_strerror.3 b/lib/libc/net/gai_strerror.3 index 7c5503026ed1..51d0d073a0bf 100644 --- a/lib/libc/net/gai_strerror.3 +++ b/lib/libc/net/gai_strerror.3 @@ -63,6 +63,8 @@ memory allocation failure or .Fa servname not provided, or not known +.It Dv EAI_OVERFLOW +argument buffer overflow .It Dv EAI_PROTOCOL resolved protocol is unknown .It Dv EAI_SERVICE diff --git a/lib/libc/net/gai_strerror.c b/lib/libc/net/gai_strerror.c index bd351abd1266..5611559cfe0c 100644 --- a/lib/libc/net/gai_strerror.c +++ b/lib/libc/net/gai_strerror.c @@ -48,7 +48,8 @@ static const char *ai_errlist[] = { "ai_socktype not supported", /* EAI_SOCKTYPE */ "System error returned in errno", /* EAI_SYSTEM */ "Invalid value for hints", /* EAI_BADHINTS */ - "Resolved protocol is unknown" /* EAI_PROTOCOL */ + "Resolved protocol is unknown", /* EAI_PROTOCOL */ + "Argument buffer overflow" /* EAI_OVERFLOW */ }; const char * diff --git a/lib/libc/net/getnameinfo.c b/lib/libc/net/getnameinfo.c index b14cc27255fc..ed1e3af11bec 100644 --- a/lib/libc/net/getnameinfo.c +++ b/lib/libc/net/getnameinfo.c @@ -280,7 +280,7 @@ ip6_parsenumeric(const struct sockaddr *sa, const char *addr, numaddrlen = strlen(numaddr); if (numaddrlen + 1 > hostlen) /* don't forget terminator */ - return EAI_MEMORY; + return EAI_OVERFLOW; strlcpy(host, numaddr, hostlen); if (((const struct sockaddr_in6 *)sa)->sin6_scope_id) { @@ -291,9 +291,9 @@ ip6_parsenumeric(const struct sockaddr *sa, const char *addr, (const struct sockaddr_in6 *)(const void *)sa, zonebuf, sizeof(zonebuf), flags); if (zonelen < 0) - return EAI_MEMORY; + return EAI_OVERFLOW; if (zonelen + 1 + numaddrlen + 1 > hostlen) - return EAI_MEMORY; + return EAI_OVERFLOW; /* construct */ memcpy(host + numaddrlen + 1, zonebuf,