When I added code to use whois.nic.XX for new TLDs I forgot to think
about one case, where the TLD is a substring of one of the "traditional"
TLDs who have to use the old whois-servers.net method. Specifically,
trying to lookup a .network name will incorrectly try to use
network.whois-servers.net - strncasecmp was the wrong decision,
so this diff switches to strcasecmp instead to fix. They're all
null-terminated strings.

before:

$ whois shitty.network|head -5
whois: network.whois-servers.net: no address associated with name

after:

$ whois shitty.network|head -5
Domain Name: shitty.network
Domain ID: d8b5dc3cc4f44139a517c0f66d1c8ad7-D
WHOIS Server: http://whois.rrpproxy.net
Referral URL: http://key-systems.net
Updated Date: 2015-01-02T15:18:22Z

Bonus simplification, use "snprintf...%s" rather than strlcpy+strlcat.

ok?

Index: whois.c
===================================================================
RCS file: /cvs/src/usr.bin/whois/whois.c,v
retrieving revision 1.47
diff -u -p -r1.47 whois.c
--- whois.c     9 Apr 2015 19:29:53 -0000       1.47
+++ whois.c     16 Aug 2015 20:50:10 -0000
@@ -310,22 +310,21 @@ choose_server(const char *name, const ch
         * Post-2003 ("new") gTLDs are all supposed to have "whois.nic.domain"
         * (per registry agreement), some older gTLDs also support this...
         */
-       strlcpy(server, "whois.nic.", len);
-       strlcat(server, qhead, len);
+       snprintf(server, len, "whois.nic.%s", qhead);
 
        /* most ccTLDs don't do this, but QNICHOST/whois-servers mostly works */
        if ((strlen(qhead) == 2 ||
            /* and is required for most of the <=2003 TLDs/gTLDs */
-           strncasecmp(qhead, "org", 3) == 0 ||
-           strncasecmp(qhead, "com", 3) == 0 ||
-           strncasecmp(qhead, "net", 3) == 0 ||
-           strncasecmp(qhead, "cat", 3) == 0 ||
-           strncasecmp(qhead, "pro", 3) == 0 ||
-           strncasecmp(qhead, "info", 4) == 0 ||
-           strncasecmp(qhead, "aero", 4) == 0 ||
-           strncasecmp(qhead, "jobs", 4) == 0 ||
-           strncasecmp(qhead, "mobi", 4) == 0 ||
-           strncasecmp(qhead, "museum", 6) == 0 ||
+           strcasecmp(qhead, "org") == 0 ||
+           strcasecmp(qhead, "com") == 0 ||
+           strcasecmp(qhead, "net") == 0 ||
+           strcasecmp(qhead, "cat") == 0 ||
+           strcasecmp(qhead, "pro") == 0 ||
+           strcasecmp(qhead, "info") == 0 ||
+           strcasecmp(qhead, "aero") == 0 ||
+           strcasecmp(qhead, "jobs") == 0 ||
+           strcasecmp(qhead, "mobi") == 0 ||
+           strcasecmp(qhead, "museum") == 0 ||
             /* for others, if whois.nic.TLD doesn't exist, try whois-servers */
            getaddrinfo(server, NULL, &hints, &res) != 0)) {
                strlcpy(server, qhead, len);

Reply via email to