INN commit: branches/2.5/lib (getnameinfo.c)
INN Commit
rra at isc.org
Sun Aug 21 01:32:47 UTC 2011
Date: Saturday, August 20, 2011 @ 18:32:47
Author: eagle
Revision: 9360
Fix warning suppression in getnameinfo replacement
When lengths that may be 0 are cast to unsigned before subtracting
one, we may get underflow. Move the subtraction to an addition on
the other side of the comparison. Use const void * as the cast for
calling gethostbyaddr, since it's more general than char *.
Modified:
branches/2.5/lib/getnameinfo.c
---------------+
getnameinfo.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
Modified: getnameinfo.c
===================================================================
--- getnameinfo.c 2011-08-21 01:31:53 UTC (rev 9359)
+++ getnameinfo.c 2011-08-21 01:32:47 UTC (rev 9360)
@@ -48,7 +48,7 @@
{
if (strchr(name, '.') == NULL)
return false;
- if (strlen(name) > (unsigned) nodelen - 1)
+ if (strlen(name) + 1 > (size_t) nodelen)
*status = EAI_OVERFLOW;
else {
strlcpy(node, name, nodelen);
@@ -73,7 +73,8 @@
/* Do the name lookup first unless told not to. */
if (!(flags & NI_NUMERICHOST)) {
- host = gethostbyaddr((char *) addr, sizeof(struct in_addr), AF_INET);
+ host = gethostbyaddr((const void *) addr, sizeof(struct in_addr),
+ AF_INET);
if (host == NULL) {
if (flags & NI_NAMEREQD)
return EAI_NONAME;
@@ -93,7 +94,7 @@
/* Just convert the address to ASCII. */
name = inet_ntoa(*addr);
- if (strlen(name) > (unsigned) nodelen - 1)
+ if (strlen(name) + 1 > (size_t) nodelen)
return EAI_OVERFLOW;
strlcpy(node, name, nodelen);
return 0;
@@ -116,7 +117,7 @@
protocol = (flags & NI_DGRAM) ? "udp" : "tcp";
srv = getservbyport(htons(port), protocol);
if (srv != NULL) {
- if (strlen(srv->s_name) > (unsigned) servicelen - 1)
+ if (strlen(srv->s_name) + 1 > (size_t) servicelen)
return EAI_OVERFLOW;
strlcpy(service, srv->s_name, servicelen);
return 0;
More information about the inn-committers
mailing list