From 1c50689b39eb028d91a28951b8300b7970a2aca5 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 22 Nov 2022 12:08:21 +0100 Subject: executor: fix puff_zlib_to_file signature In executor code we commonly use the syscall interface for functions: return -1 on erorr and set errno. Use this interface for puff_zlib_to_file. --- executor/common_linux.h | 6 +++--- executor/common_zlib.h | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) (limited to 'executor') diff --git a/executor/common_linux.h b/executor/common_linux.h index e0537e062..40d2ad894 100644 --- a/executor/common_linux.h +++ b/executor/common_linux.h @@ -2910,9 +2910,9 @@ static int setup_loop_device(long unsigned size, long unsigned compressed_size, goto error_close_memfd; } - err = puff_zlib_to_file(data, compressed_size, memfd, size); - if (err) { - debug("setup_loop_device: could not decompress data: %d\n", err); + if (puff_zlib_to_file(data, compressed_size, memfd, size)) { + err = errno; + debug("setup_loop_device: could not decompress data: %d\n", errno); goto error_close_memfd; } diff --git a/executor/common_zlib.h b/executor/common_zlib.h index e122f2dd0..d5fd480d3 100644 --- a/executor/common_zlib.h +++ b/executor/common_zlib.h @@ -499,6 +499,7 @@ static int puff( //% END CODE DERIVED FROM puff.{c,h} +#include #include #define ZLIB_HEADER_WIDTH 2 // Two-byte zlib header width. @@ -509,27 +510,27 @@ static int puff_zlib_to_file( unsigned long destlen) { // Ignore zlib header. - if (sourcelen < ZLIB_HEADER_WIDTH) - return -12; // use next available negative return value + if (sourcelen < ZLIB_HEADER_WIDTH) { + errno = EMSGSIZE; + return -1; + } source += ZLIB_HEADER_WIDTH; sourcelen -= ZLIB_HEADER_WIDTH; // Memory-map destination file dest_fd. void* ret = mmap(0, destlen, PROT_WRITE | PROT_READ, MAP_SHARED, dest_fd, 0); if (ret == MAP_FAILED) - return -13; // use next available negative return value + return -1; unsigned char* dest = (unsigned char*)ret; // Inflate source array to destination file. unsigned long destlen_copy = destlen; // copy destlen as puff() may modify it int err = puff(dest, &destlen_copy, source, &sourcelen); - if (err) - return err; + if (err) { + errno = -err; + return -1; + } // Unmap memory-mapped region - err = munmap(dest, destlen); - if (err) - return -14; // use next available negative return value - - return 0; + return munmap(dest, destlen); } -- cgit mrf-deployment