mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-12-04 12:28:58 +00:00
Reinstate one more old bugfix that got lost in the tirpc commit:
always look up -network and -mask addresses numerically before trying getnetbyname(). Without this, we may end up attempting DNS queries on silly names such as "127.0.0.0.my-domain.com". See the commit log from revisions 1.21 and 1.20 for further details.
This commit is contained in:
parent
b2bcd87e4f
commit
931c04f1a8
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=75861
@ -1866,10 +1866,10 @@ get_net(cp, net, maskflg)
|
||||
struct netmsk *net;
|
||||
int maskflg;
|
||||
{
|
||||
struct netent *np;
|
||||
struct netent *np = NULL;
|
||||
char *name, *p, *prefp;
|
||||
struct sockaddr_in sin;
|
||||
struct sockaddr *sa;
|
||||
struct sockaddr *sa = NULL;
|
||||
struct addrinfo hints, *ai = NULL;
|
||||
char netname[NI_MAXHOST];
|
||||
long preflen;
|
||||
@ -1881,13 +1881,11 @@ get_net(cp, net, maskflg)
|
||||
prefp = p + 1;
|
||||
}
|
||||
|
||||
if ((np = getnetbyname(cp)) != NULL) {
|
||||
bzero(&sin, sizeof sin);
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_len = sizeof sin;
|
||||
sin.sin_addr = inet_makeaddr(np->n_net, 0);
|
||||
sa = (struct sockaddr *)&sin;
|
||||
} else if (isxdigit(*cp) || *cp == ':') {
|
||||
/*
|
||||
* Check for a numeric address first. We wish to avoid
|
||||
* possible DNS lookups in getnetbyname().
|
||||
*/
|
||||
if (isxdigit(*cp) || *cp == ':') {
|
||||
memset(&hints, 0, sizeof hints);
|
||||
/* Ensure the mask and the network have the same family. */
|
||||
if (maskflg && (opt_flags & OP_NET))
|
||||
@ -1897,9 +1895,9 @@ get_net(cp, net, maskflg)
|
||||
else
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_flags = AI_NUMERICHOST;
|
||||
if (getaddrinfo(cp, NULL, &hints, &ai) != 0)
|
||||
goto fail;
|
||||
if (ai->ai_family == AF_INET) {
|
||||
if (getaddrinfo(cp, NULL, &hints, &ai) == 0)
|
||||
sa = ai->ai_addr;
|
||||
if (sa != NULL && ai->ai_family == AF_INET) {
|
||||
/*
|
||||
* The address in `cp' is really a network address, so
|
||||
* use inet_network() to re-interpret this correctly.
|
||||
@ -1913,9 +1911,16 @@ get_net(cp, net, maskflg)
|
||||
fprintf(stderr, "get_net: v4 addr %s\n",
|
||||
inet_ntoa(sin.sin_addr));
|
||||
sa = (struct sockaddr *)&sin;
|
||||
} else
|
||||
sa = ai->ai_addr;
|
||||
} else
|
||||
}
|
||||
}
|
||||
if (sa == NULL && (np = getnetbyname(cp)) != NULL) {
|
||||
bzero(&sin, sizeof sin);
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_len = sizeof sin;
|
||||
sin.sin_addr = inet_makeaddr(np->n_net, 0);
|
||||
sa = (struct sockaddr *)&sin;
|
||||
}
|
||||
if (sa == NULL)
|
||||
goto fail;
|
||||
|
||||
if (maskflg) {
|
||||
|
@ -1866,10 +1866,10 @@ get_net(cp, net, maskflg)
|
||||
struct netmsk *net;
|
||||
int maskflg;
|
||||
{
|
||||
struct netent *np;
|
||||
struct netent *np = NULL;
|
||||
char *name, *p, *prefp;
|
||||
struct sockaddr_in sin;
|
||||
struct sockaddr *sa;
|
||||
struct sockaddr *sa = NULL;
|
||||
struct addrinfo hints, *ai = NULL;
|
||||
char netname[NI_MAXHOST];
|
||||
long preflen;
|
||||
@ -1881,13 +1881,11 @@ get_net(cp, net, maskflg)
|
||||
prefp = p + 1;
|
||||
}
|
||||
|
||||
if ((np = getnetbyname(cp)) != NULL) {
|
||||
bzero(&sin, sizeof sin);
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_len = sizeof sin;
|
||||
sin.sin_addr = inet_makeaddr(np->n_net, 0);
|
||||
sa = (struct sockaddr *)&sin;
|
||||
} else if (isxdigit(*cp) || *cp == ':') {
|
||||
/*
|
||||
* Check for a numeric address first. We wish to avoid
|
||||
* possible DNS lookups in getnetbyname().
|
||||
*/
|
||||
if (isxdigit(*cp) || *cp == ':') {
|
||||
memset(&hints, 0, sizeof hints);
|
||||
/* Ensure the mask and the network have the same family. */
|
||||
if (maskflg && (opt_flags & OP_NET))
|
||||
@ -1897,9 +1895,9 @@ get_net(cp, net, maskflg)
|
||||
else
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_flags = AI_NUMERICHOST;
|
||||
if (getaddrinfo(cp, NULL, &hints, &ai) != 0)
|
||||
goto fail;
|
||||
if (ai->ai_family == AF_INET) {
|
||||
if (getaddrinfo(cp, NULL, &hints, &ai) == 0)
|
||||
sa = ai->ai_addr;
|
||||
if (sa != NULL && ai->ai_family == AF_INET) {
|
||||
/*
|
||||
* The address in `cp' is really a network address, so
|
||||
* use inet_network() to re-interpret this correctly.
|
||||
@ -1913,9 +1911,16 @@ get_net(cp, net, maskflg)
|
||||
fprintf(stderr, "get_net: v4 addr %s\n",
|
||||
inet_ntoa(sin.sin_addr));
|
||||
sa = (struct sockaddr *)&sin;
|
||||
} else
|
||||
sa = ai->ai_addr;
|
||||
} else
|
||||
}
|
||||
}
|
||||
if (sa == NULL && (np = getnetbyname(cp)) != NULL) {
|
||||
bzero(&sin, sizeof sin);
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_len = sizeof sin;
|
||||
sin.sin_addr = inet_makeaddr(np->n_net, 0);
|
||||
sa = (struct sockaddr *)&sin;
|
||||
}
|
||||
if (sa == NULL)
|
||||
goto fail;
|
||||
|
||||
if (maskflg) {
|
||||
|
Loading…
Reference in New Issue
Block a user