From 49aca3b1525ff2273b4d61d52a9bb1347b48bd5f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 16 Jul 2019 14:52:07 +0200 Subject: [PATCH 1/2] activate: move array allocation to heap In theory 'n' could get quite large, and some sanitizers notice that, let's hence avoid the stack, and use the heap instead. Moreover, there's no need to include the first 3 fds in the array, close_all() excludes those anyway. See: #13064 --- src/activate/activate.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/activate/activate.c b/src/activate/activate.c index 15a3150666..2fe312f5a0 100644 --- a/src/activate/activate.c +++ b/src/activate/activate.c @@ -49,8 +49,7 @@ static int add_epoll(int epoll_fd, int fd) { static int open_sockets(int *epoll_fd, bool accept) { char **address; - int n, fd, r; - int count = 0; + int n, fd, r, count = 0; n = sd_listen_fds(true); if (n < 0) @@ -69,13 +68,18 @@ static int open_sockets(int *epoll_fd, bool accept) { /* Close logging and all other descriptors */ if (arg_listen) { - int except[3 + n]; + _cleanup_free_ int *except = NULL; + int i; - for (fd = 0; fd < SD_LISTEN_FDS_START + n; fd++) - except[fd] = fd; + except = new(int, n); + if (!except) + return log_oom(); + + for (i = 0; i < n; i++) + except[i] = SD_LISTEN_FDS_START + i; log_close(); - r = close_all_fds(except, 3 + n); + r = close_all_fds(except, n); if (r < 0) return log_error_errno(r, "Failed to close all file descriptors: %m"); } From 4094c4bfb770f5e3045cc6da88b9b8de74aa027d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 16 Jul 2019 15:22:26 +0200 Subject: [PATCH 2/2] journal: properly read unaligned le64 integers Fixes: #13051 Replaces: #13064 --- src/journal/compress.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/journal/compress.c b/src/journal/compress.c index 7a79e566b8..bfb75ae8c9 100644 --- a/src/journal/compress.c +++ b/src/journal/compress.c @@ -26,6 +26,7 @@ #include "sparse-endian.h" #include "string-table.h" #include "string-util.h" +#include "unaligned.h" #include "util.h" #if HAVE_LZ4 @@ -101,7 +102,7 @@ int compress_blob_lz4(const void *src, uint64_t src_size, if (r <= 0) return -ENOBUFS; - *(le64_t*) dst = htole64(src_size); + unaligned_write_le64(dst, src_size); *dst_size = r + 8; return 0; @@ -187,8 +188,8 @@ int decompress_blob_lz4(const void *src, uint64_t src_size, if (src_size <= 8) return -EBADMSG; - size = le64toh( *(le64_t*)src ); - if (size < 0 || (unsigned) size != le64toh(*(le64_t*)src)) + size = unaligned_read_le64(src); + if (size < 0 || (unsigned) size != unaligned_read_le64(src)) return -EFBIG; if ((size_t) size > *dst_alloc_size) { out = realloc(*dst, size);