Skip to contentSkip to conversation

: Don't dereference error pointer dst1

PATCH In review Roel Kluin 3 participants 3 messages Sep 29, 2010

Subsystems (3)
lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 : Don't dereference error pointer dst1

Don't dereference dst1 when it's an error pointer.

---
 net/xfrm/xfrm_policy.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

I just noticed this by code analysis. It wasn't tested in any way.

net/xfrm/xfrm_policy.c +2 -1
index cbab6e1..b186c3d 100644
@@ -1414,13 +1414,14 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
 
 	for (; i < nx; i++) {
 		struct xfrm_dst *xdst = xfrm_alloc_dst(net, family);
-		struct dst_entry *dst1 = &xdst->u.dst;
+		struct dst_entry *dst1;
 
 		err = PTR_ERR(xdst);
 		if (IS_ERR(xdst)) {
 			dst_release(dst);
 			goto put_states;
 		}
+		dst1 = &xdst->u.dst;
 
 		if (!dst_prev)
 			dst0 = dst1;
#1 lore raw
Quoted 20 lines · Roel Kluin

Don't dereference dst1 when it's an error pointer.

---
 net/xfrm/xfrm_policy.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

I just noticed this by code analysis. It wasn't tested in any way.

net/xfrm/xfrm_policy.c +1 -1
index cbab6e1..b186c3d 100644
@@ -1414,13 +1414,14 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
 
 	for (; i < nx; i++) {
 		struct xfrm_dst *xdst = xfrm_alloc_dst(net, family);
-		struct dst_entry *dst1 = &xdst->u.dst;
+		struct dst_entry *dst1;

net/xfrm/xfrm_policy.c static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy, · line 1427

Quoted 10 lines
net/xfrm/xfrm_policy.c +1 -0
 
 		err = PTR_ERR(xdst);
 		if (IS_ERR(xdst)) {
 			dst_release(dst);
 			goto put_states;
 		}
+		dst1 = &xdst->u.dst;
 
 		if (!dst_prev)
 			dst0 = dst1;

This is not a dereference, but a cast from "struct xfrm_dst *" to "struct dst_entry *"

maintainer
#2 lore raw

From: Eric Dumazet <[email protected]>
Date: Wed, 29 Sep 2010 22:45:13 +0200

Quoted 2 lines

This is not a dereference, but a cast from "struct xfrm_dst *" to "struct dst_entry *"

Right, please teach whatever tool caught this that taking an address of a member of an object referenced by pointer is not an error like a true dereference is.