diff options
author | jsing <jsing@openbsd.org> | 2016-09-18 15:14:52 +0000 |
---|---|---|
committer | jsing <jsing@openbsd.org> | 2016-09-18 15:14:52 +0000 |
commit | ba4b5c500445d62cc63a6ee1ba93669013458d0a (patch) | |
tree | 6953d3d3faa3c4cd8e65f1b97d2c40087176e041 /sys/lib | |
parent | simplify startup, since we know earlier which type of socket we need (diff) | |
download | wireguard-openbsd-ba4b5c500445d62cc63a6ee1ba93669013458d0a.tar.xz wireguard-openbsd-ba4b5c500445d62cc63a6ee1ba93669013458d0a.zip |
Correctly handle short read()s in the libsa gzip handling lseek(). Also
avoid masking the errno from a failed read().
ok guenther@ tom@
Diffstat (limited to 'sys/lib')
-rw-r--r-- | sys/lib/libsa/cread.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/sys/lib/libsa/cread.c b/sys/lib/libsa/cread.c index 4f3410623f6..b945d778a1e 100644 --- a/sys/lib/libsa/cread.c +++ b/sys/lib/libsa/cread.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cread.c,v 1.14 2016/09/16 15:50:11 jasper Exp $ */ +/* $OpenBSD: cread.c,v 1.15 2016/09/18 15:14:52 jsing Exp $ */ /* $NetBSD: cread.c,v 1.2 1997/02/04 18:38:20 thorpej Exp $ */ /* @@ -416,15 +416,18 @@ lseek(int fd, off_t offset, int where) while(toskip > 0) { #define DUMMYBUFSIZE 256 char dummybuf[DUMMYBUFSIZE]; - off_t len = toskip; + size_t len = toskip; + ssize_t n; if (len > DUMMYBUFSIZE) len = DUMMYBUFSIZE; - if (read(fd, dummybuf, len) != len) { - errno = EOFFSET; + n = read(fd, dummybuf, len); + if (n <= 0) { + if (n == 0) + errno = EINVAL; return((off_t)-1); } - toskip -= len; + toskip -= n; } } #ifdef DEBUG |