From fbc895c61cffb41a68d70d1caa4d429d4d0f72f8 Mon Sep 17 00:00:00 2001 From: Michael Shalayeff Date: Mon, 25 Jan 1999 19:28:41 +0000 Subject: 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. --- sys/lib/libsa/cread.c | 17 +++++++++++++---- sys/lib/libz/zlib.h | 4 ++-- 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 */ -- cgit v1.2.3