X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fjournal-file.c;h=e778e1c67c19a5f798a6bdd4291557e6272eeeba;hb=f2cc3753ce0e85960f0299855c3b98ba60efa580;hp=e55162ab2c0361babbf941d9368b2e8502ad5059;hpb=5996c7c295e073ce21d41305169132c8aa993ad0;p=elogind.git diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index e55162ab2..e778e1c67 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(); @@ -1041,7 +1051,7 @@ void journal_file_post_change(JournalFile *f) { __sync_synchronize(); if (ftruncate(f->fd, f->last_stat.st_size) < 0) - log_error("Failed to to truncate file to its own size: %m"); + log_error("Failed to truncate file to its own size: %m"); } int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const struct iovec iovec[], unsigned n_iovec, uint64_t *seqnum, Object **ret, uint64_t *offset) {