chiark / gitweb /
journald: increase rate limit burst rate
[elogind.git] / src / journal / journal-file.c
index a0c479fc676983a5989664a7844e41802d4ee7a8..6c7718de3126018483b3efbc5f2c797549c691cc 100644 (file)
@@ -241,6 +241,10 @@ static int journal_file_map(
         wsize = size + (offset - woffset);
         wsize = PAGE_ALIGN(wsize);
 
+        /* Avoid SIGBUS on invalid accesses */
+        if (woffset + wsize > (uint64_t) PAGE_ALIGN(f->last_stat.st_size))
+                return -EADDRNOTAVAIL;
+
         window = mmap(NULL, wsize, f->prot, MAP_SHARED, f->fd, woffset);
         if (window == MAP_FAILED)
                 return -errno;
@@ -305,6 +309,15 @@ static int journal_file_move_to(JournalFile *f, int wt, uint64_t offset, uint64_
         } else
                 delta = 0;
 
+        if (offset > (uint64_t) f->last_stat.st_size)
+                return -EADDRNOTAVAIL;
+
+        if (offset + size > (uint64_t) f->last_stat.st_size)
+                size = PAGE_ALIGN((uint64_t) f->last_stat.st_size - offset);
+
+        if (size <= 0)
+                return -EADDRNOTAVAIL;
+
         r = journal_file_map(f,
                              offset, size,
                              &w->ptr, &w->offset, &w->size,
@@ -595,7 +608,7 @@ int journal_file_find_data_object_with_hash(
                         return r;
 
                 if (le64toh(o->data.hash) != hash)
-                        return -EBADMSG;
+                        goto next;
 
                 if (o->object.flags & OBJECT_COMPRESSED) {
 #ifdef HAVE_XZ
@@ -637,6 +650,7 @@ int journal_file_find_data_object_with_hash(
                         return 1;
                 }
 
+        next:
                 p = le64toh(o->data.next_hash_offset);
         }
 
@@ -1218,7 +1232,6 @@ static int generic_array_bisect_plus_one(JournalFile *f,
 
         /* This bisects the array in object 'first', but first checks
          * an extra  */
-
         r = test_object(f, extra, needle);
         if (r < 0)
                 return r;
@@ -1234,6 +1247,11 @@ static int generic_array_bisect_plus_one(JournalFile *f,
 
                 if (offset)
                         *offset = extra;
+
+                if (idx)
+                        *idx = 0;
+
+                return 1;
         } else if (r == TEST_RIGHT)
                 return 0;