fix whitespace handling on sysfs attributes
PATCH 1/1 fix whitespace handling on sysfs attributes
The first version of this patch didn't allow for the request firmware case which does multiple parsing passes on the parameter. This was discussed in the thread '2.6.13-rc6-mm1'
gregkh-driver-sysfs-strip_leading_trailing_whitespace-3.patch
should replace in 2.6.13-rc6-mm1
gregkh-driver-sysfs-strip_leading_trailing_whitespace.patch
Signed-off-by Jon Smirl <[email protected]>
Signature · 2 lines
Jon Smirl [email protected]
fs/sysfs/file.c +35 -1
@@ -6,6 +6,7 @@#include <linux/fsnotify.h> #include <linux/kobject.h> #include <linux/namei.h> +#include <linux/ctype.h> #include <asm/uaccess.h> #include <asm/semaphore.h>
@@ -207,8 +208,41 @@ flush_write_buffer(struct dentry * dentrstruct attribute * attr =to_attr (dentry);struct kobject * kobj =to_kobj (dentry->d_parent);struct sysfs_ops * ops = buffer->ops; +size_t ws_count = count, leading =0 ; +int ret =0 ; +char *x; -return ops->store (kobj,attr,buffer->page,count); +/* locate trailing white space */ +while ((ws_count >0 ) &&isspace (buffer->page[ws_count -1 ])) + ws_count--; +if (ws_count ==0 ) +return count; + +/* locate leading white space */ + x = buffer->page; +while (isspace (*x)) + x++; + leading = x - buffer->page; + ws_count -= leading; + +/* interface is still ambigous about this */ +/* string is both passed by length and terminated */ +if (ws_count !=PAGE_SIZE ) + x[ws_count] ='\0' ; + + ret = ops->store (kobj, attr, x, ws_count); + +/* is it an error? */ +if (ret <0 ) +return ret; + +/* the whole string was consumed */ +if (ret == ws_count) +return count; + +/* only part of the string was consumed */ +/* return count can not include trailing space */ +return leading + ret; }
Hi!
Quoted 3 lines
The first version of this patch didn't allow for the request firmware case which does multiple parsing passes on the parameter. This was discussed in the thread '2.6.13-rc6-mm1'
I still thing this is very wrong to do. sysfs should not try to outguess users.
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms