summaryrefslogtreecommitdiff
path: root/sys/lib/libsa/cread.c
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>1999-01-25 19:28:41 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>1999-01-25 19:28:41 +0000
commitfbc895c61cffb41a68d70d1caa4d429d4d0f72f8 (patch)
tree20737295b11ea6c7cebf85103b6eca769a0d5e86 /sys/lib/libsa/cread.c
parentf20f9c111cc35df6e73122e5df2f502f5676ef4d (diff)
fix a real bad bug, which consists of return value from
read() /* oread() */ not being checked for errors/eof or not checked for error value (-1), which would result in bad kernels loaded, i/o errors not reported and such.
Diffstat (limited to 'sys/lib/libsa/cread.c')
-rw-r--r--sys/lib/libsa/cread.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/sys/lib/libsa/cread.c b/sys/lib/libsa/cread.c
index 2f024440cba..d75c3ec6e38 100644
--- a/sys/lib/libsa/cread.c
+++ b/sys/lib/libsa/cread.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cread.c,v 1.6 1998/09/08 03:33:06 millert Exp $ */
+/* $OpenBSD: cread.c,v 1.7 1999/01/25 19:28:38 mickey Exp $ */
/* $NetBSD: cread.c,v 1.2 1997/02/04 18:38:20 thorpej Exp $ */
/*
@@ -105,7 +105,7 @@ static int get_byte(s)
if (s->stream.avail_in == 0) {
errno = 0;
s->stream.avail_in = oread(s->fd, s->inbuf, Z_BUFSIZE);
- if (s->stream.avail_in == 0) {
+ if (s->stream.avail_in <= 0) {
s->z_eof = 1;
if (errno) s->z_err = Z_ERRNO;
return EOF;
@@ -279,7 +279,16 @@ read(fd, buf, len)
s->stream.avail_in -= n;
}
if (s->stream.avail_out > 0) {
- s->stream.avail_out -= oread(fd, s->stream.next_out, s->stream.avail_out);
+ int n;
+ n = oread(fd, s->stream.next_out, s->stream.avail_out);
+ if (n <= 0) {
+ s->z_eof = 1;
+ if (errno) {
+ s->z_err = Z_ERRNO;
+ break;
+ }
+ }
+ s->stream.avail_out -= n;
}
len -= s->stream.avail_out;
s->stream.total_in += (unsigned long)len;
@@ -292,7 +301,7 @@ read(fd, buf, len)
errno = 0;
s->stream.avail_in = oread(fd, s->inbuf, Z_BUFSIZE);
- if (s->stream.avail_in == 0) {
+ if (s->stream.avail_in <= 0) {
s->z_eof = 1;
if (errno) {
s->z_err = Z_ERRNO;