[PATCH] fix tid testing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



return error if tid is not a postive integer

Signed-off-by: Doron Shoham <dorons@xxxxxxxxxxxx>
---
 usr/tgtadm.c |   26 ++++++++++++++++++++------
 1 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/usr/tgtadm.c b/usr/tgtadm.c
index 23dbc53..1102312 100644
--- a/usr/tgtadm.c
+++ b/usr/tgtadm.c
@@ -385,6 +385,7 @@ int main(int argc, char **argv)
 	char *bstype;
 	char *user, *password;
 	char *buf;
+	char *endptr;
 	struct tgtadm_req *req;
 
 	op = tid = mode = -1;
@@ -416,9 +417,22 @@ int main(int argc, char **argv)
 			mode = str_to_mode(optarg);
 			break;
 		case 't':
-			tid = strtol(optarg, NULL, 10);
-			if (errno == EINVAL) {
+			tid = strtol(optarg, &endptr, 10);
+			if ((errno == ERANGE) || (errno != 0 && tid == 0)) {
 				eprintf("invalid tid '%s'\n", optarg);
+				eprintf("'tid' must be a positive integer\n");
+				exit(EINVAL);
+			}
+
+			if (endptr == optarg) {
+				eprintf("invalid tid '%s'\n", optarg);
+				eprintf("'tid' must be a positive integer\n");
+				exit(EINVAL);
+			}
+
+			if (tid < 0) {
+				eprintf("invalid tid '%s'\n", optarg);
+				eprintf("'tid' must be a positive integer\n");
 				exit(EINVAL);
 			}
 			break;
@@ -507,7 +521,7 @@ int main(int argc, char **argv)
 	}
 
 	if (mode == MODE_TARGET) {
-		if ((tid <= 0 && (op != OP_SHOW))) {
+		if ((tid < 0 && (op != OP_SHOW))) {
 			eprintf("'tid' option is necessary\n");
 			exit(EINVAL);
 		}
@@ -608,7 +622,7 @@ int main(int argc, char **argv)
 				eprintf("'user' option is necessary\n");
 				exit(EINVAL);
 			}
-			if (tid <= 0) {
+			if (tid < 0) {
 				eprintf("'tid' option is necessary\n");
 				exit(EINVAL);
 			}
@@ -624,7 +638,7 @@ int main(int argc, char **argv)
 				eprintf("'user' option is necessary\n");
 				exit(EINVAL);
 			}
-			if (tid <= 0) {
+			if (tid < 0) {
 				eprintf("'tid' option is necessary\n");
 				exit(EINVAL);
 			}
@@ -637,7 +651,7 @@ int main(int argc, char **argv)
 	}
 
 	if (mode == MODE_DEVICE) {
-		if (tid <= 0) {
+		if (tid < 0) {
 			eprintf("'tid' option is necessary\n");
 			exit(EINVAL);
 		}
-- 
1.5.3.8

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux