From patchwork Wed Mar 30 21:12:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thadeu Lima de Souza Cascardo X-Patchwork-Id: 603653 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (unknown [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3qb0j52KdMz9s9Z for ; Thu, 31 Mar 2016 08:12:40 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 4879B10682; Wed, 30 Mar 2016 14:12:30 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e3.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id E221910681 for ; Wed, 30 Mar 2016 14:12:28 -0700 (PDT) Received: from bar5.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id 40A73420320 for ; Wed, 30 Mar 2016 15:12:28 -0600 (MDT) X-ASG-Debug-ID: 1459372346-09eadd5b7e4b8f0001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar5.cudamail.com with ESMTP id ZrPd5kwPS9NUn4Ze (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 30 Mar 2016 15:12:27 -0600 (MDT) X-Barracuda-Envelope-From: cascardo@redhat.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx1-pf2.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 30 Mar 2016 21:12:26 -0000 Received-SPF: pass (mx1-pf2.cudamail.com: SPF record at _spf1.redhat.com designates 209.132.183.28 as permitted sender) X-Barracuda-Apparent-Source-IP: 209.132.183.28 X-Barracuda-RBL-IP: 209.132.183.28 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id C85D2D6482; Wed, 30 Mar 2016 21:12:25 +0000 (UTC) Received: from indiana.gru.redhat.com (ovpn-113-95.phx2.redhat.com [10.3.113.95]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2ULCOvP001978; Wed, 30 Mar 2016 17:12:24 -0400 X-CudaMail-Envelope-Sender: cascardo@redhat.com From: Thadeu Lima de Souza Cascardo To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-E2-329079733 X-CudaMail-DTE: 033016 X-CudaMail-Originating-IP: 209.132.183.28 Date: Wed, 30 Mar 2016 18:12:17 -0300 X-ASG-Orig-Subj: [##CM-E2-329079733##][PATCH] netdev: verify ifa_addr is not NULL when iterating over getifaddrs Message-Id: <1459372337-21102-1-git-send-email-cascardo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 30 Mar 2016 21:12:25 +0000 (UTC) X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1459372347 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Subject: [ovs-dev] [PATCH] netdev: verify ifa_addr is not NULL when iterating over getifaddrs X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" Some point-to-point devices like TUN devices will not have an address, and while iterating over ifaddrs, its ifa_addr will be NULL. This patch fixes a crash when starting ovs-vswitchd on a system with such a device. Signed-off-by: Thadeu Lima de Souza Cascardo Fixes: a8704b502785 ("tunneling: Handle multiple ip address for given device.") Cc: Pravin B Shelar --- lib/netdev.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/netdev.c b/lib/netdev.c index 95fdbc7..928f46f 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -1882,12 +1882,14 @@ netdev_get_addrs(const char dev[], struct in6_addr **paddr, } for (ifa = if_addr_list; ifa; ifa = ifa->ifa_next) { - int family; + if (ifa->ifa_addr != NULL) { + int family; - family = ifa->ifa_addr->sa_family; - if (family == AF_INET || family == AF_INET6) { - if (!strncmp(ifa->ifa_name, dev, IFNAMSIZ)) { - cnt++; + family = ifa->ifa_addr->sa_family; + if (family == AF_INET || family == AF_INET6) { + if (!strncmp(ifa->ifa_name, dev, IFNAMSIZ)) { + cnt++; + } } } } @@ -1901,7 +1903,7 @@ netdev_get_addrs(const char dev[], struct in6_addr **paddr, for (ifa = if_addr_list; ifa; ifa = ifa->ifa_next) { int family; - if (strncmp(ifa->ifa_name, dev, IFNAMSIZ)) { + if (strncmp(ifa->ifa_name, dev, IFNAMSIZ) || ifa->ifa_addr == NULL) { continue; }