summaryrefslogtreecommitdiff
path: root/sys
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
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')
-rw-r--r--sys/lib/libsa/cread.c17
-rw-r--r--sys/lib/libz/zlib.h4
2 files changed, 15 insertions, 6 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;
diff --git a/sys/lib/libz/zlib.h b/sys/lib/libz/zlib.h
index 49f56b43bc6..9e231f491e9 100644
--- a/sys/lib/libz/zlib.h
+++ b/sys/lib/libz/zlib.h
@@ -67,11 +67,11 @@ struct internal_state;
typedef struct z_stream_s {
Bytef *next_in; /* next input byte */
- uInt avail_in; /* number of bytes available at next_in */
+ int avail_in; /* number of bytes available at next_in */
uLong total_in; /* total nb of input bytes read so far */
Bytef *next_out; /* next output byte should be put there */
- uInt avail_out; /* remaining free space at next_out */
+ int avail_out; /* remaining free space at next_out */
uLong total_out; /* total nb of bytes output so far */
char *msg; /* last error message, NULL if no error */