Blame SOURCES/0005-iscsi-tools-Convert-r-argument-to-an-integer-before-.patch

6c64be
From 9dd181dcb1ca299cd82075b8e598fc57d87ee1c0 Mon Sep 17 00:00:00 2001
6c64be
From: Jim Ramsay <jim_ramsay@dell.com>
6c64be
Date: Wed, 3 Oct 2012 09:57:43 -0400
6c64be
Subject: iscsi tools: Convert '-r' argument to an integer before checking if
6c64be
 it is a path
6c64be
6c64be
If there is a file in the CWD named '1' and you were trying to run
6c64be
'iscsiadm -m session -r 1 ...', the command would fail with "1 is not a
6c64be
directory".
6c64be
6c64be
Root cause: The code that parses the -r option's argument tries lstat(2)
6c64be
first, falling back to atoi(3) only if lstat fails.
6c64be
6c64be
This change inverts the order of checks, first with strtol(3) to see if
6c64be
the argument given is a positive integer, then falling back to lstat(2)
6c64be
only if it is not.
6c64be
6c64be
Signed-off-by: Jim Ramsay <jim_ramsay@dell.com>
6c64be
---
6c64be
 usr/iscsi_sysfs.c | 17 +++++++++--------
6c64be
 1 file changed, 9 insertions(+), 8 deletions(-)
6c64be
6c64be
diff --git a/usr/iscsi_sysfs.c b/usr/iscsi_sysfs.c
6c64be
index 123dde3..4015b35 100644
6c64be
--- a/usr/iscsi_sysfs.c
6c64be
+++ b/usr/iscsi_sysfs.c
6c64be
@@ -740,7 +740,7 @@ int iscsi_sysfs_session_has_leadconn(uint32_t sid)
6c64be
  * /sys/devices/platform/hostH/sessionS/targetH:B:I
6c64be
  * /sys/devices/platform/hostH/sessionS
6c64be
  *
6c64be
- * return the sid S. If just the sid is passed in it will be covnerted
6c64be
+ * return the sid S. If just the sid is passed in it will be converted
6c64be
  * to a int.
6c64be
  */
6c64be
 int iscsi_sysfs_get_sid_from_path(char *session)
6c64be
@@ -748,15 +748,16 @@ int iscsi_sysfs_get_sid_from_path(char *session)
6c64be
 	struct sysfs_device *dev_parent, *dev;
6c64be
 	struct stat statb;
6c64be
 	char devpath[PATH_SIZE];
6c64be
+	char *end;
6c64be
+	int sid;
6c64be
+
6c64be
+	sid = strtol(session, &end, 10);
6c64be
+	if (sid > 0 && *session != '\0' && *end == '\0')
6c64be
+		return sid;
6c64be
 
6c64be
 	if (lstat(session, &statb)) {
6c64be
-		log_debug(1, "Could not stat %s failed with %d",
6c64be
-			  session, errno);
6c64be
-		if (index(session, '/')) {
6c64be
-			log_error("%s is an invalid session path\n", session);
6c64be
-			exit(1);
6c64be
-		}
6c64be
-		return atoi(session);
6c64be
+		log_error("%s is an invalid session ID or path\n", session);
6c64be
+		exit(1);
6c64be
 	}
6c64be
 
6c64be
 	if (!S_ISDIR(statb.st_mode) && !S_ISLNK(statb.st_mode)) {
6c64be
-- 
6c64be
1.7.11.7
6c64be