From patchwork Fri Nov 30 07:00:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Yang X-Patchwork-Id: 17666 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id 6D3F680956; Fri, 30 Nov 2018 08:28:32 +0100 (CET) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=63.217.80.70; helo=mxhk.zte.com.cn; envelope-from=wen.yang99@zte.com.cn; receiver= X-Greylist: delayed 950 seconds by postgrey-1.36 at open-mesh.org; Fri, 30 Nov 2018 08:13:23 CET Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.217.80.70]) by open-mesh.org (Postfix) with ESMTPS id B42368053D for ; Fri, 30 Nov 2018 08:13:23 +0100 (CET) Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 31C33D718A6C74EAF65A; Fri, 30 Nov 2018 14:57:30 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id wAU6vKDZ086462; Fri, 30 Nov 2018 14:57:20 +0800 (GMT-8) (envelope-from wen.yang99@zte.com.cn) Received: from localhost.localdomain ([10.75.9.60]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2018113014575815-13904801 ; Fri, 30 Nov 2018 14:57:58 +0800 From: Wen Yang To: mareklindner@neomailbox.ch, sw@simonwunderlich.de, a@unstable.cc, davem@davemloft.net Date: Fri, 30 Nov 2018 15:00:02 +0800 Message-Id: <1543561202-614-1-git-send-email-wen.yang99@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2018-11-30 14:57:58, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-11-30 14:57:04, Serialize complete at 2018-11-30 14:57:04 X-MAIL: mse01.zte.com.cn wAU6vKDZ086462 X-Mailman-Approved-At: Fri, 30 Nov 2018 08:28:31 +0100 Subject: [B.A.T.M.A.N.] [PATCH] batman-adv: fix null pointer dereference in batadv_gw_election X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, zhong.weidong@zte.com.cn, linux-kernel@vger.kernel.org, wen.yang99@zte.com.cn Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" This patch fixes a possible null pointer dereference in batadv_gw_election, detected by the semantic patch deref_null.cocci, with the following warning: ./net/batman-adv/gateway_client.c:289:15-24: ERROR: next_gw is NULL but dereferenced. ./net/batman-adv/gateway_client.c:290:15-29: ERROR: next_gw is NULL but dereferenced. ./net/batman-adv/gateway_client.c:291:15-29: ERROR: next_gw is NULL but dereferenced. ./net/batman-adv/gateway_client.c:292:15-27: ERROR: next_gw is NULL but dereferenced. ./net/batman-adv/gateway_client.c:293:15-27: ERROR: next_gw is NULL but dereferenced. Signed-off-by: Wen Yang Reviewed-by: Tan Hu --- net/batman-adv/gateway_client.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c index 140c61a..d80ef1c 100644 --- a/net/batman-adv/gateway_client.c +++ b/net/batman-adv/gateway_client.c @@ -284,14 +284,16 @@ void batadv_gw_election(struct batadv_priv *bat_priv) batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_ADD, gw_addr); } else { - batadv_dbg(BATADV_DBG_BATMAN, bat_priv, - "Changing route to gateway %pM (bandwidth: %u.%u/%u.%u MBit, tq: %i)\n", - next_gw->orig_node->orig, - next_gw->bandwidth_down / 10, - next_gw->bandwidth_down % 10, - next_gw->bandwidth_up / 10, - next_gw->bandwidth_up % 10, - router_ifinfo->bat_iv.tq_avg); + if (next_gw) { + batadv_dbg(BATADV_DBG_BATMAN, bat_priv, + "Changing route to gateway %pM (bandwidth: %u.%u/%u.%u MBit, tq: %i)\n", + next_gw->orig_node->orig, + next_gw->bandwidth_down / 10, + next_gw->bandwidth_down % 10, + next_gw->bandwidth_up / 10, + next_gw->bandwidth_up % 10, + router_ifinfo->bat_iv.tq_avg); + } batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_CHANGE, gw_addr); }