Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/w Restore ']' if not using a result from an address ...



details:   https://anonhg.NetBSD.org/src/rev/e6a38e50aac6
branches:  trunk
changeset: 974498:e6a38e50aac6
user:      kim <kim%NetBSD.org@localhost>
date:      Sat Aug 01 17:25:57 2020 +0000

description:
Restore ']' if not using a result from an address lookup.

diffstat:

 usr.bin/w/w.c |  26 +++++++++++++++-----------
 1 files changed, 15 insertions(+), 11 deletions(-)

diffs (68 lines):

diff -r 9d5fa69b4982 -r e6a38e50aac6 usr.bin/w/w.c
--- a/usr.bin/w/w.c     Sat Aug 01 17:20:42 2020 +0000
+++ b/usr.bin/w/w.c     Sat Aug 01 17:25:57 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: w.c,v 1.88 2020/08/01 15:52:50 kim Exp $       */
+/*     $NetBSD: w.c,v 1.89 2020/08/01 17:25:57 kim Exp $       */
 
 /*-
  * Copyright (c) 1980, 1991, 1993, 1994
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)w.c        8.6 (Berkeley) 6/30/94";
 #else
-__RCSID("$NetBSD: w.c,v 1.88 2020/08/01 15:52:50 kim Exp $");
+__RCSID("$NetBSD: w.c,v 1.89 2020/08/01 17:25:57 kim Exp $");
 #endif
 #endif /* not lint */
 
@@ -621,7 +621,7 @@
 fixhost(struct entry *ep)
 {
        char host_buf[sizeof(ep->host)];
-       char *p, *r, *x, *m;
+       char *b, *m, *p, *r, *x;
        struct hostent *hp;
        union {
                struct in_addr l4;
@@ -653,19 +653,20 @@
        /*
         * Leading '[' indicates an IP address inside brackets.
         */
+       b = NULL;
        if (*p == '[') {
-               for (p++; p < &host_buf[sizeof(host_buf)]; p++)
-                       if (*p == '\0' || *p == ']')
+               for (b = p++; b < &host_buf[sizeof(host_buf)]; b++)
+                       if (*b == '\0' || *b == ']')
                                break;
-               if (p < &host_buf[sizeof(host_buf)] && *p == ']') {
-                       *p = '\0';
-                       for (x = ++p; x < &host_buf[sizeof(host_buf)]; x++)
+               if (b < &host_buf[sizeof(host_buf)] && *b == ']') {
+                       *b = '\0';
+                       for (x = b + 1; x < &host_buf[sizeof(host_buf)]; x++)
                                if (*x == '\0' || *x == ':')
                                        break;
                        if (x < &host_buf[sizeof(host_buf)] && *x == ':')
                                *x++ = '\0';
-               }
-               p = host_buf + 1;
+               } else
+                       b = NULL;
        }
 
        int af = m ? AF_INET6 : AF_INET;
@@ -673,8 +674,11 @@
        if (!nflag && inet_pton(af, p, &l) &&
            (hp = gethostbyaddr((char *)&l, alen, af)))
                r = hp->h_name;
-       else
+       else {
+               if (b)
+                       *b = ']';
                r = host_buf;
+       }
 
        if (domain[0] != '\0') {
                p = r;



Home | Main Index | Thread Index | Old Index