[maint] batman-adv: properly check pskb_may_pull return value

Message ID 1391037144-2448-1-git-send-email-antonio@meshcoding.com (mailing list archive)
State Accepted, archived
Commit eabdc3175b1d119cd673f36d06264cddb4803ace
Headers

Commit Message

Antonio Quartulli Jan. 29, 2014, 11:12 p.m. UTC
  pskb_may_pull() returns 1 on success and 0 in case of failure,
therefore checking for the return value being negative does
not make sense at all.

Fix this by doing the proper check.

Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>
---
 routing.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Antonio Quartulli Jan. 29, 2014, 11:15 p.m. UTC | #1
On 30/01/14 00:12, Antonio Quartulli wrote:
> pskb_may_pull() returns 1 on success and 0 in case of failure,
> therefore checking for the return value being negative does
> not make sense at all.
> 

I should have added:

This way if the function fails we will probably read beyond the current
skb data buffer.

> Fix this by doing the proper check.
> 
> Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>
  
Marek Lindner Feb. 2, 2014, 2:38 p.m. UTC | #2
On Thursday 30 January 2014 00:15:10 Antonio Quartulli wrote:
> On 30/01/14 00:12, Antonio Quartulli wrote:
> > pskb_may_pull() returns 1 on success and 0 in case of failure,
> > therefore checking for the return value being negative does
> > not make sense at all.
> >
> > 
> 
> I should have added:
> 
> This way if the function fails we will probably read beyond the current
> skb data buffer.

Applied in revision eabdc31.

Thanks,
Marek
  

Patch

diff --git a/routing.c b/routing.c
index f28920f..f7579d0 100644
--- a/routing.c
+++ b/routing.c
@@ -833,7 +833,7 @@  static int batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,
 	int is_old_ttvn;
 
 	/* check if there is enough data before accessing it */
-	if (pskb_may_pull(skb, hdr_len + ETH_HLEN) < 0)
+	if (!pskb_may_pull(skb, hdr_len + ETH_HLEN))
 		return 0;
 
 	/* create a copy of the skb (in case of for re-routing) to modify it. */