]> granicus.if.org Git - procps-ng/commitdiff
Applied corrected patch for w -i
authorJaromir Capik <jcapik@redhat.com>
Wed, 30 May 2012 11:37:13 +0000 (21:37 +1000)
committerCraig Small <csmall@enc.com.au>
Wed, 30 May 2012 11:37:13 +0000 (21:37 +1000)
I checked the second patch, saved it, it looked ok.
And then applied the first (wrong) patch. Jaromik gave this correction.

Signed-off-by: Craig Small <csmall@enc.com.au>
w.c

diff --git a/w.c b/w.c
index 42854b66a071a41de1e19e930cf4cb9bba0916f3..43e941a55001187e42c8ceec1a8e7f718e6dbe2e 100644 (file)
--- a/w.c
+++ b/w.c
@@ -146,6 +146,7 @@ static void print_display(const char *restrict host, int len, int restlen)
 /* This routine prints either the hostname or the IP address of the remote */
 static void print_from(const utmp_t *restrict const u, const int ip_addresses, const int fromlen) {
        char buf[fromlen + 1];
+       char buf_ipv6[INET6_ADDRSTRLEN];
        int len;
        int32_t ut_addr_v6[4];      /* IP address of the remote host */
 
@@ -160,8 +161,10 @@ static void print_from(const utmp_t *restrict const u, const int ip_addresses, c
                }
                if (ut_addr_v6[1] || ut_addr_v6[2] || ut_addr_v6[3]) {
                        /* IPv6 */
-                       if (!inet_ntop(AF_INET6, &ut_addr_v6, buf, sizeof(buf))) {
+                       if (!inet_ntop(AF_INET6, &ut_addr_v6, buf_ipv6, sizeof(buf_ipv6))) {
                                strcpy(buf, ""); /* invalid address, clean the buffer */
+                       } else {
+                               strncpy(buf, buf_ipv6, fromlen); /* adress valid, copy to buffer */
                        }
                } else {
                        /* IPv4 */