richardphibel / rpms / systemd

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