Skip to contentSkip to conversation

debugfs: write_file_bool() - ensure strtobool() operates on valid data

PATCH New Mathias Krause 1 participant 1 message May 31, 2013 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 debugfs: write_file_bool() - ensure strtobool() operates on valid data

In case, userland writes an empty string to a bool debugfs file, buf[] will still be uninitialized when being passed to strtobool() making the outcome of that function purely random.

Fix this by always zero-terminating the buffer.

---
 fs/debugfs/file.c |    1 +
 1 file changed, 1 insertion(+)
fs/debugfs/file.c +1 -0
index c5ca6ae..b15a1c5 100644
@@ -431,6 +431,7 @@ static ssize_t write_file_bool(struct file *file, const char __user *user_buf,
 	if (copy_from_user(buf, user_buf, buf_size))
 		return -EFAULT;
 
+	buf[buf_size] = '\0';
 	if (strtobool(buf, &bv) == 0)
 		*val = bv;
 
Signature · 1 line
1.7.10.4