]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-file: avoid risky subtraction when validity checking object
authorLennart Poettering <lennart@poettering.net>
Thu, 23 Apr 2020 08:45:31 +0000 (10:45 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 23 Apr 2020 10:12:17 +0000 (12:12 +0200)
The value might change beneath what we do, and hence let's avoid any
chance of underflow.

src/journal/journal-file.c

index bd5363586077bda3a7d3b724a70ccbe098807935..b823a3850e29c428301889176f6b30fc6f3ec0fe 100644 (file)
@@ -760,7 +760,7 @@ static int journal_file_check_object(JournalFile *f, uint64_t offset, Object *o)
                                                le64toh(o->data.n_entries),
                                                offset);
 
-                if (le64toh(o->object.size) - offsetof(DataObject, payload) <= 0)
+                if (le64toh(o->object.size) <= offsetof(DataObject, payload))
                         return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
                                                "Bad object size (<= %zu): %" PRIu64 ": %" PRIu64,
                                                offsetof(DataObject, payload),
@@ -782,7 +782,7 @@ static int journal_file_check_object(JournalFile *f, uint64_t offset, Object *o)
                 break;
 
         case OBJECT_FIELD:
-                if (le64toh(o->object.size) - offsetof(FieldObject, payload) <= 0)
+                if (le64toh(o->object.size) <= offsetof(FieldObject, payload))
                         return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
                                                "Bad field size (<= %zu): %" PRIu64 ": %" PRIu64,
                                                offsetof(FieldObject, payload),