From 5ba055a8e514698058589d3b615d408767a6e330 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Tue, 1 Aug 2017 16:45:25 +0200 Subject: [PATCH] #928: fix possible TypeError --- psutil/_psbsd.py | 12 ++++++++---- psutil/_pssunos.py | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py index fe55f92f2..ba2414cd4 100644 --- a/psutil/_psbsd.py +++ b/psutil/_psbsd.py @@ -719,8 +719,10 @@ def connections(self, kind='inet'): except KeyError: status = TCP_STATUSES[cext.PSUTIL_CONN_NONE] if fam in (AF_INET, AF_INET6): - laddr = _common.addr(*laddr) - raddr = _common.addr(*raddr) + if laddr: + laddr = _common.addr(*laddr) + if raddr: + raddr = _common.addr(*raddr) fam = sockfam_to_enum(fam) type = socktype_to_enum(type) nt = _common.pconn(fd, fam, type, laddr, raddr, status) @@ -737,8 +739,10 @@ def connections(self, kind='inet'): for item in rawlist: fd, fam, type, laddr, raddr, status = item if fam in (AF_INET, AF_INET6): - laddr = _common.addr(*laddr) - raddr = _common.addr(*raddr) + if laddr: + laddr = _common.addr(*laddr) + if raddr: + raddr = _common.addr(*raddr) fam = sockfam_to_enum(fam) type = socktype_to_enum(type) status = TCP_STATUSES[status] diff --git a/psutil/_pssunos.py b/psutil/_pssunos.py index 9931d885f..06e8bbbaa 100644 --- a/psutil/_pssunos.py +++ b/psutil/_pssunos.py @@ -266,8 +266,10 @@ def net_connections(kind, _pid=-1): if type_ not in types: continue if fam in (AF_INET, AF_INET6): - laddr = _common.addr(*laddr) - raddr = _common.addr(*raddr) + if laddr: + laddr = _common.addr(*laddr) + if raddr: + raddr = _common.addr(*raddr) status = TCP_STATUSES[status] fam = sockfam_to_enum(fam) type_ = socktype_to_enum(type_)