From 4d46b361ff1371a6f3f4f89ed8ca81ee23e86de8 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 6 Nov 2019 11:54:56 +0100 Subject: Remove raw file descriptors from tar read path Signed-off-by: David Oberhollenzer --- lib/common/io_stdin.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'lib/common') diff --git a/lib/common/io_stdin.c b/lib/common/io_stdin.c index 9e96e45..ea73771 100644 --- a/lib/common/io_stdin.c +++ b/lib/common/io_stdin.c @@ -46,7 +46,7 @@ static int stdin_read_at(sqfs_file_t *base, sqfs_u64 offset, size_t temp_size = 0; sqfs_u8 *temp = NULL; sqfs_u64 diff; - ssize_t ret; + size_t ret; if (offset < file->offset) return SQFS_ERROR_IO; @@ -60,24 +60,21 @@ static int stdin_read_at(sqfs_file_t *base, sqfs_u64 offset, return SQFS_ERROR_OUT_OF_BOUNDS; while (size > 0) { + if (ferror(stdin)) + return SQFS_ERROR_IO; + + if (feof(stdin)) + return SQFS_ERROR_OUT_OF_BOUNDS; + if (offset > file->offset) { diff = file->offset - offset; diff = diff > (sqfs_u64)temp_size ? temp_size : diff; - ret = read(STDIN_FILENO, temp, diff); + ret = fread(temp, 1, diff, stdin); } else { - ret = read(STDIN_FILENO, buffer, size); - } - - if (ret < 0) { - if (errno == EINTR) - continue; - return SQFS_ERROR_IO; + ret = fread(buffer, 1, size, stdin); } - if (ret == 0) - return SQFS_ERROR_OUT_OF_BOUNDS; - if (offset <= file->offset) { buffer = (char *)buffer + ret; size -= ret; -- cgit v1.2.3