diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-09-13 17:10:46 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-09-13 17:10:46 +0200 |
commit | b588975fb0292cbb23770d6fc2349f57ab5b0db8 (patch) | |
tree | 9501af234f8c04f5e405864f7cd5a19c0cfa8f8a /src/journal/journal-file.c | |
parent | 5996c7c295e073ce21d41305169132c8aa993ad0 (diff) |
journal: never assert directly on data read from the journal
Diffstat (limited to 'src/journal/journal-file.c')
-rw-r--r-- | src/journal/journal-file.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index e55162ab2c..8dc0a3a669 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -590,7 +590,9 @@ static int journal_file_link_data(JournalFile *f, Object *o, uint64_t offset, ui assert(f); assert(o); assert(offset > 0); - assert(o->object.type == OBJECT_DATA); + + if (o->object.type != OBJECT_DATA) + return -EINVAL; /* This might alter the window we are looking at */ @@ -798,22 +800,28 @@ static int journal_file_append_data( uint64_t journal_file_entry_n_items(Object *o) { assert(o); - assert(o->object.type == OBJECT_ENTRY); + + if (o->object.type != OBJECT_ENTRY) + return 0; return (le64toh(o->object.size) - offsetof(Object, entry.items)) / sizeof(EntryItem); } uint64_t journal_file_entry_array_n_items(Object *o) { assert(o); - assert(o->object.type == OBJECT_ENTRY_ARRAY); + + if (o->object.type != OBJECT_ENTRY_ARRAY) + return 0; 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); + + if (o->object.type != OBJECT_DATA_HASH_TABLE && + o->object.type != OBJECT_FIELD_HASH_TABLE) + return 0; return (le64toh(o->object.size) - offsetof(Object, hash_table.items)) / sizeof(HashItem); } @@ -949,7 +957,9 @@ static int journal_file_link_entry(JournalFile *f, Object *o, uint64_t offset) { assert(f); assert(o); assert(offset > 0); - assert(o->object.type == OBJECT_ENTRY); + + if (o->object.type != OBJECT_ENTRY) + return -EINVAL; __sync_synchronize(); |