summaryrefslogtreecommitdiff
path: root/libopeniscsiusr
diff options
context:
space:
mode:
Diffstat (limited to 'libopeniscsiusr')
-rw-r--r--libopeniscsiusr/sysfs.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/libopeniscsiusr/sysfs.c b/libopeniscsiusr/sysfs.c
index 70298f2..6f590f4 100644
--- a/libopeniscsiusr/sysfs.c
+++ b/libopeniscsiusr/sysfs.c
@@ -311,6 +311,9 @@ int _iscsi_host_id_of_session(struct iscsi_context *ctx, uint32_t sid,
int n = 0;
const char *host_id_str = NULL;
int i = 0;
+ const char iscsi_host_dir_str[] = "/iscsi_host/";
+ const unsigned int iscsi_host_dir_strlen = strlen(iscsi_host_dir_str);
+
assert(ctx != NULL);
assert(sid != 0);
@@ -323,8 +326,16 @@ int _iscsi_host_id_of_session(struct iscsi_context *ctx, uint32_t sid,
_good(sysfs_get_dev_path(ctx, sys_se_dir_path, sys_dev_path), rc, out);
- snprintf(sys_scsi_host_dir_path, PATH_MAX, "%s/iscsi_host/",
- sys_dev_path);
+ if ((strlen(sys_dev_path) + iscsi_host_dir_strlen) >= PATH_MAX) {
+ rc = LIBISCSI_ERR_SYSFS_LOOKUP;
+ _error(ctx, "Pathname too long: %s%s",
+ sys_dev_path, iscsi_host_dir_str);
+ goto out;
+ }
+
+ strncpy(sys_scsi_host_dir_path, sys_dev_path, PATH_MAX);
+ strncat(sys_scsi_host_dir_path, iscsi_host_dir_str,
+ PATH_MAX - iscsi_host_dir_strlen);
n = scandir(sys_scsi_host_dir_path, &namelist, _scan_filter_skip_dot,
alphasort);