chiark / gitweb /
journal: even more simple static object tests
authorLennart Poettering <lennart@poettering.net>
Fri, 17 Aug 2012 23:45:39 +0000 (01:45 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 17 Aug 2012 23:45:39 +0000 (01:45 +0200)
src/journal/journal-def.h
src/journal/journal-file.c
src/journal/journal-file.h
src/journal/journal-verify.c

index 45c3cde9f02def0d960e9540baf0c5b91579bf5e..8f00176bd70c04dc0a9713eb38ee3f8069ecc471 100644 (file)
@@ -188,6 +188,8 @@ _packed_ struct Header {
         /* Added in 189 */
         le64_t n_tags;
         le64_t n_entry_arrays;
         /* 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' })
 };
 
 #define FSS_HEADER_SIGNATURE ((char[]) { 'K', 'S', 'H', 'H', 'R', 'H', 'L', 'P' })
index e04ffd0452d2c690e032767997d6e4218f8e2bf4..df991a4a07c24c8afe296e5506da9ac6aef1759c 100644 (file)
@@ -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);
 }
 
         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,
 static int link_entry_into_array(JournalFile *f,
                                  le64_t *first,
                                  le64_t *idx,
index 2d2bf319a0e7846fd94a8bebc905aca4aa02ff70..e2ef03347ce64fcdcc9a1fb98f043633daf180f5 100644 (file)
@@ -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_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);
 
 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);
index e3bd8ffbd7ce2ecf4c0b8e165842dbf7e9851677..a31817671b30e17926ee4de76fbd0f15d8f1cca8 100644 (file)
@@ -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;
 
                 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:
                 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;
 
                 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:
                 break;
 
         case OBJECT_TAG: