[systemd-commits] 2 commits - src/journal

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Tue Mar 4 21:20:04 PST 2014


 src/journal/journal-file.c |   26 ++++++++++++++++++++------
 src/journal/sd-journal.c   |   16 ++++++++++++----
 2 files changed, 32 insertions(+), 10 deletions(-)

New commits:
commit a9a245c128af6c0418085062c60251bc51fa4a94
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Feb 27 00:11:54 2014 -0500

    journal: forget file after encountering an error
    
    If we encounter an inconsistency in a file, let's just
    ignore it. Otherwise, after previous patch, we would try,
    and fail, to use this file in every invocation of sd_journal_next
    or sd_journal_previous that happens afterwards.

diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index ef455e9..b54bc21 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -51,6 +51,8 @@
 
 #define DEFAULT_DATA_THRESHOLD (64*1024)
 
+static void remove_file_real(sd_journal *j, JournalFile *f);
+
 static bool journal_pid_changed(sd_journal *j) {
         assert(j);
 
@@ -885,6 +887,7 @@ static int real_journal_next(sd_journal *j, direction_t direction) {
                 r = next_beyond_location(j, f, direction, &o, &p);
                 if (r < 0) {
                         log_debug("Can't iterate through %s, ignoring: %s", f->path, strerror(-r));
+                        remove_file_real(j, f);
                         continue;
                 } else if (r == 0)
                         continue;
@@ -1339,7 +1342,7 @@ static int add_file(sd_journal *j, const char *prefix, const char *filename) {
 }
 
 static int remove_file(sd_journal *j, const char *prefix, const char *filename) {
-        char *path;
+        _cleanup_free_ char *path;
         JournalFile *f;
 
         assert(j);
@@ -1351,10 +1354,17 @@ static int remove_file(sd_journal *j, const char *prefix, const char *filename)
                 return -ENOMEM;
 
         f = hashmap_get(j->files, path);
-        free(path);
         if (!f)
                 return 0;
 
+        remove_file_real(j, f);
+        return 0;
+}
+
+static void remove_file_real(sd_journal *j, JournalFile *f) {
+        assert(j);
+        assert(f);
+
         hashmap_remove(j->files, f->path);
 
         log_debug("File %s removed.", f->path);
@@ -1372,8 +1382,6 @@ static int remove_file(sd_journal *j, const char *prefix, const char *filename)
         journal_file_close(f);
 
         j->current_invalidate_counter ++;
-
-        return 0;
 }
 
 static int add_directory(sd_journal *j, const char *prefix, const char *dirname) {

commit fb099c8d2af6620db2709e826a258089d10cdfe8
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Thu Feb 27 00:07:29 2014 -0500

    journal: assume that next entry is after previous entry
    
    With a corrupted file, we can get in a situation where two entries
    in the entry array point to the same object. Then journal_file_next_entry
    will find the first one using generic_arrray_bisect, and try to move to
    the second one, but since the address is the same, generic_array_get will
    return the first one. journal_file_next_entry ends up in an infinite loop.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1047039

diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 5876733..0e1fc7f 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -1359,7 +1359,7 @@ int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const st
 }
 
 typedef struct ChainCacheItem {
-        uint64_t first; /* the array at the begin of the chain */
+        uint64_t first; /* the array at the beginning of the chain */
         uint64_t array; /* the cached array */
         uint64_t begin; /* the first item in the cached array */
         uint64_t total; /* the total number of items in all arrays before this one in the chain */
@@ -1945,7 +1945,7 @@ int journal_file_next_entry(
                 direction_t direction,
                 Object **ret, uint64_t *offset) {
 
-        uint64_t i, n;
+        uint64_t i, n, ofs;
         int r;
 
         assert(f);
@@ -1986,10 +1986,24 @@ int journal_file_next_entry(
         }
 
         /* And jump to it */
-        return generic_array_get(f,
-                                 le64toh(f->header->entry_array_offset),
-                                 i,
-                                 ret, offset);
+        r = generic_array_get(f,
+                              le64toh(f->header->entry_array_offset),
+                              i,
+                              ret, &ofs);
+        if (r <= 0)
+                return r;
+
+        if (p > 0 &&
+            (direction == DIRECTION_DOWN ? ofs <= p : ofs >= p)) {
+                log_debug("%s: entry array corrupted at entry %"PRIu64,
+                          f->path, i);
+                return -EBADMSG;
+        }
+
+        if (offset)
+                *offset = ofs;
+
+        return 1;
 }
 
 int journal_file_skip_entry(



More information about the systemd-commits mailing list