journal-file: avoid risky subtraction when validity checking object

The value might change beneath what we do, and hence let's avoid any
chance of underflow.
This commit is contained in:
Lennart Poettering
2020-04-23 12:12:17 +02:00
parent ed50f18c4d
commit 20ee282bb7
+2 -2
View 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),