diff options
-rw-r--r-- | src/journal/journal-def.h | 2 | ||||
-rw-r--r-- | src/journal/journal-file.c | 8 | ||||
-rw-r--r-- | src/journal/journal-file.h | 1 | ||||
-rw-r--r-- | src/journal/journal-verify.c | 18 |
4 files changed, 29 insertions, 0 deletions
diff --git a/src/journal/journal-def.h b/src/journal/journal-def.h index 45c3cde9f0..8f00176bd7 100644 --- a/src/journal/journal-def.h +++ b/src/journal/journal-def.h @@ -188,6 +188,8 @@ _packed_ struct Header { /* Added in 189 */ le64_t n_tags; le64_t n_entry_arrays; + + /* Size: 224 */ }; #define FSS_HEADER_SIGNATURE ((char[]) { 'K', 'S', 'H', 'H', 'R', 'H', 'L', 'P' }) diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index e04ffd0452..df991a4a07 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -798,6 +798,14 @@ uint64_t journal_file_entry_array_n_items(Object *o) { return (le64toh(o->object.size) - offsetof(Object, entry_array.items)) / sizeof(uint64_t); } +uint64_t journal_file_hash_table_n_items(Object *o) { + assert(o); + assert(o->object.type == OBJECT_DATA_HASH_TABLE || + o->object.type == OBJECT_FIELD_HASH_TABLE); + + return (le64toh(o->object.size) - offsetof(Object, hash_table.items)) / sizeof(HashItem); +} + static int link_entry_into_array(JournalFile *f, le64_t *first, le64_t *idx, diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h index 2d2bf319a0..e2ef03347c 100644 --- a/src/journal/journal-file.h +++ b/src/journal/journal-file.h @@ -126,6 +126,7 @@ int journal_file_move_to_object(JournalFile *f, int type, uint64_t offset, Objec uint64_t journal_file_entry_n_items(Object *o); uint64_t journal_file_entry_array_n_items(Object *o); +uint64_t journal_file_hash_table_n_items(Object *o); int journal_file_append_object(JournalFile *f, int type, uint64_t size, Object **ret, uint64_t *offset); int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const struct iovec iovec[], unsigned n_iovec, uint64_t *seqno, Object **ret, uint64_t *offset); diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c index e3bd8ffbd7..a31817671b 100644 --- a/src/journal/journal-verify.c +++ b/src/journal/journal-verify.c @@ -134,6 +134,19 @@ static int journal_file_object_verify(JournalFile *f, Object *o) { if ((le64toh(o->object.size) - offsetof(HashTableObject, items)) / sizeof(HashItem) <= 0) return -EBADMSG; + for (i = 0; i < journal_file_hash_table_n_items(o); i++) { + if (o->hash_table.items[i].head_hash_offset != 0 && + !VALID64(le64toh(o->hash_table.items[i].head_hash_offset))) + return -EBADMSG; + if (o->hash_table.items[i].tail_hash_offset != 0 && + !VALID64(le64toh(o->hash_table.items[i].tail_hash_offset))) + return -EBADMSG; + + if ((o->hash_table.items[i].head_hash_offset != 0) != + (o->hash_table.items[i].tail_hash_offset != 0)) + return -EBADMSG; + } + break; case OBJECT_ENTRY_ARRAY: @@ -146,6 +159,11 @@ static int journal_file_object_verify(JournalFile *f, Object *o) { if (!VALID64(o->entry_array.next_entry_array_offset)) return -EBADMSG; + for (i = 0; i < journal_file_entry_array_n_items(o); i++) + if (o->entry_array.items[i] != 0 && + !VALID64(o->entry_array.items[i])) + return -EBADMSG; + break; case OBJECT_TAG: |