chiark / gitweb /
journal: fix bad memory access
[elogind.git] / src / journal / journal-file.c
index 73420d9c1b17530cd7aecb07d04702026d3addb7..83f603ac821b0af1ac521a6b8b992bd754ffe362 100644 (file)
@@ -1275,7 +1275,11 @@ static int generic_array_bisect_plus_one(JournalFile *f,
         r = test_object(f, extra, needle);
         if (r < 0)
                 return r;
-        else if (r == TEST_FOUND) {
+
+        if (r == TEST_FOUND)
+                r = direction == DIRECTION_DOWN ? TEST_RIGHT : TEST_LEFT;
+
+        if (r == TEST_RIGHT) {
                 Object *o;
 
                 r = journal_file_move_to_object(f, OBJECT_ENTRY, extra, &o);
@@ -1292,12 +1296,11 @@ static int generic_array_bisect_plus_one(JournalFile *f,
                         *idx = 0;
 
                 return 1;
-        } else if (r == TEST_RIGHT)
-                return 0;
+        }
 
         r = generic_array_bisect(f, first, n-1, needle, test_object, direction, ret, offset, idx);
 
-        if (r > 0)
+        if (r > 0 && idx)
                 (*idx) ++;
 
         return r;
@@ -1400,11 +1403,11 @@ int journal_file_move_to_entry_by_monotonic(
                 Object **ret,
                 uint64_t *offset) {
 
-        char t[8+32+1] = "_BOOT_ID=";
+        char t[9+32+1] = "_BOOT_ID=";
         Object *o;
         int r;
 
-        sd_id128_to_string(boot_id, t + 8);
+        sd_id128_to_string(boot_id, t + 9);
 
         r = journal_file_find_data_object(f, t, strlen(t), &o, NULL);
         if (r < 0)