From: Antonio Quartulli Date: Sat, 6 Jan 2018 18:31:50 +0000 (+0800) Subject: ss: fix NULL pointer access when parsing unix sockets with oldformat X-Git-Tag: v4.15.0~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ebbb219c924ccedbc59e209d40b77d5dbeecd7cd;p=thirdparty%2Fiproute2.git 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 Cc: Stephen Hemminger Signed-off-by: Antonio Quartulli Reviewed-by: Stefano Brivio Signed-off-by: Stephen Hemminger --- diff --git a/misc/ss.c b/misc/ss.c index b35859dc4..29a250704 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -3711,7 +3711,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) {