提交 d39b7dd1 编写于 作者: L Linus Torvalds

sgi-gru: decrapfiy options_write() function

Not a single line of actual code in the function was really
fundamentally correct.

Problems ranged from lack of proper range checking, to removing the last
character written (which admittedly is usually '\n'), to not accepting
hex numbers even though the 'show' routine would show the data in that
format.

This tries to do better.
Acked-by: NMichael Buesch <mb@bu3sch.de>
Tested-and-acked-by: NJack Steiner <steiner@sgi.com>
Cc: stable@kernel.org
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Michael Gilbert <michael.s.gilbert@gmail.com>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 91d3f9ba
......@@ -161,14 +161,15 @@ static int options_show(struct seq_file *s, void *p)
static ssize_t options_write(struct file *file, const char __user *userbuf,
size_t count, loff_t *data)
{
unsigned long val;
char buf[80];
char buf[20];
if (strncpy_from_user(buf, userbuf, sizeof(buf) - 1) < 0)
if (count >= sizeof(buf))
return -EINVAL;
if (copy_from_user(buf, userbuf, count))
return -EFAULT;
buf[count - 1] = '\0';
if (!strict_strtoul(buf, 10, &val))
gru_options = val;
buf[count] = '\0';
if (strict_strtoul(buf, 0, &gru_options))
return -EINVAL;
return count;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册