From ba96b53461e2b4ea9034c2e532e2abbf478772bf Mon Sep 17 00:00:00 2001 From: iedowse Date: Mon, 23 Apr 2001 10:12:31 +0000 Subject: 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. --- usr.sbin/mountd/mountd.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'usr.sbin/mountd') diff --git a/usr.sbin/mountd/mountd.c b/usr.sbin/mountd/mountd.c index 3726cba..cab8bc0 100644 --- a/usr.sbin/mountd/mountd.c +++ b/usr.sbin/mountd/mountd.c @@ -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) { -- cgit v1.1