aboutsummaryrefslogtreecommitdiffstats
path: root/executor
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2022-11-22 12:08:21 +0100
committerDmitry Vyukov <dvyukov@google.com>2022-11-23 09:09:39 +0100
commit1c50689b39eb028d91a28951b8300b7970a2aca5 (patch)
tree84cd6ab7f5fb0d87ed334a59ad3949df35afb5ab /executor
parentcaddc6cbcef9933a4539a06714df006e0c5ac7b2 (diff)
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.
Diffstat (limited to 'executor')
-rw-r--r--executor/common_linux.h6
-rw-r--r--executor/common_zlib.h21
2 files changed, 14 insertions, 13 deletions
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 <errno.h>
#include <sys/mman.h>
#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);
}