From hans@chaosradio.ccc.de Thu Apr 22 13:31:43 1999
Return-Path: <hans@chaosradio.ccc.de>
Received: from berlin.ccc.de (berlin.ccc.de [195.21.255.248])
	by hub.freebsd.org (Postfix) with ESMTP id 23A4514EBA
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 22 Apr 1999 13:31:40 -0700 (PDT)
	(envelope-from hans@chaosradio.ccc.de)
Received: from hans by berlin.ccc.de with local (Exim 2.05 #1)
	id 10aQ5D-000K49-00
	for FreeBSD-gnats-submit@freebsd.org; Thu, 22 Apr 1999 22:28:27 +0200
Message-Id: <E10aQ5D-000K49-00@berlin.ccc.de>
Date: Thu, 22 Apr 1999 22:28:27 +0200
From: Hans Huebner <hans@chaosradio.ccc.de>
Reply-To: hans@chaosradio.ccc.de
To: FreeBSD-gnats-submit@freebsd.org
Subject: [patch] /usr/bin/w fails with -n flag for certain host names
X-Send-Pr-Version: 3.2

>Number:         11286
>Category:       bin
>Synopsis:       [patch] /usr/bin/w fails with -n flag for certain host names
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Apr 22 13:30:02 PDT 1999
>Closed-Date:    Thu Apr 22 16:42:26 PDT 1999
>Last-Modified:  Thu Apr 22 16:42:53 PDT 1999
>Originator:     Hans Huebner
>Release:        FreeBSD 3.1-STABLE i386
>Organization:
Chaos Computer Club Berlin
>Environment:

-STABLE as of this week.

>Description:

The w command has a flag -n, which makes it print IP addresses instead
of host names in the FROM field.  If a user's entry in the utmp file
contains a hostname with 16 chars, w fails to translate it back to
an IP adress.

>How-To-Repeat:

"w -n" on a system with someone logged in from a host whose name is
16 characters long.

>Fix:

Index: w.c
===================================================================
RCS file: /usr/cvs/src/usr.bin/w/w.c,v
retrieving revision 1.32
diff -u -r1.32 w.c
--- w.c 1999/01/10 15:28:37     1.32
+++ w.c 1999/04/22 20:16:12
@@ -337,7 +337,10 @@
                }
 
        for (ep = ehead; ep != NULL; ep = ep->next) {
-               p = *ep->utmp.ut_host ? ep->utmp.ut_host : "-";
+               char host_buf[UT_HOSTSIZE+1];
+               host_buf[UT_HOSTSIZE] = '\0';
+               strncpy(host_buf, ep->utmp.ut_host, UT_HOSTSIZE);
+               p = *host_buf ? host_buf : "-";
                if ((x = strchr(p, ':')) != NULL)
                        *x++ = '\0';
                if (!nflag && isdigit(*p) &&



>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: ache 
State-Changed-When: Thu Apr 22 16:42:26 PDT 1999 
State-Changed-Why:  
Fixed patch applied 
>Unformatted:
