kernel: allow negative lengths in pwrite

This commit is contained in:
Giacomo Tesio 2016-12-24 21:24:48 +01:00
parent ca05868e4d
commit c30fb72b82
1 changed files with 13 additions and 3 deletions

View File

@ -611,8 +611,8 @@ syspread(int fd, void *p, long n, int64_t off)
* the target device/server, but with a negative length * the target device/server, but with a negative length
* to read the buffer must be nil * to read the buffer must be nil
*/ */
pprint("trap: invalid address %#p/%ld in sys call pc=%#P\n", p, n, userpc(nil)); pprint("trap: invalid address %#p/%ld in pread pc=%#P\n", p, n, userpc(nil));
postnote(up, 1, "sys: bad address in syscall", NDebug); postnote(up, 1, "sys: bad address in pread", NDebug);
error(Ebadarg); error(Ebadarg);
} }
@ -697,7 +697,17 @@ syspwrite(int fd, void *p, long n, int64_t off)
r = n; r = n;
p = validaddr(p, n, 0); if(n >= 0)
p = validaddr(p, n, 0);
else if(p != nil) {
/* in Jehanne, a negative length can be meaningful to
* the target device/server, but with a negative length
* to write the buffer must be nil
*/
pprint("trap: invalid address %#p/%ld in pwrite pc=%#P\n", p, n, userpc(nil));
postnote(up, 1, "sys: bad address in pwrite", NDebug);
error(Ebadarg);
}
n = 0; n = 0;
c = fdtochan(fd, OWRITE, 1, 1); c = fdtochan(fd, OWRITE, 1, 1);