ryantimwilson / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone
65878a
From d3bf15d0b7c461aae4d97fe6425a6f0cea277222 Mon Sep 17 00:00:00 2001
65878a
From: Thomas Hindoe Paaboel Andersen <phomes@gmail.com>
65878a
Date: Mon, 16 Dec 2013 23:35:30 +0100
65878a
Subject: [PATCH] journal-file: protect against alloca(0)
65878a
65878a
---
65878a
 src/journal/journal-file.c | 3 ++-
65878a
 1 file changed, 2 insertions(+), 1 deletion(-)
65878a
65878a
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
65878a
index 962cdd6..ebf72f3 100644
65878a
--- a/src/journal/journal-file.c
65878a
+++ b/src/journal/journal-file.c
65878a
@@ -2730,7 +2730,8 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6
65878a
         ts.realtime = le64toh(o->entry.realtime);
65878a
 
65878a
         n = journal_file_entry_n_items(o);
65878a
-        items = alloca(sizeof(EntryItem) * n);
65878a
+        /* alloca() can't take 0, hence let's allocate at least one */
65878a
+        items = alloca(sizeof(EntryItem) * MAX(1u, n));
65878a
 
65878a
         for (i = 0; i < n; i++) {
65878a
                 uint64_t l, h;