properly check the return value of read() & pread(). PR#26688.
This commit is contained in:
parent
f884703a86
commit
70e8425daf
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: gzip.c,v 1.81 2005/12/13 10:02:04 wiz Exp $ */
|
/* $NetBSD: gzip.c,v 1.82 2006/07/13 11:51:39 mrg Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 1998, 2003, 2004 Matthew R. Green
|
* Copyright (c) 1997, 1998, 2003, 2004 Matthew R. Green
|
||||||
@ -32,7 +32,7 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
__COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004 Matthew R. Green\n\
|
__COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004 Matthew R. Green\n\
|
||||||
All rights reserved.\n");
|
All rights reserved.\n");
|
||||||
__RCSID("$NetBSD: gzip.c,v 1.81 2005/12/13 10:02:04 wiz Exp $");
|
__RCSID("$NetBSD: gzip.c,v 1.82 2006/07/13 11:51:39 mrg Exp $");
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1256,7 +1256,7 @@ file_uncompress(char *file, char *outfile, size_t outsize)
|
|||||||
ssize_t rbytes;
|
ssize_t rbytes;
|
||||||
unsigned char header1[4];
|
unsigned char header1[4];
|
||||||
enum filetype method;
|
enum filetype method;
|
||||||
int fd, ofd, zfd = -1;
|
int rv, fd, ofd, zfd = -1;
|
||||||
#ifndef SMALL
|
#ifndef SMALL
|
||||||
time_t timestamp = 0;
|
time_t timestamp = 0;
|
||||||
unsigned char name[PATH_MAX + 1];
|
unsigned char name[PATH_MAX + 1];
|
||||||
@ -1286,7 +1286,7 @@ file_uncompress(char *file, char *outfile, size_t outsize)
|
|||||||
if (rbytes == -1)
|
if (rbytes == -1)
|
||||||
maybe_warn("can't read %s", file);
|
maybe_warn("can't read %s", file);
|
||||||
else
|
else
|
||||||
maybe_warnx("%s: unexpected end of file", file);
|
goto unexpected_EOF;
|
||||||
goto lose;
|
goto lose;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1304,11 +1304,13 @@ file_uncompress(char *file, char *outfile, size_t outsize)
|
|||||||
if (method == FT_GZIP && Nflag) {
|
if (method == FT_GZIP && Nflag) {
|
||||||
unsigned char ts[4]; /* timestamp */
|
unsigned char ts[4]; /* timestamp */
|
||||||
|
|
||||||
if (pread(fd, ts, sizeof ts, GZIP_TIMESTAMP) != sizeof ts) {
|
if ((rv = pread(fd, ts, sizeof ts, GZIP_TIMESTAMP)) !=
|
||||||
if (!fflag)
|
sizeof ts) {
|
||||||
|
if (rv == -1 && !fflag)
|
||||||
maybe_warn("can't read %s", file);
|
maybe_warn("can't read %s", file);
|
||||||
goto lose;
|
goto lose;
|
||||||
}
|
} else if (rv == 0)
|
||||||
|
goto unexpected_EOF;
|
||||||
timestamp = ts[3] << 24 | ts[2] << 16 | ts[1] << 8 | ts[0];
|
timestamp = ts[3] << 24 | ts[2] << 16 | ts[1] << 8 | ts[0];
|
||||||
|
|
||||||
if (header1[3] & ORIG_NAME) {
|
if (header1[3] & ORIG_NAME) {
|
||||||
@ -1487,6 +1489,8 @@ file_uncompress(char *file, char *outfile, size_t outsize)
|
|||||||
close(ofd);
|
close(ofd);
|
||||||
return size;
|
return size;
|
||||||
|
|
||||||
|
unexpected_EOF:
|
||||||
|
maybe_warnx("%s: unexpected end of file", file);
|
||||||
lose:
|
lose:
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
close(fd);
|
close(fd);
|
||||||
@ -1568,7 +1572,7 @@ handle_stdin(void)
|
|||||||
maybe_warn("can't read stdin");
|
maybe_warn("can't read stdin");
|
||||||
return;
|
return;
|
||||||
} else if (bytes_read != sizeof(header1)) {
|
} else if (bytes_read != sizeof(header1)) {
|
||||||
maybe_warnx("unexpected EOF");
|
maybe_warnx("(stdin): unexpected end of file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1889,13 +1893,21 @@ print_list(int fd, off_t out, const char *outfile, time_t ts)
|
|||||||
unsigned char buf[8];
|
unsigned char buf[8];
|
||||||
uint32_t usize;
|
uint32_t usize;
|
||||||
|
|
||||||
if (read(fd, (char *)buf, sizeof(buf)) != sizeof(buf))
|
rv = read(fd, (char *)buf, sizeof(buf));
|
||||||
|
if (rv == -1)
|
||||||
maybe_warn("read of uncompressed size");
|
maybe_warn("read of uncompressed size");
|
||||||
usize = buf[4] | buf[5] << 8 | buf[6] << 16 | buf[7] << 24;
|
else if (rv != sizeof(buf))
|
||||||
in = (off_t)usize;
|
maybe_warnx("read of uncompressed size");
|
||||||
|
|
||||||
|
else {
|
||||||
|
usize = buf[4] | buf[5] << 8 |
|
||||||
|
buf[6] << 16 | buf[7] << 24;
|
||||||
|
in = (off_t)usize;
|
||||||
#ifndef SMALL
|
#ifndef SMALL
|
||||||
crc = buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24;
|
crc = buf[0] | buf[1] << 8 |
|
||||||
|
buf[2] << 16 | buf[3] << 24;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user