From: Lennart Poettering Date: Wed, 13 Oct 2021 10:07:52 +0000 (+0200) Subject: tree-wide: port all calls to alloca() to alloca_safe() X-Git-Tag: v250-rc1~504^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=698cec65c43e8336265f25ee39a5b75eabd081df;p=thirdparty%2Fsystemd.git tree-wide: port all calls to alloca() to alloca_safe() --- diff --git a/src/core/automount.c b/src/core/automount.c index 11eb352b9b5..5a004f82d52 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -365,7 +365,7 @@ static int open_ioctl_fd(int dev_autofs_fd, const char *where, dev_t devid) { assert(where); l = sizeof(struct autofs_dev_ioctl) + strlen(where) + 1; - param = alloca(l); + param = alloca_safe(l); init_autofs_dev_ioctl(param); param->size = l; diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 0eb27b88b29..daa7c7e45e1 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -1874,13 +1874,13 @@ static int setup_keys(void) { return log_oom(); mpk_size = FSPRG_mskinbytes(FSPRG_RECOMMENDED_SECPAR); - mpk = alloca(mpk_size); + mpk = alloca_safe(mpk_size); seed_size = FSPRG_RECOMMENDED_SEEDLEN; - seed = alloca(seed_size); + seed = alloca_safe(seed_size); state_size = FSPRG_stateinbytes(FSPRG_RECOMMENDED_SECPAR); - state = alloca(state_size); + state = alloca_safe(state_size); log_info("Generating seed..."); r = genuine_random_bytes(seed, seed_size, RANDOM_BLOCK); diff --git a/src/libsystemd/sd-journal/journal-authenticate.c b/src/libsystemd/sd-journal/journal-authenticate.c index 0bfe9f7f477..0ff25c1f472 100644 --- a/src/libsystemd/sd-journal/journal-authenticate.c +++ b/src/libsystemd/sd-journal/journal-authenticate.c @@ -182,14 +182,13 @@ int journal_file_fsprg_seek(JournalFile *f, uint64_t goal) { } else { f->fsprg_state_size = FSPRG_stateinbytes(FSPRG_RECOMMENDED_SECPAR); f->fsprg_state = malloc(f->fsprg_state_size); - if (!f->fsprg_state) return -ENOMEM; } log_debug("Seeking FSPRG key to %"PRIu64".", goal); - msk = alloca(FSPRG_mskinbytes(FSPRG_RECOMMENDED_SECPAR)); + msk = alloca_safe(FSPRG_mskinbytes(FSPRG_RECOMMENDED_SECPAR)); FSPRG_GenMK(msk, NULL, f->fsprg_seed, f->fsprg_seed_size, FSPRG_RECOMMENDED_SECPAR); FSPRG_Seek(f->fsprg_state, goal, msk, f->fsprg_seed, f->fsprg_seed_size); return 0; diff --git a/src/libsystemd/sd-journal/journal-send.c b/src/libsystemd/sd-journal/journal-send.c index fd3fd7ef9c9..42178251563 100644 --- a/src/libsystemd/sd-journal/journal-send.c +++ b/src/libsystemd/sd-journal/journal-send.c @@ -96,7 +96,7 @@ _public_ int sd_journal_printv(int priority, const char *format, va_list ap) { /* Allocate large buffer to accommodate big message */ if (len >= LINE_MAX) { - buffer = alloca(len + 9); + buffer = alloca_safe(len + 9); memcpy(buffer, "MESSAGE=", 8); assert_se(vsnprintf(buffer + 8, len + 1, format, ap) == len); } @@ -472,7 +472,7 @@ _public_ int sd_journal_printv_with_location(int priority, const char *file, con /* Allocate large buffer to accommodate big message */ if (len >= LINE_MAX) { - buffer = alloca(len + 9); + buffer = alloca_safe(len + 9); memcpy(buffer, "MESSAGE=", 8); assert_se(vsnprintf(buffer + 8, len + 1, format, ap) == len); } diff --git a/src/shared/firewall-util-iptables.c b/src/shared/firewall-util-iptables.c index d53a394895a..55bb427e7bf 100644 --- a/src/shared/firewall-util-iptables.c +++ b/src/shared/firewall-util-iptables.c @@ -128,7 +128,7 @@ int fw_iptables_add_masquerade( mr->rangesize = 1; /* Create a search mask entry */ - mask = alloca(sz); + mask = alloca_safe(sz); memset(mask, 0xFF, sz); if (add) { diff --git a/src/shared/nscd-flush.c b/src/shared/nscd-flush.c index 19e16d93455..06550306338 100644 --- a/src/shared/nscd-flush.c +++ b/src/shared/nscd-flush.c @@ -35,7 +35,7 @@ static int nscd_flush_cache_one(const char *database, usec_t end) { l = strlen(database); req_size = offsetof(struct nscdInvalidateRequest, dbname) + l + 1; - req = alloca(req_size); + req = alloca_safe(req_size); *req = (struct nscdInvalidateRequest) { .version = 2, .type = 10,