Skip to contentSkip to conversation

ipv6: move dereference after check in fl_free()

PATCH Applied Dan Carpenter 2 participants 2 messages Aug 16, 2012

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipv6: move dereference after check in fl_free()

There is a dereference before checking for NULL bug here. Generally free() functions should accept NULL pointers. For example, fl_create() can pass a NULL pointer to fl_free() on the error path.

---
Only needed on linux-next.

net/ipv6/ip6_flowlabel.c +2 -5
index c836a6a..90bbefb 100644
@@ -91,12 +91,9 @@ static struct ip6_flowlabel *fl_lookup(struct net *net, __be32 label)
 
 static void fl_free(struct ip6_flowlabel *fl)
 {
-	switch (fl->share) {
-	case IPV6_FL_S_PROCESS:
-		put_pid(fl->owner.pid);
-		break;
-	}
 	if (fl) {
+		if (fl->share = IPV6_FL_S_PROCESS)
+			put_pid(fl->owner.pid);
 		release_net(fl->fl_net);
 		kfree(fl->opt);
 	}
#1 lore raw
Quoted 3 lines · Dan Carpenter

There is a dereference before checking for NULL bug here. Generally free() functions should accept NULL pointers. For example, fl_create() can pass a NULL pointer to fl_free() on the error path.

Thanks.

Applied to user-namespace.git

Eric

Quoted 24 lines

---
Only needed on linux-next.

net/ipv6/ip6_flowlabel.c +2 -5
index c836a6a..90bbefb 100644
@@ -91,12 +91,9 @@ static struct ip6_flowlabel *fl_lookup(struct net *net, __be32 label)
 
 static void fl_free(struct ip6_flowlabel *fl)
 {
-	switch (fl->share) {
-	case IPV6_FL_S_PROCESS:
-		put_pid(fl->owner.pid);
-		break;
-	}
 	if (fl) {
+		if (fl->share = IPV6_FL_S_PROCESS)
+			put_pid(fl->owner.pid);
 		release_net(fl->fl_net);
 		kfree(fl->opt);
 	}