[ofw] [PATCH] libibverbs/tests: fix buffer overrun issue that caused random connection failures

Sean Hefty sean.hefty at intel.com
Fri Jul 25 13:23:14 PDT 2008


I committed the following SVN patch to SVN to fix random failures running
libibverbs tests:

libibverbs tests occasionally had failures connecting over sockets in order to
exchange QP information.  (The ping-pong tests failed more than the perftests.)
The failure was caused by copying a port number into a buffer that was too
small, then using it to look up an address.  Increase the size of the buffer and
make sure that it's NULL terminated.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
Index: tests/perftest/read_bw/read_bw.c
===================================================================
--- tests/perftest/read_bw/read_bw.c	(revision 1446)
+++ tests/perftest/read_bw/read_bw.c	(working copy)
@@ -109,14 +109,14 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	int n;
 	SOCKET sockfd = INVALID_SOCKET;
 
 	memset(&hints, 0, sizeof hints);
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(servername, service, &hints, &res);
 
@@ -188,7 +188,7 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	SOCKET sockfd = INVALID_SOCKET, connfd;
 	int n;
 
@@ -196,7 +196,7 @@
 	hints.ai_flags    = AI_PASSIVE;
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(NULL, service, &hints, &res);
 
Index: tests/perftest/read_lat/read_lat.c
===================================================================
--- tests/perftest/read_lat/read_lat.c	(revision 1446)
+++ tests/perftest/read_lat/read_lat.c	(working copy)
@@ -184,14 +184,14 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	int n;
 	SOCKET sockfd = INVALID_SOCKET;
 
 	memset(&hints, 0, sizeof hints);
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(servername, service, &hints, &res);
 
@@ -232,7 +232,7 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	SOCKET sockfd = INVALID_SOCKET, connfd;
 	int n;
 
@@ -240,7 +240,7 @@
 	hints.ai_flags    = AI_PASSIVE;
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(NULL, service, &hints, &res);
 
Index: tests/perftest/send_bw/send_bw.c
===================================================================
--- tests/perftest/send_bw/send_bw.c	(revision 1446)
+++ tests/perftest/send_bw/send_bw.c	(working copy)
@@ -124,14 +124,14 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	int n;
 	SOCKET sockfd = INVALID_SOCKET;
 
 	memset(&hints, 0, sizeof hints);
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(servername, service, &hints, &res);
 
@@ -203,7 +203,7 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	SOCKET sockfd = INVALID_SOCKET, connfd;
 	int n;
 
@@ -211,7 +211,7 @@
 	hints.ai_flags    = AI_PASSIVE;
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(NULL, service, &hints, &res);
 
Index: tests/perftest/send_lat/send_lat.c
===================================================================
--- tests/perftest/send_lat/send_lat.c	(revision 1446)
+++ tests/perftest/send_lat/send_lat.c	(working copy)
@@ -195,14 +195,14 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	int n;
 	SOCKET sockfd = INVALID_SOCKET;
 
 	memset(&hints, 0, sizeof hints);
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(servername, service, &hints, &res);
 
@@ -243,7 +243,7 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	SOCKET sockfd = INVALID_SOCKET, connfd;
 	int n;
 
@@ -251,7 +251,7 @@
 	hints.ai_flags    = AI_PASSIVE;
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(NULL, service, &hints, &res);
 
Index: tests/perftest/write_bw/write_bw.c
===================================================================
--- tests/perftest/write_bw/write_bw.c	(revision 1446)
+++ tests/perftest/write_bw/write_bw.c	(working copy)
@@ -118,14 +118,14 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	int n;
 	SOCKET sockfd = INVALID_SOCKET;
 
 	memset(&hints, 0, sizeof hints);
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(servername, service, &hints, &res);
 
@@ -197,7 +197,7 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	SOCKET sockfd = INVALID_SOCKET, connfd;
 	int n;
 
