Zbigniew Jędrzejewski-Szmek d743bb
From f88105d528645b5c99dbe5dcbd0300948a01c9c9 Mon Sep 17 00:00:00 2001
Zbigniew Jędrzejewski-Szmek d743bb
From: Yusuke Nojima <nojima718@gmail.com>
Zbigniew Jędrzejewski-Szmek d743bb
Date: Sun, 30 Apr 2017 02:37:53 +0900
Zbigniew Jędrzejewski-Szmek d743bb
Subject: [PATCH] journald: fix assertion failure on journal_file_link_data.
Zbigniew Jędrzejewski-Szmek d743bb
 (#5843)
Zbigniew Jędrzejewski-Szmek d743bb
Zbigniew Jędrzejewski-Szmek d743bb
When some error occurs during the initialization of JournalFile,
Zbigniew Jędrzejewski-Szmek d743bb
the JournalFile can be left without hash tables created.  When later
Zbigniew Jędrzejewski-Szmek d743bb
trying to append an entry to that file, the assertion in
Zbigniew Jędrzejewski-Szmek d743bb
journal_file_link_data() fails, and journald crashes.
Zbigniew Jędrzejewski-Szmek d743bb
Zbigniew Jędrzejewski-Szmek d743bb
This patch fix this issue by checking *_hash_table_size in
Zbigniew Jędrzejewski-Szmek d743bb
journal_file_verify_header().
Zbigniew Jędrzejewski-Szmek d743bb
(cherry picked from commit 5b3cc0c86aeddd4615e7e28e79aa89e5b77a6507)
Zbigniew Jędrzejewski-Szmek d743bb
---
Zbigniew Jędrzejewski-Szmek d743bb
 src/journal/journal-file.c | 3 +++
Zbigniew Jędrzejewski-Szmek d743bb
 1 file changed, 3 insertions(+)
Zbigniew Jędrzejewski-Szmek d743bb
Zbigniew Jędrzejewski-Szmek d743bb
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
Zbigniew Jędrzejewski-Szmek d743bb
index 14cb01a600..243d5198d9 100644
Zbigniew Jędrzejewski-Szmek d743bb
--- a/src/journal/journal-file.c
Zbigniew Jędrzejewski-Szmek d743bb
+++ b/src/journal/journal-file.c
Zbigniew Jędrzejewski-Szmek d743bb
@@ -613,6 +613,9 @@ static int journal_file_verify_header(JournalFile *f) {
Zbigniew Jędrzejewski-Szmek d743bb
                         return -EBUSY;
Zbigniew Jędrzejewski-Szmek d743bb
                 }
Zbigniew Jędrzejewski-Szmek d743bb
 
Zbigniew Jędrzejewski-Szmek d743bb
+                if (f->header->field_hash_table_size == 0 || f->header->data_hash_table_size == 0)
Zbigniew Jędrzejewski-Szmek d743bb
+                        return -EBADMSG;
Zbigniew Jędrzejewski-Szmek d743bb
+
Zbigniew Jędrzejewski-Szmek d743bb
                 /* Don't permit appending to files from the future. Because otherwise the realtime timestamps wouldn't
Zbigniew Jędrzejewski-Szmek d743bb
                  * be strictly ordered in the entries in the file anymore, and we can't have that since it breaks
Zbigniew Jędrzejewski-Szmek d743bb
                  * bisection. */