Skip to content

Commit

Permalink
- reject numeric address
Browse files Browse the repository at this point in the history
- validate scope in sockaddr comparison logic

patch was originally submitted by itojun and slightly modified by me.

Reviewed by:	itojun, kris
  • Loading branch information
Hajimu UMEMOTO authored and Hajimu UMEMOTO committed Sep 25, 2000
1 parent 65e893c commit 6568848
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions contrib/tcp_wrappers/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,23 @@ struct host_info *host;

STRN_CPY(host->name, hname, sizeof(host->name));

/* reject numeric addresses */
memset(&hints, 0, sizeof(hints));
hints.ai_family = sin->sa_family;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST;
if ((err = getaddrinfo(host->name, NULL, &hints, &res0) == 0)) {
freeaddrinfo(res0);
tcpd_warn("host name/name mismatch: "
"reverse lookup results in non-FQDN %s",
host->name);
strcpy(host->name, paranoid); /* name is bad, clobber it */
}
err = !err;
}
if (!err) {
/* we are now sure that this is non-numeric */

/*
* Verify that the address is a member of the address list returned
* by gethostbyname(hostname).
Expand Down Expand Up @@ -276,6 +293,11 @@ struct host_info *host;
rap = (char *)&((struct sockaddr_in *)res->ai_addr)->sin_addr;
break;
case AF_INET6:
/* need to check scope_id */
if (((struct sockaddr_in6 *)sin)->sin6_scope_id !=
((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id) {
continue;
}
rap = (char *)&((struct sockaddr_in6 *)res->ai_addr)->sin6_addr;
break;
default:
Expand Down

0 comments on commit 6568848

Please sign in to comment.