All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ss: replace all zero characters in a unix name to '@'
@ 2017-04-01  1:31 Andrei Vagin
  2017-04-04 21:44 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Andrei Vagin @ 2017-04-01  1:31 UTC (permalink / raw)
  To: stephen; +Cc: netdev, Andrei Vagin

From: Andrei Vagin <avagin@virtuozzo.com>

A name of an abstract socket can contain zero characters.
Now we replace only the first character. If a name contains more
than one zero character, the ss tool shows only a part of the name:
u_str  UNCONN    0    0     @                            1931097   * 0

the output with this patch:
u_str  UNCONN    0    0     @@zdtm-./sk-unix-unconn-23/@ 1931097   * 0

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 misc/ss.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/misc/ss.c b/misc/ss.c
index 5cda728..a3200a1 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -2726,10 +2726,24 @@ static int unix_show_sock(const struct sockaddr_nl *addr, struct nlmsghdr *nlh,
 	if (tb[UNIX_DIAG_NAME]) {
 		int len = RTA_PAYLOAD(tb[UNIX_DIAG_NAME]);
 
+		if (len > sizeof(name) - 1)
+			len = sizeof(name) - 1;
+
 		memcpy(name, RTA_DATA(tb[UNIX_DIAG_NAME]), len);
 		name[len] = '\0';
-		if (name[0] == '\0')
+		if (name[0] == '\0') {
+			char *n;
+
 			name[0] = '@';
+
+			n = name + 1;
+			while (n && n < name + len) {
+				n = memchr(n, 0, name + len - n);
+				if (n == NULL)
+					break;
+				*n = '@';
+			}
+		}
 		stat.name = &name[0];
 		memcpy(stat.local.data, &stat.name, sizeof(stat.name));
 	}
-- 
2.7.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ss: replace all zero characters in a unix name to '@'
  2017-04-01  1:31 [PATCH] ss: replace all zero characters in a unix name to '@' Andrei Vagin
@ 2017-04-04 21:44 ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2017-04-04 21:44 UTC (permalink / raw)
  To: Andrei Vagin; +Cc: netdev, Andrei Vagin

On Sat,  1 Apr 2017 04:31:57 +0300
Andrei Vagin <avagin@openvz.org> wrote:

> From: Andrei Vagin <avagin@virtuozzo.com>
> 
> A name of an abstract socket can contain zero characters.
> Now we replace only the first character. If a name contains more
> than one zero character, the ss tool shows only a part of the name:
> u_str  UNCONN    0    0     @                            1931097   * 0
> 
> the output with this patch:
> u_str  UNCONN    0    0     @@zdtm-./sk-unix-unconn-23/@ 1931097   * 0
> 
> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>

This patch duplicates changes that are already in current version.

commit 878dadc79d247aa37b67fb30608e58ef1f9ab9ff
Author: Isaac Boukris <iboukris@gmail.com>
Date:   Sat Oct 29 22:20:19 2016 +0300

    iproute2: ss: escape all null bytes in abstract unix domain socket
    
    Abstract unix domain socket may embed null characters,
    these should be translated to '@' when printed by ss the
    same way the null prefix is currently being translated.
    
    Signed-off-by: Isaac Boukris <iboukris@gmail.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-04-04 21:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-01  1:31 [PATCH] ss: replace all zero characters in a unix name to '@' Andrei Vagin
2017-04-04 21:44 ` Stephen Hemminger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.