chiark / gitweb /
journal-file: protect against alloca(0)
authorThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Mon, 16 Dec 2013 22:35:30 +0000 (23:35 +0100)
committerThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Mon, 16 Dec 2013 22:37:38 +0000 (23:37 +0100)
src/journal/journal-file.c

index 4009b29b4603fbb92888d25fe84f82dffe543a68..48fdb6163aec5a1989dd4186d2d33483db56455f 100644 (file)
@@ -2730,7 +2730,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;