From: Thomas Maier Date: Sun, 22 Oct 2006 17:17:47 +0000 (+0200) Subject: sysfs: sysfs_write_file() writes zero terminated data X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=035ed7a49447bc8e15d4d9316fc6a359b2d94333;p=GitHub%2FLineageOS%2Fandroid_kernel_samsung_universal7580.git sysfs: sysfs_write_file() writes zero terminated data since most of the files in sysfs are text files, it would be nice, if the "store" function called during sysfs_write_file() gets a zero terminated string / data. The current implementation seems not to ensure this. (But only if it is the first time the zeroed buffer page is allocated.) So the buffer can be scanned by sscanf() easily, for example. This patch simply sets a \0 char behind the data in buffer->page. Signed-off-by: Thomas Maier Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index 298303b5a71..95c165101c9 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -190,6 +190,9 @@ fill_write_buffer(struct sysfs_buffer * buffer, const char __user * buf, size_t count = PAGE_SIZE - 1; error = copy_from_user(buffer->page,buf,count); buffer->needs_read_fill = 1; + /* if buf is assumed to contain a string, terminate it by \0, + so e.g. sscanf() can scan the string easily */ + buffer->page[count] = 0; return error ? -EFAULT : count; }