@@ -205,7 +205,7 @@
 	hints.ai_flags    = AI_PASSIVE;
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(NULL, service, &hints, &res);
 
Index: tests/perftest/write_lat/write_lat.c
===================================================================
--- tests/perftest/write_lat/write_lat.c	(revision 1446)
+++ tests/perftest/write_lat/write_lat.c	(working copy)
@@ -181,14 +181,14 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	int n;
 	SOCKET sockfd = INVALID_SOCKET;
 
 	memset(&hints, 0, sizeof hints);
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(servername, service, &hints, &res);
 
@@ -229,7 +229,7 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	SOCKET sockfd = INVALID_SOCKET, connfd;
 	int n;
 
@@ -237,7 +237,7 @@
 	hints.ai_flags    = AI_PASSIVE;
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(NULL, service, &hints, &res);
 
Index: ulp/libibverbs/examples/rc_pingpong/rc_pingpong.c
===================================================================
--- ulp/libibverbs/examples/rc_pingpong/rc_pingpong.c	(revision 1446)
+++ ulp/libibverbs/examples/rc_pingpong/rc_pingpong.c	(working copy)
@@ -118,7 +118,7 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	char msg[sizeof "0000:000000:000000"];
 	int n;
 	SOCKET sockfd = INVALID_SOCKET;
@@ -127,7 +127,7 @@
 	memset(&hints, 0, sizeof hints);
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(servername, service, &hints, &res);
 
@@ -185,7 +185,7 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	char msg[sizeof "0000:000000:000000"];
 	int n;
 	SOCKET sockfd = INVALID_SOCKET, connfd;
@@ -195,7 +195,7 @@
 	hints.ai_flags    = AI_PASSIVE;
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(NULL, service, &hints, &res);
 
Index: ulp/libibverbs/examples/uc_pingpong/uc_pingpong.c
===================================================================
--- ulp/libibverbs/examples/uc_pingpong/uc_pingpong.c	(revision 1446)
+++ ulp/libibverbs/examples/uc_pingpong/uc_pingpong.c	(working copy)
@@ -105,7 +105,7 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	char msg[sizeof "0000:000000:000000"];
 	int n;
 	SOCKET sockfd = INVALID_SOCKET;
@@ -114,7 +114,7 @@
 	memset(&hints, 0, sizeof hints);
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(servername, service, &hints, &res);
 
@@ -172,7 +172,7 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	char msg[sizeof "0000:000000:000000"];
 	int n;
 	SOCKET sockfd = INVALID_SOCKET, connfd;
@@ -182,7 +182,7 @@
 	hints.ai_flags    = AI_PASSIVE;
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(NULL, service, &hints, &res);
 
Index: ulp/libibverbs/examples/ud_pingpong/ud_pingpong.c
===================================================================
--- ulp/libibverbs/examples/ud_pingpong/ud_pingpong.c	(revision 1446)
+++ ulp/libibverbs/examples/ud_pingpong/ud_pingpong.c	(working copy)
@@ -107,7 +107,7 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	char msg[sizeof "0000:000000:000000"];
 	int n;
 	SOCKET sockfd = INVALID_SOCKET;
@@ -116,7 +116,7 @@
 	memset(&hints, 0, sizeof hints);
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(servername, service, &hints, &res);
 
@@ -173,7 +173,7 @@
 {
 	struct addrinfo *res, *t;
 	struct addrinfo hints;
-	char service[4];
+	char service[6];
 	char msg[sizeof "0000:000000:000000"];
 	int n;
 	SOCKET sockfd = INVALID_SOCKET, connfd;
@@ -183,7 +183,7 @@
 	hints.ai_flags    = AI_PASSIVE;
 	hints.ai_family   = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	sprintf(service, "%d", port);
+	sprintf(service, "%d\0", port);
 
 	n = getaddrinfo(NULL, service, &hints, &res);
 





More information about the ofw mailing list