From: Alan Cox Date: Sat, 24 Sep 2016 13:17:25 +0000 (+0100) Subject: read/write: error oversized requests X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=afe1c661572c7a6e9d9419a51fe78e58b18ecbf3;p=FUZIX.git read/write: error oversized requests We could allow it but it's undefined behaviour in the standard and in some of our driver code, so force a nice clear error. --- diff --git a/Kernel/syscall_fs.c b/Kernel/syscall_fs.c index db58a8cc..b4e07214 100644 --- a/Kernel/syscall_fs.c +++ b/Kernel/syscall_fs.c @@ -403,7 +403,12 @@ arg_t _read(void) uint8_t flag; if (!nbytes) - return 0; + return 0; + + if ((ssize_t)nbytes < 0) { + udata.u_error = EINVAL; + return -1; + } if (!valaddr(buf, nbytes)) return -1; @@ -466,7 +471,12 @@ arg_t _write(void) uint8_t flag; if (!nbytes) - return 0; + return 0; + + if ((ssize_t)nbytes < 0) { + udata.u_error = EINVAL; + return -1; + } if (!valaddr(buf, nbytes)) return -1;