Skip to contentSkip to conversation

target: handle empty string writes in sysfs

PATCH Superseded Dan Carpenter 2 participants 4 messages Jan 24, 2012 – Jan 27, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target: handle empty string writes in sysfs

These are root only and we're not likely to hit the problem in practise, but it makes a the static checkers happy.

drivers/target/target_core_configfs.c +4 -0
index 0955bb8..9b86330 100644
@@ -1707,6 +1707,8 @@ static ssize_t target_core_store_dev_alias(
 	se_dev->su_dev_flags |= SDF_USING_ALIAS;
 	read_bytes = snprintf(&se_dev->se_dev_alias[0], SE_DEV_ALIAS_LEN,
 			"%s", page);
+	if (read_bytes = 0)
+		return -EINVAL;
 
 	if (se_dev->se_dev_alias[read_bytes - 1] = '\n')
 		se_dev->se_dev_alias[read_bytes - 1] = '\0';
@@ -1756,6 +1758,8 @@ static ssize_t target_core_store_dev_udev_path(
 	se_dev->su_dev_flags |= SDF_USING_UDEV_PATH;
 	read_bytes = snprintf(&se_dev->se_dev_udev_path[0], SE_UDEV_PATH_LEN,
 			"%s", page);
+	if (read_bytes = 0)
+		return -EINVAL;
 
 	if (se_dev->se_dev_udev_path[read_bytes - 1] = '\n')
 		se_dev->se_dev_udev_path[read_bytes - 1] = '\0';
#1 lore raw

Am 24.01.2012 09:40, schrieb Dan Carpenter:

drivers/target/target_core_configfs.c static ssize_t target_core_store_dev_alias( · line 1709

Quoted 13 lines

These are root only and we're not likely to hit the problem in practise, but it makes a the static checkers happy.

drivers/target/target_core_configfs.c +0 -0
index 0955bb8..9b86330 100644
@@ -1707,6 +1707,8 @@ static ssize_t target_core_store_dev_alias(
 	se_dev->su_dev_flags |= SDF_USING_ALIAS;
 	read_bytes = snprintf(&se_dev->se_dev_alias[0], SE_DEV_ALIAS_LEN,
 			"%s", page);

Would it help to check page=NULL or *page=0 at start ? Now you have se_dev->su_dev_flags initialised.

re,
wh

Quoted 20 lines
drivers/target/target_core_configfs.c +4 -1
+	if (read_bytes = 0)
+		return -EINVAL;
 
 	if (se_dev->se_dev_alias[read_bytes - 1] = '\n')
 		se_dev->se_dev_alias[read_bytes - 1] = '\0';
@@ -1756,6 +1758,8 @@ static ssize_t target_core_store_dev_udev_path(
 	se_dev->su_dev_flags |= SDF_USING_UDEV_PATH;
 	read_bytes = snprintf(&se_dev->se_dev_udev_path[0], SE_UDEV_PATH_LEN,
 			"%s", page);
+	if (read_bytes = 0)
+		return -EINVAL;
 
 	if (se_dev->se_dev_udev_path[read_bytes - 1] = '\n')
 		se_dev->se_dev_udev_path[read_bytes - 1] = '\0';
--

To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 8 lines · walter harms

Am 24.01.2012 09:40, schrieb Dan Carpenter:

Quoted 5 lines

These are root only and we're not likely to hit the problem in practise, but it makes a the static checkers happy.

Quoted 11 lines

drivers/target/target_core_configfs.c static ssize_t target_core_store_dev_alias( · line 1709

Quoted 8 lines
drivers/target/target_core_configfs.c +0 -0
index 0955bb8..9b86330 100644
@@ -1707,6 +1707,8 @@ static ssize_t target_core_store_dev_alias(
 	se_dev->su_dev_flags |= SDF_USING_ALIAS;
 	read_bytes = snprintf(&se_dev->se_dev_alias[0], SE_DEV_ALIAS_LEN,
 			"%s", page);

Would it help to check page==NULL or *page==0 at start ? Now you have se_dev->su_dev_flags initialised.

It's a fair point. Let me redo it.

regards,
dan carpenter

#3 lore raw

PATCH v2 1/1 target: handle empty string writes in sysfs

In reply to walter harms

These are root only and we're not likely to hit the problem in practise, but it makes the static checkers happy.

---
v2: only set ->su_dev_flags on success.

drivers/target/target_core_configfs.c +8 -4
index 0955bb8..6e043ee 100644
@@ -1704,13 +1704,15 @@ static ssize_t target_core_store_dev_alias(
 		return -EINVAL;
 	}
 
-	se_dev->su_dev_flags |= SDF_USING_ALIAS;
 	read_bytes = snprintf(&se_dev->se_dev_alias[0], SE_DEV_ALIAS_LEN,
 			"%s", page);
-
+	if (!read_bytes)
+		return -EINVAL;
 	if (se_dev->se_dev_alias[read_bytes - 1] == '\n')
 		se_dev->se_dev_alias[read_bytes - 1] = '\0';
 
+	se_dev->su_dev_flags |= SDF_USING_ALIAS;
+
 	pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n",
 		config_item_name(&hba->hba_group.cg_item),
 		config_item_name(&se_dev->se_dev_group.cg_item),
@@ -1753,13 +1755,15 @@ static ssize_t target_core_store_dev_udev_path(
 		return -EINVAL;
 	}
 
-	se_dev->su_dev_flags |= SDF_USING_UDEV_PATH;
 	read_bytes = snprintf(&se_dev->se_dev_udev_path[0], SE_UDEV_PATH_LEN,
 			"%s", page);
-
+	if (!read_bytes)
+		return -EINVAL;
 	if (se_dev->se_dev_udev_path[read_bytes - 1] == '\n')
 		se_dev->se_dev_udev_path[read_bytes - 1] = '\0';
 
+	se_dev->su_dev_flags |= SDF_USING_UDEV_PATH;
+
 	pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
 		config_item_name(&hba->hba_group.cg_item),
 		config_item_name(&se_dev->se_dev_group.cg_item),