[PATCH iproute2 v2 1/2] ss: move lport and rport in struct sockstat from int to long

Luigi Leonardi <[email protected]>
Newsgroups gmane.linux.network
Message-ID <[email protected]>
Commit 012cb515 ("ss: change aafilter port from int to long (inode
support)") widened aafilter.port to long so that unix socket inode
numbers larger than INT_MAX can be used as port filter values, but left
sockstat.lport and sockstat.rport as int. This means large u32 values
(e.g. vsock ports or unix inodes > INT_MAX) are truncated on the
socket-stat side, making the comparison against aafilter.port always
fail.

Widen lport and rport to long and update the sscanf format specifiers
in proc_parse_inet_addr() and unix_show() accordingly.

Fixes: 012cb515 ("ss: change aafilter port from int to long (inode support)")
Suggested-by: Stefano Garzarella <[email protected]>
Signed-off-by: Luigi Leonardi <[email protected]>
---
 misc/ss.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index 14e9f27a..ff1a88de 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -809,8 +809,8 @@ struct sockstat {
 	uint16_t	    raw_prot;
 	inet_prefix	    local;
 	inet_prefix	    remote;
-	int		    lport;
-	int		    rport;
+	long		    lport;
+	long		    rport;
 	int		    state;
 	int		    rq, wq;
 	unsigned int ino;
@@ -2490,23 +2490,23 @@ static int proc_parse_inet_addr(char *loc, char *rem, int family, struct
 {
 	s->local.family = s->remote.family = family;
 	if (family == AF_INET) {
-		sscanf(loc, "%x:%x", s->local.data, (unsigned *)&s->lport);
-		sscanf(rem, "%x:%x", s->remote.data, (unsigned *)&s->rport);
+		sscanf(loc, "%x:%lx", s->local.data, (unsigned long *)&s->lport);
+		sscanf(rem, "%x:%lx", s->remote.data, (unsigned long *)&s->rport);
 		s->local.bytelen = s->remote.bytelen = 4;
 		return 0;
 	} else {
-		sscanf(loc, "%08x%08x%08x%08x:%x",
+		sscanf(loc, "%08x%08x%08x%08x:%lx",
 		       s->local.data,
 		       s->local.data + 1,
 		       s->local.data + 2,
 		       s->local.data + 3,
-		       &s->lport);
-		sscanf(rem, "%08x%08x%08x%08x:%x",
+		       (unsigned long *)&s->lport);
+		sscanf(rem, "%08x%08x%08x%08x:%lx",
 		       s->remote.data,
 		       s->remote.data + 1,
 		       s->remote.data + 2,
 		       s->remote.data + 3,
-		       &s->rport);
+		       (unsigned long *)&s->rport);
 		s->local.bytelen = s->remote.bytelen = 16;
 		return 0;
 	}
@@ -4638,8 +4638,8 @@ static int unix_show(struct filter *f)
 		if (!(u = calloc(1, sizeof(*u))))
 			break;
 
-		if (sscanf(buf, "%x: %x %x %x %x %x %d %s",
-			   &u->rport, &u->rq, &u->wq, &flags, &u->type,
+		if (sscanf(buf, "%lx: %x %x %x %x %x %d %s",
+			   (unsigned long *)&u->rport, &u->rq, &u->wq, &flags, &u->type,
 			   &u->state, &u->ino, name) < 8)
 			name[0] = 0;
 

-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.