Date: Tue, 10 Jul 2001 17:03:26 -0400 (EDT) From: Mike Barcroft <mike@q9media.com> To: FreeBSD-gnats-submit@freebsd.org Subject: bin/28880: [patch] src/usr.bin/whois bug fix Message-ID: <200107102103.f6AL3QB20816@coffee.q9media.com>
next in thread | raw e-mail | index | archive | help
>Number: 28880
>Category: bin
>Synopsis: [patch] src/usr.bin/whois bug fix
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Tue Jul 10 13:50:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Mike Barcroft
>Release: FreeBSD 5.0-CURRENT i386
>Organization:
Q9 Media
>Environment:
$FreeBSD: src/usr.bin/whois/whois.c,v 1.20 2001/06/27 23:06:47 dd Exp $
>Description:
o Re-write the logic that finds the whois server to query.
[This fixes a bug where one would type 'whois foo.bar.'
and get an error because of the trailing period.]
o Tested on i386 and alpha
>How-To-Repeat:
N/A
>Fix:
Index: whois/whois.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/whois/whois.c,v
retrieving revision 1.20
diff -u -r1.20 whois.c
--- whois/whois.c 2001/06/27 23:06:47 1.20
+++ whois/whois.c 2001/07/10 20:38:48
@@ -79,6 +79,7 @@
const char *ip_whois[] = { RNICHOST, PNICHOST, NULL };
+static char *choose_server(const char *);
static void usage(void);
static void whois(char *, struct addrinfo *, int);
@@ -88,7 +89,7 @@
struct addrinfo hints, *res;
const char *host;
char *qnichost;
- int ch, error, flags, i, j, use_qnichost;
+ int ch, error, flags, use_qnichost;
#ifdef SOCKS
SOCKSinit(argv[0]);
@@ -159,21 +160,7 @@
}
while (argc--) {
if (use_qnichost) {
- for (i = j = 0; (*argv)[i]; i++)
- if ((*argv)[i] == '.')
- j = i;
- if (j != 0) {
- if (isdigit(*(*argv + j + 1))) {
- asprintf(&qnichost, "%s", ANICHOST);
- if (qnichost == NULL)
- err(1, "asprintf()");
- } else {
- asprintf(&qnichost, "%s%s",
- *argv + j + 1, QNICHOST_TAIL);
- if (qnichost == NULL)
- err(1, "asprintf()");
- }
-
+ if ((qnichost = choose_server(*argv)) != NULL) {
memset(&hints, 0, sizeof(hints));
hints.ai_flags = 0;
hints.ai_family = AF_UNSPEC;
@@ -202,6 +189,40 @@
freeaddrinfo(res);
}
exit(0);
+}
+
+/*
+ * Returns a pointer to newly allocated memory containing the whois server to
+ * be queried, or a NULL pointer, if the correct server couldn't be determined.
+ * The caller must remember to free(3) the allocated memory.
+ */
+static char *
+choose_server(const char *domain)
+{
+ size_t len;
+ char *buf, *pos, *retval;
+
+ if ((buf = strdup(domain)) == NULL)
+ err(1, "strdup()");
+ len = strlen(buf);
+ while (len && buf[len - 1] == '.')
+ buf[--len] = '\0';
+ if ((pos = strrchr(buf, '.')) == NULL) {
+ free(buf);
+ return (NULL);
+ }
+ pos++;
+ if (isdigit(*pos)) {
+ asprintf(&retval, "%s", ANICHOST);
+ if (retval == NULL)
+ err(1, "asprintf()");
+ } else {
+ asprintf(&retval, "%s%s", pos, QNICHOST_TAIL);
+ if (retval == NULL)
+ err(1, "asprintf()");
+ }
+ free(buf);
+ return (retval);
}
static void
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200107102103.f6AL3QB20816>
