diff mbox

Further timeout paramater verification (Was: [PATCH] infiniband-diags: Verify timeout value specified to diagnostics)

Message ID 20101222114707.c6ec051f.weiny2@llnl.gov (mailing list archive)
State Not Applicable
Headers show

Commit Message

Ira Weiny Dec. 22, 2010, 7:47 p.m. UTC
None
diff mbox

Patch

diff --git a/infiniband-diags/src/ibdiag_common.c b/infiniband-diags/src/ibdiag_common.c
index 8ccf2fc..8f5eec3 100644
--- a/infiniband-diags/src/ibdiag_common.c
+++ b/infiniband-diags/src/ibdiag_common.c
@@ -138,7 +138,8 @@  void ibdiag_show_usage()
 
 static int process_opt(int ch, char *optarg)
 {
-	int val;
+	char *endp;
+	long val;
 
 	switch (ch) {
 	case 'h':
@@ -175,13 +176,16 @@  static int process_opt(int ch, char *optarg)
 		ibd_dest_type = IB_DEST_GUID;
 		break;
 	case 't':
-		val = (int)strtol(optarg, NULL, 0);
-		if (val > 0) {
-			madrpc_set_timeout(val);
-			ibd_timeout = val;
-		} else
+		errno = 0;
+		val = strtol(optarg, &endp, 0);
+		if (errno || (endp && *endp != '\0') || val <= 0 ||
+		    val > INT_MAX)
 			IBERROR("Invalid timeout \"%s\".  Timeout requires a "
-				"positive integer value.", optarg);
+				"positive integer value < %d.", optarg, INT_MAX);
+		else {
+			madrpc_set_timeout((int)val);
+			ibd_timeout = (int)val;
+		}
 		break;
 	case 's':
 		/* srcport is not required when resolving via IB_DEST_LID */