Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Signed-off-by: Mathias Krause <minipli@googlemail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Mathias Krause and committed by
Greg Kroah-Hartman
a3b2c8c7 3a76e5e0

+1
+1
fs/debugfs/file.c
··· 473 473 if (copy_from_user(buf, user_buf, buf_size)) 474 474 return -EFAULT; 475 475 476 + buf[buf_size] = '\0'; 476 477 if (strtobool(buf, &bv) == 0) 477 478 *val = bv; 478 479