Blob Blame History Raw
From 6392180b7a11f2177be9e6411e3fd4bd79237d81 Mon Sep 17 00:00:00 2001
From: Thomas Hindoe Paaboel Andersen <phomes@gmail.com>
Date: Mon, 16 Dec 2013 23:35:30 +0100
Subject: [PATCH] journal-file: protect against alloca(0)

(cherry picked from commit 4faa70046ca0c1775c8e231179716a78cf3291b1)
---
 src/journal/journal-file.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 090cf9771e..8ea258bdfb 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -2737,7 +2737,8 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6
         ts.realtime = le64toh(o->entry.realtime);
 
         n = journal_file_entry_n_items(o);
-        items = alloca(sizeof(EntryItem) * n);
+        /* alloca() can't take 0, hence let's allocate at least one */
+        items = alloca(sizeof(EntryItem) * MAX(1u, n));
 
         for (i = 0; i < n; i++) {
                 uint64_t l, h;