naccyde / rpms / iproute

Forked from rpms/iproute 7 months ago
Clone
Blob Blame History Raw
From c903640ae37106ae416592a413a1f55afd56eeda Mon Sep 17 00:00:00 2001
From: Andrea Claudi <aclaudi@redhat.com>
Date: Wed, 22 Apr 2020 10:21:03 +0200
Subject: [PATCH] ss: fix NULL pointer access when parsing unix sockets with
 oldformat

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1795891
Upstream Status: iproute2.git commit ebbb219c924cc

commit ebbb219c924ccedbc59e209d40b77d5dbeecd7cd
Author: Antonio Quartulli <a@unstable.cc>
Date:   Sun Jan 7 02:31:50 2018 +0800

    ss: fix NULL pointer access when parsing unix sockets with oldformat

    When parsing and printing the unix sockets in unix_show(),
    if the oldformat is detected, the peer_name member of the sockstat
    object is left uninitialized (NULL).
    For this reason, if a filter has been specified on the command line,
    a strcmp() will crash when trying to access it.

    Avoid crash by checking that peer_name is not NULL before
    passing it to strcmp().

    Cc: Stefano Brivio <sbrivio@redhat.com>
    Cc: Stephen Hemminger <stephen@networkplumber.org>
    Signed-off-by: Antonio Quartulli <a@unstable.cc>
    Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
    Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 misc/ss.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/misc/ss.c b/misc/ss.c
index 8f184fb929d31..0b66cca7aaab2 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -3276,7 +3276,10 @@ static int unix_show(struct filter *f)
 			};
 
 			memcpy(st.local.data, &u->name, sizeof(u->name));
-			if (strcmp(u->peer_name, "*"))
+			/* when parsing the old format rport is set to 0 and
+			 * therefore peer_name remains NULL
+			 */
+			if (u->peer_name && strcmp(u->peer_name, "*"))
 				memcpy(st.remote.data, &u->peer_name,
 				       sizeof(u->peer_name));
 			if (run_ssfilter(f->f, &st) == 0) {
-- 
2.25.3