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>
This commit is contained in:
Antonio Quartulli 2018-01-07 02:31:50 +08:00 committed by Stephen Hemminger
parent 192be8fccb
commit ebbb219c92

View File

@ -3711,7 +3711,10 @@ static int unix_show(struct filter *f)
}; };
memcpy(st.local.data, &u->name, sizeof(u->name)); 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, memcpy(st.remote.data, &u->peer_name,
sizeof(u->peer_name)); sizeof(u->peer_name));
if (run_ssfilter(f->f, &st) == 0) { if (run_ssfilter(f->f, &st) == 0) {