mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 03:36:19 +00:00
[PATCH] _proc_do_string(): fix short reads
If you try to read things like /proc/sys/kernel/osrelease with single-byte reads, you get just one byte and then EOF. This is because _proc_do_string() assumes that the caller is read()ing into a buffer which is large enough to fit the whole string in a single hit. Fix. Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Michael Tokarev <mjt@tls.msk.ru> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
c75fb88dbc
commit
8d06087714
1 changed files with 12 additions and 4 deletions
|
@ -1686,13 +1686,12 @@ static int _proc_do_string(void* data, int maxlen, int write,
|
||||||
size_t len;
|
size_t len;
|
||||||
char __user *p;
|
char __user *p;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
if (!data || !maxlen || !*lenp ||
|
if (!data || !maxlen || !*lenp) {
|
||||||
(*ppos && !write)) {
|
|
||||||
*lenp = 0;
|
*lenp = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write) {
|
if (write) {
|
||||||
len = 0;
|
len = 0;
|
||||||
p = buffer;
|
p = buffer;
|
||||||
|
@ -1713,6 +1712,15 @@ static int _proc_do_string(void* data, int maxlen, int write,
|
||||||
len = strlen(data);
|
len = strlen(data);
|
||||||
if (len > maxlen)
|
if (len > maxlen)
|
||||||
len = maxlen;
|
len = maxlen;
|
||||||
|
|
||||||
|
if (*ppos > len) {
|
||||||
|
*lenp = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
data += *ppos;
|
||||||
|
len -= *ppos;
|
||||||
|
|
||||||
if (len > *lenp)
|
if (len > *lenp)
|
||||||
len = *lenp;
|
len = *lenp;
|
||||||
if (len)
|
if (len)
|
||||||
|
|
Loading…
Reference in a new issue