lkml.org 
[lkml]   [2007]   [Jan]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: bug reading /proc/sys/kernel/*: only first byte read.
On 01/30, Andrew Morton wrote:
>
> @@ -1705,18 +1704,38 @@ static int _proc_do_string(void* data, i
> ((char *) data)[len] = 0;
> *ppos += *lenp;
> } else {
> - len = strlen(data);
> + loff_t pos = *ppos;
> + const size_t slen = strlen(data);
> +
> + /*
> + * len is the amount of data to copy, and becomes the amount of
> + * data which was copied
> + */
> + len = slen;
> + if (pos > len) {
> + *lenp = 0;
> + return 0;
> + }
> if (len > maxlen)
> len = maxlen;
> if (len > *lenp)
> len = *lenp;
> - if (len)
> - if(copy_to_user(buffer, data, len))
> - return -EFAULT;
> - if (len < *lenp) {
> - if(put_user('\n', ((char __user *) buffer) + len))
> + /* Don't copy past the end of the string */
> + if (len > slen - pos)
> + len = slen - pos;
> + data += pos;
> + /* Copy as much of the string as we can */
> + if (len) {
> + if (copy_to_user(buffer, data, len))
> return -EFAULT;
> - len++;
> + }
> + /* If we copied the whole string, now write a \n */
> + if (len + pos == slen) {
> + if (len + pos < maxlen) {
^^^^^^^^^^^^^^^^^^^^^^^
Shouldn't this be
if (len < *lenp)

?

> + if (put_user('\n', (char __user *)buffer + len))
> + return -EFAULT;
> + len++;
> + }
> }
> *lenp = len;
> *ppos += len;

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2007-01-30 14:29    [W:0.042 / U:1.792 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site