summaryrefslogtreecommitdiff
path: root/sys/lib/libsa
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2016-09-18 15:14:53 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2016-09-18 15:14:53 +0000
commit2723afe21c17425f143489aecfdd457976aac5f8 (patch)
treea49ec40ed4546d1ead6b8cdd98a9902fd8ea0c19 /sys/lib/libsa
parent5e62d079f56e7ed8db94ba68753eef2d65ca60c7 (diff)
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/libsa')
-rw-r--r--sys/lib/libsa/cread.c13
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