Skip to contentSkip to conversation

fix potential segfault in ibnd_node_t destroy path

PATCH Applied Al Chu 2 participants 2 messages Nov 6, 2009 – Nov 12, 2009 1 message not in the archive InfiniBand

lore
Share & tools
lore

Al Chu

author
#0 lore raw

PATCH 2/2 fix potential segfault in ibnd_node_t destroy path

Hey Sasha,

There is a potential for the ports array in ibnd_node_t to be NULL if you hit an error during scan and eventually destroy the fabric struct before returning to the user.

Al

Signature · 5 lines
Albert Chu
[email protected]
Computer Scientist
High Performance Systems Division
Lawrence Livermore National Laboratory

From: Albert Chu <[email protected]>
Date: Thu, 5 Nov 2009 15:18:27 -0800
Subject: [PATCH] fix potential segfault in ibnd_node_t destroy path

---
 infiniband-diags/libibnetdisc/src/ibnetdisc.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
infiniband-diags/libibnetdisc/src/ibnetdisc.c +5 -3
index 62dff93..7ce9a54 100644
@@ -605,10 +605,12 @@ static void destroy_node(ibnd_node_t * node)
 {
 	int p = 0;
 
-	for (p = 0; p <= node->numports; p++) {
-		free(node->ports[p]);
+	if (node->ports) {
+		for (p = 0; p <= node->numports; p++) {
+			free(node->ports[p]);
+		}
+		free(node->ports);
 	}
-	free(node->ports);
 	free(node);
 }
 
Signature · 1 line
1.5.4.5

A message that is not in the archive (sent off-list or not yet received): 1257531264.18550.70.camel-X2zTWyBD0EhliZ7u+bvwcg@public.gmane.org

#2 lore raw
Quoted 21 lines · Al Chu

Hey Sasha,

There is a potential for the ports array in ibnd_node_t to be NULL if you hit an error during scan and eventually destroy the fabric struct before returning to the user.

Al

Signature · 12 lines
Albert Chu
[email protected]
Computer Scientist
High Performance Systems Division
Lawrence Livermore National Laboratory

From: Albert Chu <[email protected]>
Date: Thu, 5 Nov 2009 15:18:27 -0800
Subject: [PATCH] fix potential segfault in ibnd_node_t destroy path


Signed-off-by: Albert Chu <[email protected]>

Applied with minor change (see below). Thanks.

Quoted 9 lines
---
 infiniband-diags/libibnetdisc/src/ibnetdisc.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
infiniband-diags/libibnetdisc/src/ibnetdisc.c +0 -0
index 62dff93..7ce9a54 100644

infiniband-diags/libibnetdisc/src/ibnetdisc.c static void destroy_node(ibnd_node_t * node) · line 611

Quoted 9 lines
infiniband-diags/libibnetdisc/src/ibnetdisc.c +4 -2
@@ -605,10 +605,12 @@ static void destroy_node(ibnd_node_t * node)
 {
 	int p = 0;
 
-	for (p = 0; p <= node->numports; p++) {
-		free(node->ports[p]);
+	if (node->ports) {
+		for (p = 0; p <= node->numports; p++) {
+			free(node->ports[p]);
+		}

Removing here unneeded braces around free().

Sasha

Quoted 9 lines
infiniband-diags/libibnetdisc/src/ibnetdisc.c +1 -1
+		free(node->ports);
 	}
-	free(node->ports);
 	free(node);
 }
 
Signature · 1 line
1.5.4.5

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html