From patchwork Sun Jul 1 20:51:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Wunderlich X-Patchwork-Id: 2167 Return-Path: Received: from nick.hrz.tu-chemnitz.de (nick.hrz.tu-chemnitz.de [134.109.228.11]) by open-mesh.org (Postfix) with ESMTPS id 4F47C6008A5 for ; Sun, 1 Jul 2012 22:51:43 +0200 (CEST) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key; insecure key) header.i=@tu-chemnitz.de; dkim-adsp=none (insecure policy) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tu-chemnitz.de; s=dkim2010; h=Message-Id:Date:Subject:Cc:To:From; bh=nwJ7YuWbqsQ8akbc9pp5TY2YK29Y5+gEvzRYXG/jV7c=; b=g3knZ57DyJGixabkhFtYKPX8yz/brqlhDYur/kw/98/6Ojb9DKcNWRdcB9dduTwTeT2fjGUyfAkFU9m7VjT2xORbRrzoDSRVqQqkZ9rY5PAAmZCQ5LPwXrxVdFT/+dfsTBZVJe1WAEwsfgDSuqYiJYYlJDgYHJL7/F4y6P9z6T4=; Received: from p57aa0252.dip0.t-ipconnect.de ([87.170.2.82] helo=pandem0nium) by nick.hrz.tu-chemnitz.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1SlR7O-0002NK-L4; Sun, 01 Jul 2012 22:51:42 +0200 Received: from dotslash by pandem0nium with local (Exim 4.72) (envelope-from ) id 1SlR7h-0006zh-LA; Sun, 01 Jul 2012 22:52:01 +0200 From: Simon Wunderlich To: b.a.t.m.a.n@lists.open-mesh.org Date: Sun, 1 Jul 2012 22:51:55 +0200 Message-Id: <1341175915-26856-1-git-send-email-siwu@hrz.tu-chemnitz.de> X-Mailer: git-send-email 1.7.2.5 X-Scan-AV: nick.hrz.tu-chemnitz.de; 2012-07-01 22:51:42; 956bdaabc59abe3ace4e1f88d8444d75 X-Scan-SA: nick.hrz.tu-chemnitz.de; 2012-07-01 22:51:42; 49adc2d337b7d644d7169c0036cf2425 X-Spam-Score: -1.0 (-) X-Spam-Report: --- Textanalyse SpamAssassin 3.3.1 (-1.0 Punkte) Fragen an/questions to: Postmaster TU Chemnitz * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP --- Ende Textanalyse Cc: Simon Wunderlich Subject: [B.A.T.M.A.N.] [PATCH] batman-adv: check batadv_orig_hash_add_if() return code X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Jul 2012 20:51:43 -0000 If this call fails, some of the orig_nodes spaces may have been resized for the increased number of interface, and some may not. If we would just continue with the larger number of interfaces, this would lead to access to not allocated memory later. We better check the return code, and don't add the interface if no memory is available. OTOH, keeping some of the orig_nodes with too much memory allocated should hurt no one (except for a few too many bytes allocated). Signed-off-by: Simon Wunderlich --- hard-interface.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hard-interface.c b/hard-interface.c index 282bf6e..2d7f4f2 100644 --- a/hard-interface.c +++ b/hard-interface.c @@ -313,7 +313,12 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, hard_iface->if_num = bat_priv->num_ifaces; bat_priv->num_ifaces++; hard_iface->if_status = BATADV_IF_INACTIVE; - batadv_orig_hash_add_if(hard_iface, bat_priv->num_ifaces); + ret = batadv_orig_hash_add_if(hard_iface, bat_priv->num_ifaces); + if (ret < 0) { + bat_priv->bat_algo_ops->bat_iface_disable(hard_iface); + bat_priv->num_ifaces--; + goto err_dev; + } hard_iface->batman_adv_ptype.type = ethertype; hard_iface->batman_adv_ptype.func = batadv_batman_skb_recv;