[Pkg-iscsi-maintainers] [open-iscsi] 05/33: iscsi tools: Convert '-r' argument to an integer before checking if it is a path

Ritesh Raj Sarraf rrs at alioth.debian.org
Tue Nov 5 16:21:10 UTC 2013


This is an automated email from the git hooks/post-receive script.

rrs pushed a commit to branch upstream-mnc
in repository open-iscsi.

commit 9dd181dcb1ca299cd82075b8e598fc57d87ee1c0
Author: Jim Ramsay <jim_ramsay at dell.com>
Date:   Wed Oct 3 09:57:43 2012 -0400

    iscsi tools: Convert '-r' argument to an integer before checking if it is a path
    
    If there is a file in the CWD named '1' and you were trying to run
    'iscsiadm -m session -r 1 ...', the command would fail with "1 is not a
    directory".
    
    Root cause: The code that parses the -r option's argument tries lstat(2)
    first, falling back to atoi(3) only if lstat fails.
    
    This change inverts the order of checks, first with strtol(3) to see if
    the argument given is a positive integer, then falling back to lstat(2)
    only if it is not.
    
    Signed-off-by: Jim Ramsay <jim_ramsay at dell.com>
---
 usr/iscsi_sysfs.c |   17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/usr/iscsi_sysfs.c b/usr/iscsi_sysfs.c
index 123dde3..4015b35 100644
--- a/usr/iscsi_sysfs.c
+++ b/usr/iscsi_sysfs.c
@@ -740,7 +740,7 @@ int iscsi_sysfs_session_has_leadconn(uint32_t sid)
  * /sys/devices/platform/hostH/sessionS/targetH:B:I
  * /sys/devices/platform/hostH/sessionS
  *
- * return the sid S. If just the sid is passed in it will be covnerted
+ * return the sid S. If just the sid is passed in it will be converted
  * to a int.
  */
 int iscsi_sysfs_get_sid_from_path(char *session)
@@ -748,15 +748,16 @@ int iscsi_sysfs_get_sid_from_path(char *session)
 	struct sysfs_device *dev_parent, *dev;
 	struct stat statb;
 	char devpath[PATH_SIZE];
+	char *end;
+	int sid;
+
+	sid = strtol(session, &end, 10);
+	if (sid > 0 && *session != '\0' && *end == '\0')
+		return sid;
 
 	if (lstat(session, &statb)) {
-		log_debug(1, "Could not stat %s failed with %d",
-			  session, errno);
-		if (index(session, '/')) {
-			log_error("%s is an invalid session path\n", session);
-			exit(1);
-		}
-		return atoi(session);
+		log_error("%s is an invalid session ID or path\n", session);
+		exit(1);
 	}
 
 	if (!S_ISDIR(statb.st_mode) && !S_ISLNK(statb.st_mode)) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-iscsi/open-iscsi.git



More information about the Pkg-iscsi-maintainers mailing list