794d16c
From c9cceff90794d452b16a5dd8d1c53cdb44f4a002 Mon Sep 17 00:00:00 2001
794d16c
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
794d16c
Date: Wed, 9 Oct 2013 22:13:13 -0400
794d16c
Subject: [PATCH] journald: remove rotated file from hashmap when rotation
794d16c
 fails
794d16c
794d16c
Before, when the user journal file was rotated, journal_file_rotate
794d16c
could close the old file and fail to open the new file. In that
794d16c
case, we would leave the old (deallocated) file in the hashmap.
794d16c
On subsequent accesses, we could retrieve this stale entry, leading
794d16c
to a segfault.
794d16c
794d16c
When journal_file_rotate fails with the file pointer set to 0,
794d16c
old file is certainly gone, and cannot be used anymore.
794d16c
794d16c
https://bugzilla.redhat.com/show_bug.cgi?id=890463
794d16c
---
794d16c
 src/journal/journald-server.c | 4 +++-
794d16c
 1 file changed, 3 insertions(+), 1 deletion(-)
794d16c
794d16c
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
794d16c
index 4f47eb1..e03e413 100644
794d16c
--- a/src/journal/journald-server.c
794d16c
+++ b/src/journal/journald-server.c
794d16c
@@ -321,8 +321,10 @@ void server_rotate(Server *s) {
794d16c
                 if (r < 0)
794d16c
                         if (f)
794d16c
                                 log_error("Failed to rotate %s: %s", f->path, strerror(-r));
794d16c
-                        else
794d16c
+                        else {
794d16c
                                 log_error("Failed to create user journal: %s", strerror(-r));
794d16c
+                                hashmap_remove(s->user_journals, k);
794d16c
+                        }
794d16c
                 else {
794d16c
                         hashmap_replace(s->user_journals, k, f);
794d16c
                         server_fix_perms(s, f, PTR_TO_UINT32(k));
794d16c
-- 
794d16c
1.8.4.652.g0d6e0ce
794d16c