diff options
author | Joel Becker <joel.becker@oracle.com> | 2007-01-23 20:00:45 -0500 |
---|---|---|
committer | Mark Fasheh <mark.fasheh@oracle.com> | 2007-02-07 15:17:08 -0500 |
commit | ff05d1c4643dd4260eb699396043d7e8009c0de4 (patch) | |
tree | fe3c601c3c8a2498c434a2d2c08e0192b4233299 /fs/configfs | |
parent | b559292e066f6d570cd5aa5dbd41de61dd04bdce (diff) |
configfs: Zero terminate data in configfs attribute writes.
Attributes in configfs are text files. As such, most handlers expect to be
able to call functions like simple_strtoul() without checking the bounds
of the buffer. Change the call to zero terminate the buffer before calling
the client's ->store() method. This does reduce the attribute size from
PAGE_SIZE to PAGE_SIZE-1.
Also, change get_zeroed_page() to alloc_page(), as we are handling the
termination.
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>
Diffstat (limited to 'fs/configfs')
-rw-r--r-- | fs/configfs/file.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/fs/configfs/file.c b/fs/configfs/file.c index 2a7cb086e80c..d98be5e01328 100644 --- a/fs/configfs/file.c +++ b/fs/configfs/file.c | |||
@@ -162,14 +162,17 @@ fill_write_buffer(struct configfs_buffer * buffer, const char __user * buf, size | |||
162 | int error; | 162 | int error; |
163 | 163 | ||
164 | if (!buffer->page) | 164 | if (!buffer->page) |
165 | buffer->page = (char *)get_zeroed_page(GFP_KERNEL); | 165 | buffer->page = (char *)__get_free_pages(GFP_KERNEL, 0); |
166 | if (!buffer->page) | 166 | if (!buffer->page) |
167 | return -ENOMEM; | 167 | return -ENOMEM; |
168 | 168 | ||
169 | if (count > PAGE_SIZE) | 169 | if (count >= PAGE_SIZE) |
170 | count = PAGE_SIZE; | 170 | count = PAGE_SIZE - 1; |
171 | error = copy_from_user(buffer->page,buf,count); | 171 | error = copy_from_user(buffer->page,buf,count); |
172 | buffer->needs_read_fill = 1; | 172 | buffer->needs_read_fill = 1; |
173 | /* if buf is assumed to contain a string, terminate it by \0, | ||
174 | * so e.g. sscanf() can scan the string easily */ | ||
175 | buffer->page[count] = 0; | ||
173 | return error ? -EFAULT : count; | 176 | return error ? -EFAULT : count; |
174 | } | 177 | } |
175 | 178 | ||