summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2021-11-16 14:39:18 +0000
committerDaan De Meyer <daan.j.demeyer@gmail.com>2021-11-19 17:12:29 +0000
commit368a14b67bb51921642d49049af995bc10814058 (patch)
treeaddbd87f6513bff61e8ca6ba11303f8e92485c69
parent363b2b9aaff14f238b0ae19beb97665a19e45c81 (diff)
downloadsystemd-368a14b67bb51921642d49049af995bc10814058.tar.gz
journal: Add verify_hash_table()
The existing verify_hash_table() function is renamed to verify_data_hash_table() since it only verifies the data hash table. The verify information is also made a little more detailed by splitting one of the checks in two.
-rw-r--r--src/libsystemd/sd-journal/journal-verify.c84
1 files changed, 52 insertions, 32 deletions
diff --git a/src/libsystemd/sd-journal/journal-verify.c b/src/libsystemd/sd-journal/journal-verify.c
index dbea50fd70..acb1b4c7e8 100644
--- a/src/libsystemd/sd-journal/journal-verify.c
+++ b/src/libsystemd/sd-journal/journal-verify.c
@@ -591,7 +591,7 @@ static int verify_data(
return 0;
}
-static int verify_hash_table(
+static int verify_data_hash_table(
JournalFile *f,
MMapFileDescriptor *cache_data_fd, uint64_t n_data,
MMapFileDescriptor *cache_entry_fd, uint64_t n_entries,
@@ -824,6 +824,43 @@ static int verify_entry_array(
return 0;
}
+static int verify_hash_table(
+ Object *o, uint64_t p, uint64_t *n_hash_tables, uint64_t header_offset, uint64_t header_size) {
+
+ assert(o);
+ assert(n_hash_tables);
+
+ if (*n_hash_tables > 1) {
+ error(p,
+ "More than one %s: %" PRIu64,
+ journal_object_type_to_string(o->object.type),
+ *n_hash_tables);
+ return -EBADMSG;
+ }
+
+ if (header_offset != p + offsetof(HashTableObject, items)) {
+ error(p,
+ "Header offset for %s invalid (%" PRIu64 " != %" PRIu64 ")",
+ journal_object_type_to_string(o->object.type),
+ header_offset,
+ p + offsetof(HashTableObject, items));
+ return -EBADMSG;
+ }
+
+ if (header_size != le64toh(o->object.size) - offsetof(HashTableObject, items)) {
+ error(p,
+ "Header size for %s invalid (%" PRIu64 " != %" PRIu64 ")",
+ journal_object_type_to_string(o->object.type),
+ header_size,
+ le64toh(o->object.size) - offsetof(HashTableObject, items));
+ return -EBADMSG;
+ }
+
+ (*n_hash_tables)++;
+
+ return 0;
+}
+
int journal_file_verify(
JournalFile *f,
const char *key,
@@ -1069,37 +1106,20 @@ int journal_file_verify(
break;
case OBJECT_DATA_HASH_TABLE:
- if (n_data_hash_tables > 1) {
- error(p, "More than one data hash table");
- r = -EBADMSG;
- goto fail;
- }
-
- if (le64toh(f->header->data_hash_table_offset) != p + offsetof(HashTableObject, items) ||
- le64toh(f->header->data_hash_table_size) != le64toh(o->object.size) - offsetof(HashTableObject, items)) {
- error(p, "header fields for data hash table invalid");
- r = -EBADMSG;
+ r = verify_hash_table(o, p, &n_data_hash_tables,
+ le64toh(f->header->data_hash_table_offset),
+ le64toh(f->header->data_hash_table_size));
+ if (r < 0)
goto fail;
- }
-
- n_data_hash_tables++;
break;
case OBJECT_FIELD_HASH_TABLE:
- if (n_field_hash_tables > 1) {
- error(p, "More than one field hash table");
- r = -EBADMSG;
- goto fail;
- }
-
- if (le64toh(f->header->field_hash_table_offset) != p + offsetof(HashTableObject, items) ||
- le64toh(f->header->field_hash_table_size) != le64toh(o->object.size) - offsetof(HashTableObject, items)) {
- error(p, "Header fields for field hash table invalid");
- r = -EBADMSG;
+ r = verify_hash_table(o, p, &n_field_hash_tables,
+ le64toh(f->header->field_hash_table_offset),
+ le64toh(f->header->field_hash_table_size));
+ if (r < 0)
goto fail;
- }
- n_field_hash_tables++;
break;
case OBJECT_ENTRY_ARRAY:
@@ -1325,12 +1345,12 @@ int journal_file_verify(
if (r < 0)
goto fail;
- r = verify_hash_table(f,
- cache_data_fd, n_data,
- cache_entry_fd, n_entries,
- cache_entry_array_fd, n_entry_arrays,
- &last_usec,
- show_progress);
+ r = verify_data_hash_table(f,
+ cache_data_fd, n_data,
+ cache_entry_fd, n_entries,
+ cache_entry_array_fd, n_entry_arrays,
+ &last_usec,
+ show_progress);
if (r < 0)
goto fail;