From fd5c9f1259d0191af57b20f06dda35e62acb6275 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Tue, 13 Jun 2023 23:44:19 +0200 Subject: Overhaul sqfs_istream_t/sqfs_ostream_t error handling Report an error number from the implementations, change the users to forward that error number (which also means libtar write header/link now returns an error code) and all subsequent binaries to use sqfs_perror() instead of relying on the function to print an error internally. Also, make sure to preserve errno/GetLastError() in the implementations and print out a stringified error in sqfs_perror() if the error code indicates an I/O error. Signed-off-by: David Oberhollenzer --- bin/gensquashfs/Makemodule.am | 2 +- bin/gensquashfs/src/filemap_xattr.c | 8 ++- bin/gensquashfs/src/fstree_from_file.c | 6 +- bin/gensquashfs/src/mkfs.c | 6 +- bin/rdsquashfs/src/fill_files.c | 14 ++-- bin/rdsquashfs/src/rdsquashfs.c | 7 +- bin/sqfs2tar/src/sqfs2tar.c | 11 ++-- bin/sqfs2tar/src/write_tree.c | 11 +++- bin/sqfsdiff/src/extract.c | 15 +++-- bin/tar2sqfs/src/tar2sqfs.c | 7 +- include/io/file.h | 25 ++++--- include/io/std.h | 12 ++-- lib/common/src/data_reader_dump.c | 14 ++-- lib/common/src/perror.c | 33 ++++++++++ lib/io/src/get_line.c | 27 ++++---- lib/io/src/unix/istream.c | 65 +++++++++--------- lib/io/src/unix/ostream.c | 110 ++++++++++++++++--------------- lib/io/src/win32/istream.c | 59 +++++++++-------- lib/io/src/win32/ostream.c | 116 ++++++++++++++++----------------- lib/io/src/xfrm/istream.c | 8 +-- lib/io/src/xfrm/ostream.c | 33 +++++----- lib/tar/Makemodule.am | 95 ++++++++++++++------------- lib/tar/src/internal.h | 2 + lib/tar/src/iterator.c | 2 +- lib/tar/src/read_header.c | 12 +++- lib/tar/src/read_sparse_map_new.c | 9 ++- lib/tar/src/read_sparse_map_old.c | 5 +- lib/tar/src/record_to_memory.c | 10 ++- lib/tar/src/write_header.c | 67 +++++++++---------- lib/tar/test/tar_big_file.c | 4 +- lib/tar/test/tar_fuzz.c | 7 +- lib/tar/test/tar_iterator.c | 9 ++- lib/tar/test/tar_iterator2.c | 5 +- lib/tar/test/tar_iterator3.c | 3 +- lib/tar/test/tar_simple.c | 4 +- lib/tar/test/tar_sparse.c | 4 +- lib/tar/test/tar_sparse_gnu.c | 4 +- lib/tar/test/tar_target_filled.c | 4 +- lib/tar/test/tar_write_simple.c | 3 +- lib/tar/test/tar_xattr.c | 4 +- lib/tar/test/tar_xattr_bin.c | 4 +- lib/util/test/str_table.c | 3 +- 42 files changed, 490 insertions(+), 359 deletions(-) diff --git a/bin/gensquashfs/Makemodule.am b/bin/gensquashfs/Makemodule.am index 98153cb..dd32d5a 100644 --- a/bin/gensquashfs/Makemodule.am +++ b/bin/gensquashfs/Makemodule.am @@ -26,7 +26,7 @@ test_filemap_xattr_SOURCES = bin/gensquashfs/test/filemap_xattr.c \ test_filemap_xattr_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/bin/gensquashfs/src test_filemap_xattr_CPPFLAGS += -DTESTPATH=$(GENDATADIR)/xattr1.txt test_filemap_xattr_LDADD = libio.a libsquashfs.la libfstree.a libutil.a -test_filemap_xattr_LDADD += libcompat.a +test_filemap_xattr_LDADD += libcommon.a libcompat.a test_fstree_from_file_SOURCES = bin/gensquashfs/test/fstree_from_file.c \ bin/gensquashfs/src/fstree_from_file.c \ diff --git a/bin/gensquashfs/src/filemap_xattr.c b/bin/gensquashfs/src/filemap_xattr.c index 89624f4..8843c46 100644 --- a/bin/gensquashfs/src/filemap_xattr.c +++ b/bin/gensquashfs/src/filemap_xattr.c @@ -159,8 +159,12 @@ xattr_open_map_file(const char *path) { struct XattrMap *map; size_t line_num = 1; char *p = NULL; - sqfs_istream_t *file = istream_open_file(path); - if (file == NULL) { + sqfs_istream_t *file = NULL; + int ret; + + ret = istream_open_file(&file, path); + if (ret) { + sqfs_perror(path, NULL, ret); return NULL; } diff --git a/bin/gensquashfs/src/fstree_from_file.c b/bin/gensquashfs/src/fstree_from_file.c index efb5d43..f392b34 100644 --- a/bin/gensquashfs/src/fstree_from_file.c +++ b/bin/gensquashfs/src/fstree_from_file.c @@ -313,9 +313,11 @@ int fstree_from_file(fstree_t *fs, const char *filename, const char *basepath) sqfs_istream_t *fp; int ret; - fp = istream_open_file(filename); - if (fp == NULL) + ret = istream_open_file(&fp, filename); + if (ret) { + sqfs_perror(filename, NULL, ret); return -1; + } ret = fstree_from_file_stream(fs, fp, basepath); diff --git a/bin/gensquashfs/src/mkfs.c b/bin/gensquashfs/src/mkfs.c index cdef359..de291fa 100644 --- a/bin/gensquashfs/src/mkfs.c +++ b/bin/gensquashfs/src/mkfs.c @@ -160,9 +160,11 @@ int main(int argc, char **argv) } if (opt.sortfile != NULL) { - sortfile = istream_open_file(opt.sortfile); - if (sortfile == NULL) + int ret = istream_open_file(&sortfile, opt.sortfile); + if (ret) { + sqfs_perror(opt.sortfile, NULL, ret); goto out; + } } if (opt.infile == NULL) { diff --git a/bin/rdsquashfs/src/fill_files.c b/bin/rdsquashfs/src/fill_files.c index e692ee3..f0ad7e2 100644 --- a/bin/rdsquashfs/src/fill_files.c +++ b/bin/rdsquashfs/src/fill_files.c @@ -145,9 +145,11 @@ static int fill_files(sqfs_data_reader_t *data, int flags) openflags |= SQFS_FILE_OPEN_NO_SPARSE; for (i = 0; i < num_files; ++i) { - fp = ostream_open_file(files[i].path, openflags); - if (fp == NULL) + ret = ostream_open_file(&fp, files[i].path, openflags); + if (ret) { + sqfs_perror(files[i].path, NULL, ret); return -1; + } if (!(flags & UNPACK_QUIET)) printf("unpacking %s\n", files[i].path); @@ -157,9 +159,13 @@ static int fill_files(sqfs_data_reader_t *data, int flags) if (ret == 0) ret = fp->flush(fp); - sqfs_drop(fp); - if (ret) + if (ret) { + sqfs_perror(files[i].path, "unpacking", ret); + sqfs_drop(fp); return -1; + } + + sqfs_drop(fp); } return 0; diff --git a/bin/rdsquashfs/src/rdsquashfs.c b/bin/rdsquashfs/src/rdsquashfs.c index ad85e68..77dc5ba 100644 --- a/bin/rdsquashfs/src/rdsquashfs.c +++ b/bin/rdsquashfs/src/rdsquashfs.c @@ -208,6 +208,7 @@ int main(int argc, char **argv) break; case OP_CAT: { sqfs_ostream_t *fp; + int ret; if (!S_ISREG(n->inode->base.mode)) { fprintf(stderr, "/%s: not a regular file\n", @@ -215,9 +216,11 @@ int main(int argc, char **argv) goto out; } - fp = ostream_open_stdout(); - if (fp == NULL) + ret = ostream_open_stdout(&fp); + if (ret) { + sqfs_perror("stdout", "creating stream wrapper", ret); goto out; + } ret = sqfs_data_reader_dump(opt.cmdpath, data, n->inode, fp, super.block_size); diff --git a/bin/sqfs2tar/src/sqfs2tar.c b/bin/sqfs2tar/src/sqfs2tar.c index e90aa56..714f6db 100644 --- a/bin/sqfs2tar/src/sqfs2tar.c +++ b/bin/sqfs2tar/src/sqfs2tar.c @@ -117,9 +117,9 @@ int main(int argc, char **argv) process_args(argc, argv); - out_file = ostream_open_stdout(); - if (out_file == NULL) { - perror("changing stdout to binary mode"); + ret = ostream_open_stdout(&out_file); + if (ret) { + sqfs_perror("stdout", "creating stream wrapper", ret); goto out; } @@ -253,8 +253,11 @@ int main(int argc, char **argv) if (terminate_archive()) goto out; - if (out_file->flush(out_file)) + ret = out_file->flush(out_file); + if (ret) { + sqfs_perror(out_file->get_filename(out_file), NULL, ret); goto out; + } status = EXIT_SUCCESS; out: diff --git a/bin/sqfs2tar/src/write_tree.c b/bin/sqfs2tar/src/write_tree.c index e578a9f..dc3ac72 100644 --- a/bin/sqfs2tar/src/write_tree.c +++ b/bin/sqfs2tar/src/write_tree.c @@ -119,6 +119,8 @@ static int write_tree_dfs(const sqfs_tree_node_t *n) if (lnk != NULL) { ret = write_hard_link(out_file, &sb, name, lnk->target, record_counter++); + if (ret != 0) + sqfs_perror(name, "writing hard link", ret); sqfs_free(name); return ret; } @@ -143,10 +145,13 @@ static int write_tree_dfs(const sqfs_tree_node_t *n) record_counter++); sqfs_xattr_list_free(xattr); - if (ret > 0) + if (ret == SQFS_ERROR_UNSUPPORTED) { + fprintf(stderr, "WARNING: %s: unsupported file type\n", name); goto out_skip; + } if (ret < 0) { + sqfs_perror(name, "writing tar header", ret); sqfs_free(name); return -1; } @@ -158,7 +163,9 @@ static int write_tree_dfs(const sqfs_tree_node_t *n) return -1; } - if (padd_file(out_file, sb.st_size)) { + ret = padd_file(out_file, sb.st_size); + if (ret) { + sqfs_perror(name, NULL, ret); sqfs_free(name); return -1; } diff --git a/bin/sqfsdiff/src/extract.c b/bin/sqfsdiff/src/extract.c index 43e9b97..d51096f 100644 --- a/bin/sqfsdiff/src/extract.c +++ b/bin/sqfsdiff/src/extract.c @@ -11,6 +11,7 @@ static int extract(sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode, { char *ptr, *temp; sqfs_ostream_t *fp; + int ret; temp = alloca(strlen(prefix) + strlen(path) + 2); sprintf(temp, "%s/%s", prefix, path); @@ -21,9 +22,9 @@ static int extract(sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode, return -1; *ptr = '/'; - fp = ostream_open_file(temp, SQFS_FILE_OPEN_OVERWRITE); - if (fp == NULL) { - perror(temp); + ret = ostream_open_file(&fp, temp, SQFS_FILE_OPEN_OVERWRITE); + if (ret) { + sqfs_perror(temp, NULL, ret); return -1; } @@ -32,7 +33,13 @@ static int extract(sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode, return -1; } - fp->flush(fp); + ret = fp->flush(fp); + if (ret) { + sqfs_perror(fp->get_filename(fp), NULL, ret); + sqfs_drop(fp); + return -1; + } + sqfs_drop(fp); return 0; } diff --git a/bin/tar2sqfs/src/tar2sqfs.c b/bin/tar2sqfs/src/tar2sqfs.c index f7ed060..ed671f5 100644 --- a/bin/tar2sqfs/src/tar2sqfs.c +++ b/bin/tar2sqfs/src/tar2sqfs.c @@ -12,12 +12,15 @@ int main(int argc, char **argv) sqfs_istream_t *input_file = NULL; dir_iterator_t *tar = NULL; sqfs_writer_t sqfs; + int ret; process_args(argc, argv); - input_file = istream_open_stdin(); - if (input_file == NULL) + ret = istream_open_stdin(&input_file); + if (ret) { + sqfs_perror("stdint", "creating stream wrapper", ret); return EXIT_FAILURE; + } tar = tar_open_stream(input_file); sqfs_drop(input_file); diff --git a/include/io/file.h b/include/io/file.h index 5065619..e7ffb0d 100644 --- a/include/io/file.h +++ b/include/io/file.h @@ -22,13 +22,15 @@ extern "C" { * of cleaning it up. On failure, the handle remains usable, and ownership * remains with the caller. * + * @param out Returns a pointer to an input stream on success. * @param path The name to associate with the handle. * @param fd A native file handle. * - * @return A pointer to an output stream on success, NULL on failure. + * @return Zero on success, a negative @ref SQFS_ERROR number on failure */ SQFS_INTERNAL -sqfs_istream_t *istream_open_handle(const char *path, sqfs_file_handle_t fd); +int istream_open_handle(sqfs_istream_t **out, const char *path, + sqfs_file_handle_t fd); /** * @brief Create an output stream that writes to an OS native file handle. @@ -40,26 +42,27 @@ sqfs_istream_t *istream_open_handle(const char *path, sqfs_file_handle_t fd); * Otherwise, it tries to use seek/truncate style APIs to create sparse output * files. * + * @param out Returns a pointer to an output stream on success. * @param path The name to associate with the handle. * @param fd A native file handle. * @param flags A combination of flags. * - * @return A pointer to an output stream on success, NULL on failure. + * @return Zero on success, a negative @ref SQFS_ERROR number on failure */ -SQFS_INTERNAL sqfs_ostream_t *ostream_open_handle(const char *path, - sqfs_file_handle_t hnd, - int flags); +SQFS_INTERNAL int ostream_open_handle(sqfs_ostream_t **out, const char *path, + sqfs_file_handle_t hnd, int flags); /** * @brief Create an input stream that reads from a file. * * @memberof sqfs_istream_t * + * @param out Returns a pointer to an input stream on success. * @param path A path to the file to open or create. * - * @return A pointer to an output stream on success, NULL on failure. + * @return Zero on success, a negative @ref SQFS_ERROR number on failure */ -SQFS_INTERNAL sqfs_istream_t *istream_open_file(const char *path); +SQFS_INTERNAL int istream_open_file(sqfs_istream_t **out, const char *path); /** * @brief Create an output stream that writes to a file. @@ -75,12 +78,14 @@ SQFS_INTERNAL sqfs_istream_t *istream_open_file(const char *path); * Otherwise, it tries to use seek/truncate style APIs to create sparse output * files. * + * @param out Returns a pointer to an output stream on success. * @param path A path to the file to open or create. * @param flags A combination of flags controling how to open/create the file. * - * @return A pointer to an output stream on success, NULL on failure. + * @return Zero on success, a negative @ref SQFS_ERROR number on failure */ -SQFS_INTERNAL sqfs_ostream_t *ostream_open_file(const char *path, int flags); +SQFS_INTERNAL int ostream_open_file(sqfs_ostream_t **out, + const char *path, int flags); #ifdef __cplusplus } diff --git a/include/io/std.h b/include/io/std.h index f622491..c5dddfa 100644 --- a/include/io/std.h +++ b/include/io/std.h @@ -18,18 +18,22 @@ extern "C" { * * @memberof sqfs_istream_t * - * @return A pointer to an input stream on success, NULL on failure. + * @param out Returns a pointer to an input stream on success. + * + * @return Zero on success, a negative @ref SQFS_ERROR number on failure */ -SQFS_INTERNAL sqfs_istream_t *istream_open_stdin(void); +SQFS_INTERNAL int istream_open_stdin(sqfs_istream_t **out); /** * @brief Create an output stream that writes to standard output. * * @memberof sqfs_ostream_t * - * @return A pointer to an output stream on success, NULL on failure. + * @param out Returns a pointer to an output stream on success. + * + * @return Zero on success, a negative @ref SQFS_ERROR number on failure */ -SQFS_INTERNAL sqfs_ostream_t *ostream_open_stdout(void); +SQFS_INTERNAL int ostream_open_stdout(sqfs_ostream_t **out); #ifdef __cplusplus } diff --git a/lib/common/src/data_reader_dump.c b/lib/common/src/data_reader_dump.c index e3cbb87..920b2bd 100644 --- a/lib/common/src/data_reader_dump.c +++ b/lib/common/src/data_reader_dump.c @@ -26,8 +26,7 @@ int sqfs_data_reader_dump(const char *name, sqfs_data_reader_t *data, diff = (filesz < block_size) ? filesz : block_size; if (SQFS_IS_SPARSE_BLOCK(inode->extra[i])) { - if (fp->append(fp, NULL, diff)) - return -1; + err = fp->append(fp, NULL, diff); } else { err = sqfs_data_reader_get_block(data, inode, i, &chunk_size, &chunk); @@ -38,11 +37,11 @@ int sqfs_data_reader_dump(const char *name, sqfs_data_reader_t *data, err = fp->append(fp, chunk, chunk_size); free(chunk); - - if (err) - return -1; } + if (err) + goto fail_io; + filesz -= diff; } @@ -58,8 +57,11 @@ int sqfs_data_reader_dump(const char *name, sqfs_data_reader_t *data, free(chunk); if (err) - return -1; + goto fail_io; } return 0; +fail_io: + sqfs_perror(fp->get_filename(fp), "writing data block", err); + return -1; } diff --git a/lib/common/src/perror.c b/lib/common/src/perror.c index 53a8c16..5f62748 100644 --- a/lib/common/src/perror.c +++ b/lib/common/src/perror.c @@ -8,9 +8,22 @@ #include +#if defined(_WIN32) || defined(__WINDOWS__) +#define WIN32_LEAN_AND_MEAN +#include +#else +#include +#include +#endif + void sqfs_perror(const char *file, const char *action, int error_code) { const char *errstr; +#if defined(_WIN32) || defined(__WINDOWS__) + DWORD syserror = GetLastError(); +#else + int syserror = errno; +#endif switch (error_code) { case SQFS_ERROR_ALLOC: @@ -76,4 +89,24 @@ void sqfs_perror(const char *file, const char *action, int error_code) fprintf(stderr, "%s: ", action); fprintf(stderr, "%s.\n", errstr); + + if (error_code == SQFS_ERROR_IO) { +#if defined(_WIN32) || defined(__WINDOWS__) + LPVOID msg = NULL; + + FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, syserror, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)&msg, 0, NULL); + + fprintf(stderr, "OS error: %s\n", (const char *)msg); + + if (msg != NULL) + LocalFree(msg); +#else + fprintf(stderr, "OS error: %s\n", strerror(syserror)); +#endif + } } diff --git a/lib/io/src/get_line.c b/lib/io/src/get_line.c index ad37be6..3178592 100644 --- a/lib/io/src/get_line.c +++ b/lib/io/src/get_line.c @@ -6,6 +6,7 @@ */ #include "internal.h" #include "sqfs/io.h" +#include "sqfs/error.h" static void ltrim(char *buffer) { @@ -44,17 +45,17 @@ int istream_get_line(sqfs_istream_t *strm, char **out, { char *line = NULL, *new; size_t line_len = 0; + int err; for (;;) { bool have_line = false; size_t i, count, avail; const sqfs_u8 *ptr; - int ret; - ret = strm->get_buffered_data(strm, &ptr, &avail, 0); - if (ret < 0) - goto fail_free; - if (ret > 0) { + err = strm->get_buffered_data(strm, &ptr, &avail, 0); + if (err < 0) + goto fail; + if (err > 0) { if (line_len == 0) goto out_eof; @@ -78,8 +79,10 @@ int istream_get_line(sqfs_istream_t *strm, char **out, } new = realloc(line, line_len + count + 1); - if (new == NULL) - goto fail_errno; + if (new == NULL) { + err = SQFS_ERROR_ALLOC; + goto fail; + } line = new; memcpy(line + line_len, ptr, count); @@ -108,13 +111,13 @@ int istream_get_line(sqfs_istream_t *strm, char **out, *out = line; return 0; -fail_errno: - fprintf(stderr, "%s: " PRI_SZ ": %s.\n", strm->get_filename(strm), - *line_num, strerror(errno)); -fail_free: +fail: { + int temp = errno; free(line); *out = NULL; - return -1; + errno = temp; + return err; +} out_eof: free(line); *out = NULL; diff --git a/lib/io/src/unix/istream.c b/lib/io/src/unix/istream.c index ca9a183..5005a69 100644 --- a/lib/io/src/unix/istream.c +++ b/lib/io/src/unix/istream.c @@ -6,6 +6,7 @@ */ #include "../internal.h" #include "sqfs/io.h" +#include "sqfs/error.h" typedef struct { sqfs_istream_t base; @@ -46,9 +47,7 @@ static int precache(sqfs_istream_t *strm) if (ret < 0) { if (errno == EINTR) continue; - - perror(file->path); - return -1; + return SQFS_ERROR_IO; } file->buffer_used += ret; @@ -90,76 +89,72 @@ static void file_advance_buffer(sqfs_istream_t *strm, size_t count) static const char *file_get_filename(sqfs_istream_t *strm) { - file_istream_t *file = (file_istream_t *)strm; - - return file->path; + return ((file_istream_t *)strm)->path; } static void file_destroy(sqfs_object_t *obj) { file_istream_t *file = (file_istream_t *)obj; - if (file->fd != STDIN_FILENO) - close(file->fd); - + close(file->fd); free(file->path); free(file); } -sqfs_istream_t *istream_open_handle(const char *path, int fd) +int istream_open_handle(sqfs_istream_t **out, const char *path, + sqfs_file_handle_t fd) { file_istream_t *file = calloc(1, sizeof(*file)); sqfs_istream_t *strm = (sqfs_istream_t *)file; - if (file == NULL) { - perror(path); - return NULL; - } + if (file == NULL) + return SQFS_ERROR_ALLOC; sqfs_object_init(file, file_destroy, NULL); file->path = strdup(path); if (file->path == NULL) { - perror(path); - goto fail_free; + int temp = errno; + free(file); + errno = temp; + return SQFS_ERROR_ALLOC; } file->fd = dup(fd); if (file->fd < 0) { - perror(path); - goto fail_path; + int temp = errno; + free(file->path); + free(file); + errno = temp; + return SQFS_ERROR_IO; } close(fd); strm->get_buffered_data = file_get_buffered_data; strm->advance_buffer = file_advance_buffer; strm->get_filename = file_get_filename; - return strm; -fail_path: - free(file->path); -fail_free: - free(file); - return NULL; + + *out = strm; + return 0; } -sqfs_istream_t *istream_open_file(const char *path) +int istream_open_file(sqfs_istream_t **out, const char *path) { sqfs_file_handle_t fd; - sqfs_istream_t *out; + int ret; - if (sqfs_open_native_file(&fd, path, SQFS_FILE_OPEN_READ_ONLY)) { - perror(path); - return NULL; - } + ret = sqfs_open_native_file(&fd, path, SQFS_FILE_OPEN_READ_ONLY); + if (ret) + return ret; - out = istream_open_handle(path, fd); - if (out == NULL) + ret = istream_open_handle(out, path, fd); + if (ret != 0) close(fd); - return out; + return ret; } -sqfs_istream_t *istream_open_stdin(void) +int istream_open_stdin(sqfs_istream_t **out) { - return istream_open_handle("stdin", STDIN_FILENO); + return istream_open_handle(out, "stdin", STDIN_FILENO); } diff --git a/lib/io/src/unix/ostream.c b/lib/io/src/unix/ostream.c index 52a566a..a97d8f3 100644 --- a/lib/io/src/unix/ostream.c +++ b/lib/io/src/unix/ostream.c @@ -6,6 +6,7 @@ */ #include "../internal.h" #include "sqfs/io.h" +#include "sqfs/error.h" typedef struct { sqfs_ostream_t base; @@ -23,15 +24,14 @@ static int write_all(file_ostream_t *file, const sqfs_u8 *data, size_t size) ssize_t ret = write(file->fd, data, size); if (ret == 0) { - fprintf(stderr, "%s: truncated write.\n", file->path); - return -1; + errno = EPIPE; + return SQFS_ERROR_IO; } if (ret < 0) { if (errno == EINTR) continue; - perror(file->path); - return -1; + return SQFS_ERROR_IO; } file->size += ret; @@ -46,6 +46,7 @@ static int realize_sparse(file_ostream_t *file) { unsigned char *buffer; size_t diff, bufsz; + int ret; if (file->sparse_count == 0) return 0; @@ -54,15 +55,18 @@ static int realize_sparse(file_ostream_t *file) bufsz = file->sparse_count > 1024 ? 1024 : file->sparse_count; buffer = calloc(1, bufsz); if (buffer == NULL) - goto fail; + return SQFS_ERROR_ALLOC; while (file->sparse_count > 0) { diff = file->sparse_count > (off_t)bufsz ? bufsz : (size_t)file->sparse_count; - if (write_all(file, buffer, diff)) { + ret = write_all(file, buffer, diff); + if (ret) { + int temp = errno; free(buffer); - return -1; + errno = temp; + return ret; } file->sparse_count -= diff; @@ -71,35 +75,31 @@ static int realize_sparse(file_ostream_t *file) free(buffer); } else { if (lseek(file->fd, file->sparse_count, SEEK_CUR) == (off_t)-1) - goto fail; + return SQFS_ERROR_IO; if (ftruncate(file->fd, file->size) != 0) - goto fail; + return SQFS_ERROR_IO; file->sparse_count = 0; } return 0; -fail: - perror(file->path); - return -1; } static int file_append(sqfs_ostream_t *strm, const void *data, size_t size) { file_ostream_t *file = (file_ostream_t *)strm; + int ret; - if (size == 0) - return 0; - - if (data == NULL) { + if (size == 0 || data == NULL) { file->sparse_count += size; file->size += size; return 0; } - if (realize_sparse(file)) - return -1; + ret = realize_sparse(file); + if (ret) + return ret; return write_all(file, data, size); } @@ -107,15 +107,15 @@ static int file_append(sqfs_ostream_t *strm, const void *data, size_t size) static int file_flush(sqfs_ostream_t *strm) { file_ostream_t *file = (file_ostream_t *)strm; + int ret; - if (realize_sparse(file)) - return -1; + ret = realize_sparse(file); + if (ret) + return ret; if (fsync(file->fd) != 0) { - if (errno == EINVAL) - return 0; - perror(file->path); - return -1; + if (errno != EINVAL) + return SQFS_ERROR_IO; } return 0; @@ -132,33 +132,36 @@ static void file_destroy(sqfs_object_t *obj) static const char *file_get_filename(sqfs_ostream_t *strm) { - file_ostream_t *file = (file_ostream_t *)strm; - - return file->path; + return ((file_ostream_t *)strm)->path; } -sqfs_ostream_t *ostream_open_handle(const char *path, int fd, int flags) +int ostream_open_handle(sqfs_ostream_t **out, const char *path, + sqfs_file_handle_t fd, int flags) { file_ostream_t *file = calloc(1, sizeof(*file)); sqfs_ostream_t *strm = (sqfs_ostream_t *)file; - if (file == NULL) { - perror(path); - return NULL; - } + *out = NULL; + if (file == NULL) + return SQFS_ERROR_ALLOC; sqfs_object_init(file, file_destroy, NULL); file->path = strdup(path); if (file->path == NULL) { - perror(path); - goto fail_free; + int temp = errno; + free(file); + errno = temp; + return SQFS_ERROR_ALLOC; } file->fd = dup(fd); if (file->fd < 0) { - perror(path); - goto fail_path; + int temp = errno; + free(file->path); + free(file); + errno = temp; + return SQFS_ERROR_IO; } close(fd); @@ -167,33 +170,34 @@ sqfs_ostream_t *ostream_open_handle(const char *path, int fd, int flags) strm->append = file_append; strm->flush = file_flush; strm->get_filename = file_get_filename; - return strm; -fail_path: - free(file->path); -fail_free: - free(file); - return NULL; + + *out = strm; + return 0; } -sqfs_ostream_t *ostream_open_file(const char *path, int flags) +int ostream_open_file(sqfs_ostream_t **out, const char *path, int flags) { sqfs_file_handle_t fd; - sqfs_ostream_t *out; + int ret; - if (sqfs_open_native_file(&fd, path, flags)) { - perror(path); - return NULL; - } + *out = NULL; + ret = sqfs_open_native_file(&fd, path, flags); + if (ret) + return ret; - out = ostream_open_handle(path, fd, flags); - if (out == NULL) + ret = ostream_open_handle(out, path, fd, flags); + if (ret) { + int temp = errno; close(fd); + errno = temp; + return ret; + } - return out; + return 0; } -sqfs_ostream_t *ostream_open_stdout(void) +int ostream_open_stdout(sqfs_ostream_t **out) { - return ostream_open_handle("stdout", STDOUT_FILENO, + return ostream_open_handle(out, "stdout", STDOUT_FILENO, SQFS_FILE_OPEN_NO_SPARSE); } diff --git a/lib/io/src/win32/istream.c b/lib/io/src/win32/istream.c index 7cc7144..1a4f4db 100644 --- a/lib/io/src/win32/istream.c +++ b/lib/io/src/win32/istream.c @@ -6,6 +6,7 @@ */ #include "../internal.h" #include "sqfs/io.h" +#include "sqfs/error.h" #define WIN32_LEAN_AND_MEAN #include @@ -52,8 +53,7 @@ static int precache(sqfs_istream_t *strm) } SetLastError(error); - w32_perror(file->path); - return -1; + return SQFS_ERROR_IO; } if (actual == 0) { @@ -112,31 +112,34 @@ static void file_destroy(sqfs_object_t *obj) free(file); } -sqfs_istream_t *istream_open_handle(const char *path, HANDLE hnd) +int istream_open_handle(sqfs_istream_t **out, const char *path, HANDLE hnd) { file_istream_t *file = calloc(1, sizeof(*file)); sqfs_istream_t *strm = (sqfs_istream_t *)file; BOOL ret; - if (file == NULL) { - perror(path); - return NULL; - } + if (file == NULL) + return SQFS_ERROR_ALLOC; sqfs_object_init(file, file_destroy, NULL); file->path = strdup(path); if (file->path == NULL) { - perror(path); - goto fail_free; + DWORD temp = GetLastError(); + free(file); + SetLastError(temp); + return SQFS_ERROR_ALLOC; } ret = DuplicateHandle(GetCurrentProcess(), hnd, GetCurrentProcess(), &file->hnd, 0, FALSE, DUPLICATE_SAME_ACCESS); if (!ret) { - w32_perror(path); - goto fail_path; + DWORD temp = GetLastError(); + free(file->path); + free(file); + SetLastError(temp); + return SQFS_ERROR_IO; } CloseHandle(hnd); @@ -144,34 +147,34 @@ sqfs_istream_t *istream_open_handle(const char *path, HANDLE hnd) strm->get_buffered_data = file_get_buffered_data; strm->advance_buffer = file_advance_buffer; strm->get_filename = file_get_filename; - return strm; -fail_path: - free(file->path); -fail_free: - free(file); - return NULL; + + *out = strm; + return 0; } -sqfs_istream_t *istream_open_file(const char *path) +int istream_open_file(sqfs_istream_t **out, const char *path) { sqfs_file_handle_t hnd; - sqfs_istream_t *out; + int ret; - if (sqfs_open_native_file(&hnd, path, SQFS_FILE_OPEN_READ_ONLY)) { - w32_perror(path); - return NULL; - } + ret = sqfs_open_native_file(&hnd, path, SQFS_FILE_OPEN_READ_ONLY); + if (ret) + return ret; - out = istream_open_handle(path, hnd); - if (out == NULL) + ret = istream_open_handle(out, path, hnd); + if (ret) { + DWORD temp = GetLastError(); CloseHandle(hnd); + SetLastError(temp); + return ret; + } - return out; + return 0; } -sqfs_istream_t *istream_open_stdin(void) +int istream_open_stdin(sqfs_istream_t **out) { HANDLE hnd = GetStdHandle(STD_INPUT_HANDLE); - return istream_open_handle("stdin", hnd); + return istream_open_handle(out, "stdin", hnd); } diff --git a/lib/io/src/win32/ostream.c b/lib/io/src/win32/ostream.c index 5b584e5..b2ba599 100644 --- a/lib/io/src/win32/ostream.c +++ b/lib/io/src/win32/ostream.c @@ -6,6 +6,7 @@ */ #include "../internal.h" #include "sqfs/io.h" +#include "sqfs/error.h" #define WIN32_LEAN_AND_MEAN #include @@ -23,10 +24,8 @@ static int write_data(file_ostream_t *file, const void *data, size_t size) DWORD diff; while (size > 0) { - if (!WriteFile(file->hnd, data, size, &diff, NULL)) { - w32_perror(file->path); - return -1; - } + if (!WriteFile(file->hnd, data, size, &diff, NULL)) + return SQFS_ERROR_IO; size -= diff; data = (const char *)data + diff; @@ -40,6 +39,7 @@ static int realize_sparse(file_ostream_t *file) size_t bufsz, diff; LARGE_INTEGER pos; void *buffer; + int ret; if (file->sparse_count == 0) return 0; @@ -48,18 +48,19 @@ static int realize_sparse(file_ostream_t *file) bufsz = file->sparse_count > 1024 ? 1024 : file->sparse_count; buffer = calloc(1, bufsz); - if (buffer == NULL) { - fputs("out-of-memory\n", stderr); - return -1; - } + if (buffer == NULL) + return SQFS_ERROR_ALLOC; while (file->sparse_count > 0) { diff = file->sparse_count > bufsz ? bufsz : file->sparse_count; - if (write_data(file, buffer, diff)) { + ret = write_data(file, buffer, diff); + if (ret) { + DWORD temp = GetLastError(); free(buffer); - return -1; + SetLastError(temp); + return ret; } file->sparse_count -= diff; @@ -70,34 +71,30 @@ static int realize_sparse(file_ostream_t *file) pos.QuadPart = file->sparse_count; if (!SetFilePointerEx(file->hnd, pos, NULL, FILE_CURRENT)) - goto fail; + return SQFS_ERROR_IO; if (!SetEndOfFile(file->hnd)) - goto fail; + return SQFS_ERROR_IO; file->sparse_count = 0; } return 0; -fail: - w32_perror(file->path); - return -1; } static int file_append(sqfs_ostream_t *strm, const void *data, size_t size) { file_ostream_t *file = (file_ostream_t *)strm; + int ret; - if (size == 0) - return 0; - - if (data == NULL) { + if (size == 0 || data == NULL) { file->sparse_count += size; return 0; } - if (realize_sparse(file)) - return -1; + ret = realize_sparse(file); + if (ret) + return ret; return write_data(file, data, size); } @@ -105,14 +102,14 @@ static int file_append(sqfs_ostream_t *strm, const void *data, size_t size) static int file_flush(sqfs_ostream_t *strm) { file_ostream_t *file = (file_ostream_t *)strm; + int ret; - if (realize_sparse(file)) - return -1; + ret = realize_sparse(file); + if (ret) + return ret; - if (!FlushFileBuffers(file->hnd)) { - w32_perror(file->path); - return -1; - } + if (!FlushFileBuffers(file->hnd)) + return SQFS_ERROR_IO; return 0; } @@ -128,36 +125,36 @@ static void file_destroy(sqfs_object_t *obj) static const char *file_get_filename(sqfs_ostream_t *strm) { - file_ostream_t *file = (file_ostream_t *)strm; - - return file->path; + return ((file_ostream_t *)strm)->path; } -sqfs_ostream_t *ostream_open_handle(const char *path, HANDLE hnd, int flags) +int ostream_open_handle(sqfs_ostream_t **out, const char *path, + sqfs_file_handle_t hnd, int flags) { file_ostream_t *file = calloc(1, sizeof(*file)); sqfs_ostream_t *strm = (sqfs_ostream_t *)file; BOOL ret; - if (file == NULL) { - perror(path); - return NULL; - } + if (file == NULL) + return SQFS_ERROR_ALLOC; sqfs_object_init(file, file_destroy, NULL); file->path = strdup(path); if (file->path == NULL) { - perror(path); - goto fail_free; + free(file); + return SQFS_ERROR_ALLOC; } ret = DuplicateHandle(GetCurrentProcess(), hnd, GetCurrentProcess(), &file->hnd, 0, FALSE, DUPLICATE_SAME_ACCESS); if (!ret) { - w32_perror(path); - goto fail_path; + DWORD temp = GetLastError(); + free(file->path); + free(file); + SetLastError(temp); + return SQFS_ERROR_IO; } CloseHandle(hnd); @@ -166,39 +163,36 @@ sqfs_ostream_t *ostream_open_handle(const char *path, HANDLE hnd, int flags) strm->append = file_append; strm->flush = file_flush; strm->get_filename = file_get_filename; - return strm; -fail_path: - free(file->path); -fail_free: - free(file); - return NULL; + + *out = strm; + return 0; } -sqfs_ostream_t *ostream_open_file(const char *path, int flags) +int ostream_open_file(sqfs_ostream_t **out, const char *path, int flags) { sqfs_file_handle_t hnd; - sqfs_ostream_t *out; - - if (sqfs_open_native_file(&hnd, path, flags)) { - w32_perror(path); - return NULL; - } + int ret; - if (hnd == INVALID_HANDLE_VALUE) { - w32_perror(path); - return NULL; - } + *out = NULL; + ret = sqfs_open_native_file(&hnd, path, flags); + if (ret) + return ret; - out = ostream_open_handle(path, hnd, flags); - if (out == NULL) + ret = ostream_open_handle(out, path, hnd, flags); + if (ret) { + DWORD temp = GetLastError(); CloseHandle(hnd); + SetLastError(temp); + return SQFS_ERROR_IO; + } - return out; + return 0; } -sqfs_ostream_t *ostream_open_stdout(void) +int ostream_open_stdout(sqfs_ostream_t **out) { HANDLE hnd = GetStdHandle(STD_OUTPUT_HANDLE); - return ostream_open_handle("stdout", hnd, SQFS_FILE_OPEN_NO_SPARSE); + return ostream_open_handle(out, "stdout", hnd, + SQFS_FILE_OPEN_NO_SPARSE); } diff --git a/lib/io/src/xfrm/istream.c b/lib/io/src/xfrm/istream.c index c499f6c..ee4b5bd 100644 --- a/lib/io/src/xfrm/istream.c +++ b/lib/io/src/xfrm/istream.c @@ -6,6 +6,7 @@ */ #include "../internal.h" #include "sqfs/io.h" +#include "sqfs/error.h" typedef struct istream_xfrm_t { sqfs_istream_t base; @@ -52,11 +53,8 @@ static int precache(sqfs_istream_t *base) BUFSZ - out_off, &in_off, &out_off, mode); - if (ret == XFRM_STREAM_ERROR) { - fprintf(stderr, "%s: internal error in decompressor.\n", - base->get_filename(base)); - return -1; - } + if (ret == XFRM_STREAM_ERROR) + return SQFS_ERROR_COMPRESSOR; xfrm->buffer_used = out_off; xfrm->wrapped->advance_buffer(xfrm->wrapped, in_off); diff --git a/lib/io/src/xfrm/ostream.c b/lib/io/src/xfrm/ostream.c index 4c77f42..c035f2a 100644 --- a/lib/io/src/xfrm/ostream.c +++ b/lib/io/src/xfrm/ostream.c @@ -6,6 +6,7 @@ */ #include "../internal.h" #include "sqfs/io.h" +#include "sqfs/error.h" typedef struct ostream_xfrm_t { sqfs_ostream_t base; @@ -26,7 +27,7 @@ static int flush_inbuf(ostream_xfrm_t *xfrm, bool finish) const int mode = finish ? XFRM_STREAM_FLUSH_FULL : XFRM_STREAM_FLUSH_NONE; sqfs_u32 off_in = 0, off_out = 0; - int ret; + int ret, ioret; while (finish || off_in < avail_in) { ret = xfrm->xfrm->process_data(xfrm->xfrm, @@ -36,15 +37,13 @@ static int flush_inbuf(ostream_xfrm_t *xfrm, bool finish) avail_out - off_out, &off_in, &off_out, mode); - if (ret == XFRM_STREAM_ERROR) { - fprintf(stderr, - "%s: internal error in compressor.\n", - xfrm->wrapped->get_filename(xfrm->wrapped)); - return -1; - } + if (ret == XFRM_STREAM_ERROR) + return SQFS_ERROR_COMPRESSOR; - if (xfrm->wrapped->append(xfrm->wrapped, xfrm->outbuf, off_out)) - return -1; + ioret = xfrm->wrapped->append(xfrm->wrapped, + xfrm->outbuf, off_out); + if (ioret) + return ioret; off_out = 0; @@ -53,8 +52,10 @@ static int flush_inbuf(ostream_xfrm_t *xfrm, bool finish) } if (off_out > 0) { - if (xfrm->wrapped->append(xfrm->wrapped, xfrm->outbuf, off_out)) - return -1; + ret = xfrm->wrapped->append(xfrm->wrapped, + xfrm->outbuf, off_out); + if (ret) + return ret; } if (off_in < avail_in) { @@ -74,8 +75,9 @@ static int xfrm_append(sqfs_ostream_t *strm, const void *data, size_t size) while (size > 0) { if (xfrm->inbuf_used >= BUFSZ) { - if (flush_inbuf(xfrm, false)) - return -1; + int ret = flush_inbuf(xfrm, false); + if (ret) + return ret; } diff = BUFSZ - xfrm->inbuf_used; @@ -102,8 +104,9 @@ static int xfrm_flush(sqfs_ostream_t *strm) ostream_xfrm_t *xfrm = (ostream_xfrm_t *)strm; if (xfrm->inbuf_used > 0) { - if (flush_inbuf(xfrm, true)) - return -1; + int ret = flush_inbuf(xfrm, true); + if (ret) + return ret; } return xfrm->wrapped->flush(xfrm->wrapped); diff --git a/lib/tar/Makemodule.am b/lib/tar/Makemodule.am index 983467e..b66d071 100644 --- a/lib/tar/Makemodule.am +++ b/lib/tar/Makemodule.am @@ -11,193 +11,194 @@ noinst_LIBRARIES += libtar.a TARDATADIR=$(top_srcdir)/lib/tar/test/data test_tar_gnu0_SOURCES = lib/tar/test/tar_simple.c -test_tar_gnu0_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_gnu0_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_gnu0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_gnu0_CPPFLAGS += -DTESTFILE=format-acceptance/gnu.tar test_tar_gnu1_SOURCES = lib/tar/test/tar_simple.c -test_tar_gnu1_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_gnu1_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_gnu1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_gnu1_CPPFLAGS += -DTESTFILE=format-acceptance/gnu-g.tar test_tar_gnu2_SOURCES = lib/tar/test/tar_simple.c -test_tar_gnu2_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_gnu2_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_gnu2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_gnu2_CPPFLAGS += -DTESTFILE=user-group-largenum/gnu.tar test_tar_gnu2_CPPFLAGS += -DTESTUID=0x80000000 -DTESTGID=0x80000000 test_tar_gnu2_CPPFLAGS += -DTESTTS=1542995392 test_tar_gnu3_SOURCES = lib/tar/test/tar_simple.c -test_tar_gnu3_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_gnu3_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_gnu3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_gnu3_CPPFLAGS += -DTESTFILE=negative-mtime/gnu.tar -DTESTTS=-315622800 test_tar_gnu4_SOURCES = lib/tar/test/tar_simple.c -test_tar_gnu4_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_gnu4_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_gnu4_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_gnu4_CPPFLAGS += -DTESTFILE=long-paths/gnu.tar -DLONG_NAME_TEST test_tar_gnu4_CPPFLAGS += -DTESTTS=1542909670 test_tar_gnu5_SOURCES = lib/tar/test/tar_simple.c -test_tar_gnu5_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_gnu5_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_gnu5_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_gnu5_CPPFLAGS += -DTESTFILE=large-mtime/gnu.tar -DTESTTS=8589934592L test_tar_gnu6_SOURCES = lib/tar/test/tar_big_file.c -test_tar_gnu6_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_gnu6_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_gnu6_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_gnu6_CPPFLAGS += -DTESTFILE=file-size/gnu.tar test_tar_pax0_SOURCES = lib/tar/test/tar_simple.c -test_tar_pax0_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_pax0_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_pax0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_pax0_CPPFLAGS += -DTESTFILE=format-acceptance/pax.tar test_tar_pax1_SOURCES = lib/tar/test/tar_simple.c -test_tar_pax1_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_pax1_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_pax1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_pax1_CPPFLAGS += -DTESTFILE=user-group-largenum/pax.tar test_tar_pax1_CPPFLAGS += -DTESTUID=2147483648UL -DTESTGID=2147483648UL test_tar_pax1_CPPFLAGS += -DTESTTS=1542995392 test_tar_pax2_SOURCES = lib/tar/test/tar_simple.c -test_tar_pax2_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_pax2_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_pax2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_pax2_CPPFLAGS += -DTESTFILE=large-mtime/pax.tar -DTESTTS=8589934592L test_tar_pax3_SOURCES = lib/tar/test/tar_simple.c -test_tar_pax3_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_pax3_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_pax3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_pax3_CPPFLAGS += -DTESTFILE=negative-mtime/pax.tar -DTESTTS=-315622800 test_tar_pax4_SOURCES = lib/tar/test/tar_simple.c -test_tar_pax4_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_pax4_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_pax4_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_pax4_CPPFLAGS += -DTESTFILE=long-paths/pax.tar test_tar_pax4_CPPFLAGS += -DLONG_NAME_TEST -DTESTTS=1542909670 test_tar_pax5_SOURCES = lib/tar/test/tar_big_file.c -test_tar_pax5_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_pax5_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_pax5_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_pax5_CPPFLAGS += -DTESTFILE=file-size/pax.tar test_tar_ustar0_SOURCES = lib/tar/test/tar_simple.c -test_tar_ustar0_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_ustar0_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_ustar0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_ustar0_CPPFLAGS += -DTESTFILE=format-acceptance/ustar.tar test_tar_ustar1_SOURCES = lib/tar/test/tar_simple.c -test_tar_ustar1_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_ustar1_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_ustar1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_ustar1_CPPFLAGS += -DTESTFILE=format-acceptance/ustar-pre-posix.tar test_tar_ustar2_SOURCES = lib/tar/test/tar_simple.c -test_tar_ustar2_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_ustar2_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_ustar2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_ustar2_CPPFLAGS += -DTESTFILE=format-acceptance/v7.tar test_tar_ustar3_SOURCES = lib/tar/test/tar_simple.c -test_tar_ustar3_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_ustar3_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_ustar3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_ustar3_CPPFLAGS += -DTESTFILE=user-group-largenum/8-digit.tar test_tar_ustar3_CPPFLAGS += -DTESTUID=8388608 -DTESTGID=8388608 test_tar_ustar3_CPPFLAGS += -DTESTTS=1542995392 test_tar_ustar4_SOURCES = lib/tar/test/tar_simple.c -test_tar_ustar4_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_ustar4_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_ustar4_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_ustar4_CPPFLAGS += -DTESTFILE=large-mtime/12-digit.tar test_tar_ustar4_CPPFLAGS += -DTESTTS=8589934592L test_tar_ustar5_SOURCES = lib/tar/test/tar_simple.c -test_tar_ustar5_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_ustar5_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_ustar5_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_ustar5_CPPFLAGS += -DTESTFILE=long-paths/ustar.tar test_tar_ustar5_CPPFLAGS += -DLONG_NAME_TEST -DTESTTS=1542909670 test_tar_ustar6_SOURCES = lib/tar/test/tar_big_file.c -test_tar_ustar6_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +test_tar_ustar6_LDADD = libtar.a libio.a libcommon.a libsquashfs.la libutil.a libcompat.a test_tar_ustar6_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_ustar6_CPPFLAGS += -DTESTFILE=file-size/12-digit.tar test_tar_target_filled_SOURCES = lib/tar/test/tar_target_filled.c -test_tar_target_filled_LDADD = libtar.a libio.a libsquashfs.la libutil.a \ - libcompat.a +test_tar_target_filled_LDADD = libtar.a libio.a libcommon.a libsquashfs.la \ + libutil.a libcompat.a test_tar_target_filled_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_sparse_gnu_SOURCES = lib/tar/test/tar_sparse_gnu.c -test_tar_sparse_gnu_LDADD = libtar.a libio.a libsquashfs.la libutil.a \ - libcompat.a +test_tar_sparse_gnu_LDADD = libtar.a libio.a libcommon.a libsquashfs.la \ + libutil.a libcompat.a test_tar_sparse_gnu_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_sparse_gnu0_SOURCES = lib/tar/test/tar_sparse.c -test_tar_sparse_gnu0_LDADD = libtar.a libio.a libsquashfs.la libutil.a \ - libcompat.a +test_tar_sparse_gnu0_LDADD = libtar.a libio.a libcommon.a libsquashfs.la \ + libutil.a libcompat.a test_tar_sparse_gnu0_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_sparse_gnu0_CPPFLAGS += -DTESTFILE=sparse-files/pax-gnu0-0.tar test_tar_sparse_gnu1_SOURCES = lib/tar/test/tar_sparse.c -test_tar_sparse_gnu1_LDADD = libtar.a libio.a libsquashfs.la libutil.a \ - libcompat.a +test_tar_sparse_gnu1_LDADD = libtar.a libio.a libcommon.a libsquashfs.la \ + libutil.a libcompat.a test_tar_sparse_gnu1_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_sparse_gnu1_CPPFLAGS += -DTESTFILE=sparse-files/pax-gnu0-1.tar test_tar_sparse_gnu2_SOURCES = lib/tar/test/tar_sparse.c -test_tar_sparse_gnu2_LDADD = libtar.a libio.a libsquashfs.la libutil.a \ - libcompat.a +test_tar_sparse_gnu2_LDADD = libtar.a libio.a libcommon.a libsquashfs.la \ + libutil.a libcompat.a test_tar_sparse_gnu2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_sparse_gnu2_CPPFLAGS += -DTESTFILE=sparse-files/pax-gnu1-0.tar test_tar_sparse_gnu3_SOURCES = lib/tar/test/tar_sparse.c -test_tar_sparse_gnu3_LDADD = libtar.a libio.a libsquashfs.la libutil.a \ - libcompat.a +test_tar_sparse_gnu3_LDADD = libtar.a libio.a libcommon.a libsquashfs.la \ + libutil.a libcompat.a test_tar_sparse_gnu3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_sparse_gnu3_CPPFLAGS += -DTESTFILE=sparse-files/gnu.tar test_tar_xattr_bsd_SOURCES = lib/tar/test/tar_xattr.c -test_tar_xattr_bsd_LDADD = libtar.a libio.a libsquashfs.la libutil.a \ - libcompat.a +test_tar_xattr_bsd_LDADD = libtar.a libio.a libcommon.a libsquashfs.la \ + libutil.a libcompat.a test_tar_xattr_bsd_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_xattr_bsd_CPPFLAGS += -DTESTFILE=xattr/xattr-libarchive.tar test_tar_xattr_schily_SOURCES = lib/tar/test/tar_xattr.c -test_tar_xattr_schily_LDADD = libtar.a libio.a libsquashfs.la libutil.a \ - libcompat.a +test_tar_xattr_schily_LDADD = libtar.a libio.a libcommon.a libsquashfs.la \ + libutil.a libcompat.a test_tar_xattr_schily_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_xattr_schily_CPPFLAGS += -DTESTFILE=xattr/xattr-schily.tar test_tar_xattr_schily_bin_SOURCES = lib/tar/test/tar_xattr_bin.c -test_tar_xattr_schily_bin_LDADD = libtar.a libio.a libsquashfs.la libutil.a \ - libcompat.a +test_tar_xattr_schily_bin_LDADD = libtar.a libio.a libcommon.a libsquashfs.la \ + libutil.a libcompat.a test_tar_xattr_schily_bin_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_xattr_schily_bin_CPPFLAGS += -DTESTFILE=xattr/xattr-schily-binary.tar test_tar_iterator_SOURCES = lib/tar/test/tar_iterator.c -test_tar_iterator_LDADD = libtar.a libio.a libsquashfs.la libxfrm.a \ - libutil.a libcompat.a $(XZ_LIBS) $(BZIP2_LIBS) \ +test_tar_iterator_LDADD = libtar.a libio.a libcommon.a libsquashfs.la \ + libxfrm.a libutil.a libcompat.a $(XZ_LIBS) $(BZIP2_LIBS) \ $(ZLIB_LIBS) $(ZSTD_LIBS) test_tar_iterator_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_iterator_CPPFLAGS += -DTESTFILE=format-acceptance/gnu.tar test_tar_iterator2_SOURCES = lib/tar/test/tar_iterator2.c -test_tar_iterator2_LDADD = libtar.a libio.a libsquashfs.la libxfrm.a \ - libutil.a libcompat.a $(XZ_LIBS) $(BZIP2_LIBS) \ +test_tar_iterator2_LDADD = libtar.a libio.a libcommon.a libsquashfs.la \ + libxfrm.a libutil.a libcompat.a $(XZ_LIBS) $(BZIP2_LIBS) \ $(ZLIB_LIBS) $(ZSTD_LIBS) test_tar_iterator2_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_iterator2_CPPFLAGS += -DTESTFILE=iterator/sparse.tar test_tar_iterator3_SOURCES = lib/tar/test/tar_iterator3.c -test_tar_iterator3_LDADD = libtar.a libio.a libsquashfs.la libxfrm.a \ - libutil.a libcompat.a $(XZ_LIBS) $(BZIP2_LIBS) \ +test_tar_iterator3_LDADD = libtar.a libio.a libcommon.a libsquashfs.la \ + libxfrm.a libutil.a libcompat.a $(XZ_LIBS) $(BZIP2_LIBS) \ $(ZLIB_LIBS) $(ZSTD_LIBS) test_tar_iterator3_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) tar_fuzz_SOURCES = lib/tar/test/tar_fuzz.c -tar_fuzz_LDADD = libtar.a libio.a libsquashfs.la libutil.a libcompat.a +tar_fuzz_LDADD = libtar.a libio.a libcommon.a libcommon.a libsquashfs.la \ + libutil.a libcompat.a test_tar_write_simple_SOURCES = lib/tar/test/tar_write_simple.c -test_tar_write_simple_LDADD = libtar.a libio.a libsquashfs.la libutil.a \ - libcompat.a +test_tar_write_simple_LDADD = libtar.a libio.a libcommon.a libsquashfs.la \ + libutil.a libcompat.a test_tar_write_simple_CPPFLAGS = $(AM_CPPFLAGS) -DTESTPATH=$(TARDATADIR) test_tar_write_simple_CPPFLAGS += -DTESTFILE=write/simple.tar diff --git a/lib/tar/src/internal.h b/lib/tar/src/internal.h index 56613d3..4671f0b 100644 --- a/lib/tar/src/internal.h +++ b/lib/tar/src/internal.h @@ -12,6 +12,8 @@ #include "tar/tar.h" #include "tar/format.h" #include "util/util.h" +#include "sqfs/error.h" +#include "common.h" enum { PAX_SIZE = 0x001, diff --git a/lib/tar/src/iterator.c b/lib/tar/src/iterator.c index 93c931c..ed35b73 100644 --- a/lib/tar/src/iterator.c +++ b/lib/tar/src/iterator.c @@ -231,7 +231,7 @@ retry: return 0; fail: - tar->state = ret < 0 ? SQFS_ERROR_IO : 1; + tar->state = ret < 0 ? ret : 1; return tar->state; } diff --git a/lib/tar/src/read_header.c b/lib/tar/src/read_header.c index 16fc9d7..df2f56c 100644 --- a/lib/tar/src/read_header.c +++ b/lib/tar/src/read_header.c @@ -176,8 +176,11 @@ int read_header(sqfs_istream_t *fp, tar_header_decoded_t *out) for (;;) { ret = sqfs_istream_read(fp, &hdr, sizeof(hdr)); - if (ret < 0) + if (ret < 0) { + sqfs_perror(fp->get_filename(fp), + "reading raw tar header", ret); goto fail; + } if ((size_t)ret < sizeof(hdr)) goto out_eof; @@ -226,7 +229,12 @@ int read_header(sqfs_istream_t *fp, tar_header_decoded_t *out) goto fail; if (pax_size % 512) pax_size += 512 - (pax_size % 512); - sqfs_istream_skip(fp, pax_size); + ret = sqfs_istream_skip(fp, pax_size); + if (ret) { + sqfs_perror(fp->get_filename(fp), + "skipping padding", ret); + goto fail; + } continue; case TAR_TYPE_PAX: clear_header(out); diff --git a/lib/tar/src/read_sparse_map_new.c b/lib/tar/src/read_sparse_map_new.c index 4e317a8..e42466c 100644 --- a/lib/tar/src/read_sparse_map_new.c +++ b/lib/tar/src/read_sparse_map_new.c @@ -42,8 +42,10 @@ sparse_map_t *read_gnu_new_sparse(sqfs_istream_t *fp, tar_header_decoded_t *out) goto fail_format; ret = sqfs_istream_read(fp, buffer, 512); - if (ret < 0) + if (ret < 0) { + sqfs_perror(fp->get_filename(fp), "reading sparse list", ret); goto fail; + } if (ret < 512) goto fail_format; @@ -69,8 +71,11 @@ sparse_map_t *read_gnu_new_sparse(sqfs_istream_t *fp, tar_header_decoded_t *out) goto fail_format; ret = sqfs_istream_read(fp, buffer + 512, 512); - if (ret < 0) + if (ret < 0) { + sqfs_perror(fp->get_filename(fp), + "reading sparse list", ret); goto fail; + } if (ret < 512) goto fail_format; diff --git a/lib/tar/src/read_sparse_map_old.c b/lib/tar/src/read_sparse_map_old.c index 1794073..0915214 100644 --- a/lib/tar/src/read_sparse_map_old.c +++ b/lib/tar/src/read_sparse_map_old.c @@ -60,8 +60,11 @@ sparse_map_t *read_gnu_old_sparse(sqfs_istream_t *fp, tar_header_t *hdr) do { ret = sqfs_istream_read(fp, &sph, sizeof(sph)); - if (ret < 0) + if (ret < 0) { + sqfs_perror(fp->get_filename(fp), + "reading old GNU sparse list", ret); goto fail; + } if ((size_t)ret < sizeof(sph)) goto fail_eof; diff --git a/lib/tar/src/record_to_memory.c b/lib/tar/src/record_to_memory.c index 597d6f8..84beaa3 100644 --- a/lib/tar/src/record_to_memory.c +++ b/lib/tar/src/record_to_memory.c @@ -19,8 +19,10 @@ char *record_to_memory(sqfs_istream_t *fp, size_t size) goto fail_errno; ret = sqfs_istream_read(fp, buffer, size); - if (ret < 0) + if (ret < 0) { + sqfs_perror(fp->get_filename(fp), "reading tar record", ret); goto fail; + } if ((size_t)ret < size) { fputs("Reading tar record: unexpected end-of-file.\n", stderr); @@ -28,8 +30,12 @@ char *record_to_memory(sqfs_istream_t *fp, size_t size) } if (size % 512) { - if (sqfs_istream_skip(fp, 512 - (size % 512))) + ret = sqfs_istream_skip(fp, 512 - (size % 512)); + if (ret) { + sqfs_perror(fp->get_filename(fp), + "skipping tar padding", ret); goto fail; + } } buffer[size] = '\0'; diff --git a/lib/tar/src/write_header.c b/lib/tar/src/write_header.c index 1183c9a..dda98b7 100644 --- a/lib/tar/src/write_header.c +++ b/lib/tar/src/write_header.c @@ -8,6 +8,7 @@ #include "internal.h" #include "sqfs/xattr.h" +#include "sqfs/error.h" #include #include @@ -106,16 +107,19 @@ static int write_ext_header(sqfs_ostream_t *fp, const struct stat *orig, int type, const char *name) { struct stat sb; + int ret; sb = *orig; sb.st_mode = S_IFREG | 0644; sb.st_size = payload_len; - if (write_header(fp, &sb, name, NULL, type)) - return -1; + ret = write_header(fp, &sb, name, NULL, type); + if (ret) + return ret; - if (fp->append(fp, payload, payload_len)) - return -1; + ret = fp->append(fp, payload, payload_len); + if (ret) + return ret; return padd_file(fp, payload_len); } @@ -159,11 +163,8 @@ static int write_schily_xattr(sqfs_ostream_t *fp, const struct stat *orig, } buffer = calloc(1, total_size + 1); - if (buffer == NULL) { - fprintf(stderr, "%s: generating xattr header: " - "out-of-memory\n", name); - return -1; - } + if (buffer == NULL) + return SQFS_ERROR_ALLOC; ptr = buffer; @@ -188,15 +189,15 @@ int write_tar_header(sqfs_ostream_t *fp, const char *slink_target, const sqfs_xattr_t *xattr, unsigned int counter) { - const char *reason; char buffer[64]; - int type; + int type, ret; if (xattr != NULL) { sprintf(buffer, "pax/xattr%u", counter); - if (write_schily_xattr(fp, sb, buffer, xattr)) - return -1; + ret = write_schily_xattr(fp, sb, buffer, xattr); + if (ret) + return ret; } if (!S_ISLNK(sb->st_mode)) @@ -204,19 +205,20 @@ int write_tar_header(sqfs_ostream_t *fp, if (S_ISLNK(sb->st_mode) && sb->st_size >= 100) { sprintf(buffer, "gnu/target%u", counter); - if (write_ext_header(fp, sb, slink_target, sb->st_size, - TAR_TYPE_GNU_SLINK, buffer)) - return -1; + ret = write_ext_header(fp, sb, slink_target, sb->st_size, + TAR_TYPE_GNU_SLINK, buffer); + if (ret) + return ret; slink_target = NULL; } if (strlen(name) >= 100) { sprintf(buffer, "gnu/name%u", counter); - if (write_ext_header(fp, sb, name, strlen(name), - TAR_TYPE_GNU_PATH, buffer)) { - return -1; - } + ret = write_ext_header(fp, sb, name, strlen(name), + TAR_TYPE_GNU_PATH, buffer); + if (ret) + return ret; sprintf(buffer, "gnu/data%u", counter); name = buffer; @@ -229,18 +231,11 @@ int write_tar_header(sqfs_ostream_t *fp, case S_IFREG: type = TAR_TYPE_FILE; break; case S_IFDIR: type = TAR_TYPE_DIR; break; case S_IFIFO: type = TAR_TYPE_FIFO; break; - case S_IFSOCK: - reason = "cannot pack socket"; - goto out_skip; default: - reason = "unknown type"; - goto out_skip; + return SQFS_ERROR_UNSUPPORTED; } return write_header(fp, sb, name, slink_target, type); -out_skip: - fprintf(stderr, "WARNING: %s: %s\n", name, reason); - return 1; } int write_hard_link(sqfs_ostream_t *fp, const struct stat *sb, const char *name, @@ -249,15 +244,17 @@ int write_hard_link(sqfs_ostream_t *fp, const struct stat *sb, const char *name, tar_header_t hdr; char buffer[64]; size_t len; + int ret; memset(&hdr, 0, sizeof(hdr)); len = strlen(target); if (len >= 100) { sprintf(buffer, "gnu/target%u", counter); - if (write_ext_header(fp, sb, target, len, - TAR_TYPE_GNU_SLINK, buffer)) - return -1; + ret = write_ext_header(fp, sb, target, len, + TAR_TYPE_GNU_SLINK, buffer); + if (ret) + return ret; sprintf(hdr.linkname, "hardlink_%u", counter); } else { memcpy(hdr.linkname, target, len); @@ -266,10 +263,10 @@ int write_hard_link(sqfs_ostream_t *fp, const struct stat *sb, const char *name, len = strlen(name); if (len >= 100) { sprintf(buffer, "gnu/name%u", counter); - if (write_ext_header(fp, sb, name, len, - TAR_TYPE_GNU_PATH, buffer)) { - return -1; - } + ret = write_ext_header(fp, sb, name, len, + TAR_TYPE_GNU_PATH, buffer); + if (ret) + return ret; sprintf(hdr.name, "gnu/data%u", counter); } else { memcpy(hdr.name, name, len); diff --git a/lib/tar/test/tar_big_file.c b/lib/tar/test/tar_big_file.c index 444548b..6a88d4c 100644 --- a/lib/tar/test/tar_big_file.c +++ b/lib/tar/test/tar_big_file.c @@ -13,9 +13,11 @@ int main(int argc, char **argv) { tar_header_decoded_t hdr; sqfs_istream_t *fp; + int ret; (void)argc; (void)argv; - fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + ret = istream_open_file(&fp, STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + TEST_EQUAL_I(ret, 0); TEST_NOT_NULL(fp); TEST_ASSERT(read_header(fp, &hdr) == 0); TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644); diff --git a/lib/tar/test/tar_fuzz.c b/lib/tar/test/tar_fuzz.c index 92c0952..42fe73d 100644 --- a/lib/tar/test/tar_fuzz.c +++ b/lib/tar/test/tar_fuzz.c @@ -8,6 +8,7 @@ #include "io/file.h" #include "tar/tar.h" +#include "common.h" #include #include @@ -23,9 +24,11 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - fp = istream_open_file(argv[1]); - if (fp == NULL) + ret = istream_open_file(&fp, argv[1]); + if (ret) { + sqfs_perror("stdint", NULL, ret); return EXIT_FAILURE; + } for (;;) { ret = read_header(fp, &hdr); diff --git a/lib/tar/test/tar_iterator.c b/lib/tar/test/tar_iterator.c index f51ecd6..8de50ed 100644 --- a/lib/tar/test/tar_iterator.c +++ b/lib/tar/test/tar_iterator.c @@ -36,10 +36,13 @@ int main(int argc, char **argv) char buffer[100]; sqfs_s32 ret; sqfs_s64 ts; + int iret; (void)argc; (void)argv; /* Open the file, create an iterator */ - fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + iret = istream_open_file(&fp, + STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + TEST_EQUAL_I(iret, 0); TEST_NOT_NULL(fp); TEST_EQUAL_UI(((sqfs_object_t *)fp)->refcount, 1); it = tar_open_stream(fp); @@ -106,7 +109,9 @@ int main(int argc, char **argv) sqfs_drop(fp); /* re-open the tar iterator */ - fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + iret = istream_open_file(&fp, + STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + TEST_EQUAL_I(iret, 0); TEST_NOT_NULL(fp); it = tar_open_stream(fp); TEST_NOT_NULL(it); diff --git a/lib/tar/test/tar_iterator2.c b/lib/tar/test/tar_iterator2.c index 7483e81..8826762 100644 --- a/lib/tar/test/tar_iterator2.c +++ b/lib/tar/test/tar_iterator2.c @@ -49,9 +49,12 @@ int main(int argc, char **argv) dir_entry_t *ent; uint64_t offset; sqfs_s32 i, ret; + int iret; (void)argc; (void)argv; - fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + iret = istream_open_file(&fp, + STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + TEST_EQUAL_I(iret, 0); TEST_NOT_NULL(fp); it = tar_open_stream(fp); TEST_NOT_NULL(it); diff --git a/lib/tar/test/tar_iterator3.c b/lib/tar/test/tar_iterator3.c index 11c2fd2..0aee0e3 100644 --- a/lib/tar/test/tar_iterator3.c +++ b/lib/tar/test/tar_iterator3.c @@ -23,7 +23,8 @@ int main(int argc, char **argv) TEST_ASSERT(chdir(TEST_PATH) == 0); - fp = istream_open_file("format-acceptance/link_filled.tar"); + ret = istream_open_file(&fp, "format-acceptance/link_filled.tar"); + TEST_EQUAL_I(ret, 0); TEST_NOT_NULL(fp); TEST_EQUAL_UI(((sqfs_object_t *)fp)->refcount, 1); it = tar_open_stream(fp); diff --git a/lib/tar/test/tar_simple.c b/lib/tar/test/tar_simple.c index a666eb5..8ee5b84 100644 --- a/lib/tar/test/tar_simple.c +++ b/lib/tar/test/tar_simple.c @@ -40,9 +40,11 @@ int main(int argc, char **argv) sqfs_istream_t *fp; char buffer[6]; sqfs_s64 ts; + int ret; (void)argc; (void)argv; - fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + ret = istream_open_file(&fp, STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + TEST_EQUAL_I(ret, 0); TEST_NOT_NULL(fp); TEST_ASSERT(read_header(fp, &hdr) == 0); TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644); diff --git a/lib/tar/test/tar_sparse.c b/lib/tar/test/tar_sparse.c index 99d4639..d93482d 100644 --- a/lib/tar/test/tar_sparse.c +++ b/lib/tar/test/tar_sparse.c @@ -14,8 +14,10 @@ static void test_case_sparse(const char *path) tar_header_decoded_t hdr; sparse_map_t *sparse; sqfs_istream_t *fp; + int ret; - fp = istream_open_file(path); + ret = istream_open_file(&fp, path); + TEST_EQUAL_I(ret, 0); TEST_NOT_NULL(fp); TEST_ASSERT(read_header(fp, &hdr) == 0); TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644); diff --git a/lib/tar/test/tar_sparse_gnu.c b/lib/tar/test/tar_sparse_gnu.c index 675ef9a..6effb52 100644 --- a/lib/tar/test/tar_sparse_gnu.c +++ b/lib/tar/test/tar_sparse_gnu.c @@ -14,11 +14,13 @@ int main(int argc, char **argv) tar_header_decoded_t hdr; sparse_map_t *sparse; sqfs_istream_t *fp; + int ret; (void)argc; (void)argv; TEST_ASSERT(chdir(TEST_PATH) == 0); - fp = istream_open_file("sparse-files/gnu-small.tar"); + ret = istream_open_file(&fp, "sparse-files/gnu-small.tar"); + TEST_EQUAL_I(ret, 0); TEST_NOT_NULL(fp); TEST_ASSERT(read_header(fp, &hdr) == 0); TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644); diff --git a/lib/tar/test/tar_target_filled.c b/lib/tar/test/tar_target_filled.c index 4f061c0..85a1af4 100644 --- a/lib/tar/test/tar_target_filled.c +++ b/lib/tar/test/tar_target_filled.c @@ -14,11 +14,13 @@ int main(int argc, char **argv) tar_header_decoded_t hdr; sqfs_istream_t *fp; char buffer[16]; + int ret; (void)argc; (void)argv; TEST_ASSERT(chdir(TEST_PATH) == 0); - fp = istream_open_file("format-acceptance/link_filled.tar"); + ret = istream_open_file(&fp, "format-acceptance/link_filled.tar"); + TEST_EQUAL_I(ret, 0); TEST_NOT_NULL(fp); /* "deep" directory hierarchy containg 2 files */ diff --git a/lib/tar/test/tar_write_simple.c b/lib/tar/test/tar_write_simple.c index ca8d1e5..28f199f 100644 --- a/lib/tar/test/tar_write_simple.c +++ b/lib/tar/test/tar_write_simple.c @@ -188,7 +188,8 @@ int main(int argc, char **argv) TEST_EQUAL_UI(wr_offset, sizeof(wr_buffer)); TEST_EQUAL_UI(sizeof(rd_buffer), sizeof(wr_buffer)); - fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + ret = istream_open_file(&fp, STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + TEST_EQUAL_I(ret, 0); TEST_NOT_NULL(fp); ret = sqfs_istream_read(fp, rd_buffer, sizeof(rd_buffer)); diff --git a/lib/tar/test/tar_xattr.c b/lib/tar/test/tar_xattr.c index 26a2cd0..0e0579c 100644 --- a/lib/tar/test/tar_xattr.c +++ b/lib/tar/test/tar_xattr.c @@ -15,9 +15,11 @@ int main(int argc, char **argv) tar_header_decoded_t hdr; sqfs_istream_t *fp; char buffer[6]; + int ret; (void)argc; (void)argv; - fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + ret = istream_open_file(&fp, STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + TEST_EQUAL_I(ret, 0); TEST_NOT_NULL(fp); TEST_ASSERT(read_header(fp, &hdr) == 0); TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644); diff --git a/lib/tar/test/tar_xattr_bin.c b/lib/tar/test/tar_xattr_bin.c index 94c8d76..617c356 100644 --- a/lib/tar/test/tar_xattr_bin.c +++ b/lib/tar/test/tar_xattr_bin.c @@ -23,9 +23,11 @@ int main(int argc, char **argv) tar_header_decoded_t hdr; sqfs_istream_t *fp; char buffer[6]; + int ret; (void)argc; (void)argv; - fp = istream_open_file(STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + ret = istream_open_file(&fp, STRVALUE(TESTPATH) "/" STRVALUE(TESTFILE)); + TEST_EQUAL_I(ret, 0); TEST_NOT_NULL(fp); TEST_ASSERT(read_header(fp, &hdr) == 0); TEST_EQUAL_UI(hdr.mode, S_IFREG | 0644); diff --git a/lib/util/test/str_table.c b/lib/util/test/str_table.c index 75658ef..4a62b59 100644 --- a/lib/util/test/str_table.c +++ b/lib/util/test/str_table.c @@ -21,7 +21,8 @@ static int read_strings(void) char *line; int i; - fp = istream_open_file("words.txt"); + i = istream_open_file(&fp, "words.txt"); + TEST_EQUAL_I(i, 0); TEST_NOT_NULL(fp); for (i = 0; i < 1000; ++i) { -- cgit v1.2.3