Skip to contentSkip to conversation

ext4: simple_strtol returns signed.

PATCH In review roel kluin 2 participants 3 messages Oct 18, 2008 – Oct 20, 2008 ext4 file system

lore
Share & tools
lore

roel kluin

author
#0 lore raw

PATCH 1/1 ext4: simple_strtol returns signed.

simple_strtol returns signed.

---

fs/ext4/super.c +1 -1
index 9b2b2bc..1789dec 100644
@@ -3516,7 +3516,7 @@ static ssize_t ext4_ui_proc_write(struct file *file, const char __user *buf,
 {
 	unsigned int *p = PDE(file->f_path.dentry->d_inode)->data;
 	char str[32];
-	unsigned long value;
+	long value;
 
 	if (cnt >= sizeof(str))
 		return -EINVAL;
maintainer
#1 lore raw
Quoted 1 line · roel kluin

simple_strtol returns signed.

Actually the better fix is probably to change the use of simple_strtol() to simple_strtoul().

- Ted

author
#2 lore raw

simple_strtol returns signed, but a negative return values is lost when stored in an unsigned. As suggested use simple_strtoul() instead.

---
Since p is dereferenced with the unsigned long return of simple_strtoul, I think p should be a pointer to an unsigned long, am I wrong?

fs/ext4/super.c +3 -6
index 9b2b2bc..0ab6cb4 100644
@@ -3514,18 +3514,15 @@ static int ext4_ui_proc_open(struct inode *inode, struct file *file)
 static ssize_t ext4_ui_proc_write(struct file *file, const char __user *buf,
 			       size_t cnt, loff_t *ppos)
 {
-	unsigned int *p = PDE(file->f_path.dentry->d_inode)->data;
+	unsigned long *p = PDE(file->f_path.dentry->d_inode)->data;
 	char str[32];
-	unsigned long value;
 
 	if (cnt >= sizeof(str))
 		return -EINVAL;
 	if (copy_from_user(str, buf, cnt))
 		return -EFAULT;
-	value = simple_strtol(str, NULL, 0);
-	if (value < 0)
-		return -ERANGE;
-	*p = value;
+
+	*p = simple_strtoul(str, NULL, 0);
 	return cnt;
 }