Skip to contentSkip to conversation

infiniband-diags: ibstat fix strncpy coverity check and -l bug

PATCH In review Ira Weiny 2 participants 3 messages Jun 13, 2013 2 messages not in the archive InfiniBand

lore
Share & tools
lore

Ira Weiny

author
#0 lore raw

PATCH 1/1 infiniband-diags: ibstat fix strncpy coverity check and -l bug

---
 src/ibstat.c |    9 ++-------
 1 files changed, 2 insertions(+), 7 deletions(-)
src/ibstat.c +2 -7
index 665bb0a..1ef27f2 100644
@@ -314,7 +314,8 @@ int main(int argc, char *argv[])
 		if (i >= n)
 			IBPANIC("'%s' IB device can't be found", argv[0]);
 
-		strncpy(names[i], argv[0], sizeof names[i]);
+		strncpy(names[0], argv[0], sizeof(names[0])-1);
+		names[0][sizeof(names[0])-1] = '\0';
 		n = 1;
 	}
 
@@ -324,12 +325,6 @@ int main(int argc, char *argv[])
 		return 0;
 	}
 
-	if (!list_only && argc) {
-		if (ca_stat(argv[0], dev_port, short_format) < 0)
-			IBPANIC("stat of IB device '%s' failed", argv[0]);
-		return 0;
-	}
-
 	for (i = 0; i < n; i++) {
 		if (list_only)
 			printf("%s\n", names[i]);
Signature · 6 lines
1.7.1

--
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
#2 lore raw
In reply to a message not in the archive

On 6/12/2013 8:03 PM, Ira Weiny wrote:

This seems like 2 different patches to me.

Quoted 20 lines
---
 src/ibstat.c |    9 ++-------
 1 files changed, 2 insertions(+), 7 deletions(-)
src/ibstat.c +2 -1
index 665bb0a..1ef27f2 100644
@@ -314,7 +314,8 @@ int main(int argc, char *argv[])
 		if (i >= n)
 			IBPANIC("'%s' IB device can't be found", argv[0]);
 
-		strncpy(names[i], argv[0], sizeof names[i]);
+		strncpy(names[0], argv[0], sizeof(names[0])-1);
+		names[0][sizeof(names[0])-1] = '\0';
 		n = 1;
 	}
 

src/ibstat.c int main(int argc, char *argv[]) · line 327

Quoted 4 lines
src/ibstat.c +0 -1
@@ -324,12 +325,6 @@ int main(int argc, char *argv[])
 		return 0;
 	}
 
-	if (!list_only && argc) {

I think I see the issue. Rather than eliminate this if clause, I think the line above should be:

	if (!list_only && argc > 1) {

so that this properly handles the case when the port option is supplied.

-- Hal

src/ibstat.c int main(int argc, char *argv[]) · line 330

Quoted 8 lines
src/ibstat.c +0 -5
-		if (ca_stat(argv[0], dev_port, short_format) < 0)
-			IBPANIC("stat of IB device '%s' failed", argv[0]);
-		return 0;
-	}
-
 	for (i = 0; i < n; i++) {
 		if (list_only)
 			printf("%s\n", names[i]);

--
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

author
#4 lore raw
In reply to a message not in the archive
Quoted 3 lines · On Wed, 12 Jun 2013 21:38:58 -0400 Hal Rosenstock…

On 6/12/2013 8:03 PM, Ira Weiny wrote:

This seems like 2 different patches to me.

Not really...

Quoted 10 lines
Quoted 10 lines
---
 src/ibstat.c |    9 ++-------
 1 files changed, 2 insertions(+), 7 deletions(-)
src/ibstat.c +0 -0
@@ -324,12 +325,6 @@ int main(int argc, char *argv[])
 		return 0;
 	}
 
Quoted 8 lines

src/ibstat.c int main(int argc, char *argv[]) · line 327

Quoted 1 line
src/ibstat.c +0 -1
-	if (!list_only && argc) {

I think I see the issue. Rather than eliminate this if clause, I think the line above should be:

	if (!list_only && argc > 1) {

so that this properly handles the case when the port option is supplied.

V2 on the way. I think we should still get rid of that if clause but your right I broke the "port" parameter.

Ira

Quoted 12 lines

-- Hal

Quoted 8 lines
src/ibstat.c +0 -5
-		if (ca_stat(argv[0], dev_port, short_format) < 0)
-			IBPANIC("stat of IB device '%s' failed", argv[0]);
-		return 0;
-	}
-
 	for (i = 0; i < n; i++) {
 		if (list_only)
 			printf("%s\n", names[i]);
Signature · 5 lines
Ira Weiny <[email protected]>
--
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