batman-adv: check batadv_orig_hash_add_if() return code
authorSimon Wunderlich <simon.wunderlich@s2003.tu-chemnitz.de>
Sun, 1 Jul 2012 20:51:55 +0000 (22:51 +0200)
committerAntonio Quartulli <ordex@autistici.org>
Thu, 23 Aug 2012 12:02:46 +0000 (14:02 +0200)
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 <siwu@hrz.tu-chemnitz.de>
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
net/batman-adv/hard-interface.c

index 282bf6e9353e6ad5ab657e0c2722ec9635701f7c..2c5a247a8f12177c927bb8efaf536fa9044801fd 100644 (file)
@@ -313,7 +313,13 @@ 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--;
+               hard_iface->if_status = BATADV_IF_NOT_IN_USE;
+               goto err_dev;
+       }
 
        hard_iface->batman_adv_ptype.type = ethertype;
        hard_iface->batman_adv_ptype.func = batadv_batman_skb_recv;