[maint] batman-adv: avoid NULL dereferences and clarify if check

Message ID 1410937316-23199-1-git-send-email-antonio@meshcoding.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Antonio Quartulli Sept. 17, 2014, 7:01 a.m. UTC
  Due to a typ0 in an if-condition used in the gateway-client
code it is possible to run in a NULL pointer dereference.

At the same type the same if-condition is not clear.

Fix this by rewriting the if-condition properly.

Introduced by 0853ec7fafe0a195754454832993c6b35e22b842
("batman-adv: tvlv - gateway download/upload bandwidth container")

Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>
Reported-by: David Binderman <dcb314@hotmail.com>
---
 gateway_client.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Antonio Quartulli Sept. 20, 2014, 4:17 p.m. UTC | #1
Hi all,

On 17/09/14 09:01, Antonio Quartulli wrote:
>  	gw_node = batadv_gw_node_get(bat_priv, orig_dst_node);
> -	if (!gw_node->bandwidth_down == 0)
> +	if (!gw_node || (gw_node->bandwidth_down == 0))

This is not the right way to fix this condition. A new patch is coming.

Cheers,
  

Patch

diff --git a/gateway_client.c b/gateway_client.c
index bcc3e0c..5f09536 100644
--- a/gateway_client.c
+++ b/gateway_client.c
@@ -811,7 +811,7 @@  bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
 		goto out;
 
 	gw_node = batadv_gw_node_get(bat_priv, orig_dst_node);
-	if (!gw_node->bandwidth_down == 0)
+	if (!gw_node || (gw_node->bandwidth_down == 0))
 		goto out;
 
 	switch (atomic_read(&bat_priv->gw_mode)) {