Skip to content

Commit

Permalink
debugfs: write_file_bool() - ensure strtobool() operates on valid data
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Mathias Krause <minipli@googlemail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Mathias Krause authored and Greg Kroah-Hartman committed Jun 3, 2013
1 parent 3a76e5e commit a3b2c8c
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions fs/debugfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,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;

Expand Down

0 comments on commit a3b2c8c

Please sign in to comment.