X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fjournal%2Fjournal-verify.c;h=9434cc925cc58c1dc4e32cf02c165750c52b1149;hp=781b1ee1deb08d8f269a1325ded712675b4de8ce;hb=fd1e5b62e8d44761ec9d6b6f49590cccc0be1e8f;hpb=92fba83e3a23ce7778a1bde67d277fdc97ab39f9 diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c index 781b1ee1d..9434cc925 100644 --- a/src/journal/journal-verify.c +++ b/src/journal/journal-verify.c @@ -34,10 +34,6 @@ #include "compress.h" #include "fsprg.h" -/* Use six characters to cover the offsets common in smallish journal - * files without adding to many zeros. */ -#define OFSfmt "%06"PRIx64 - static int journal_file_object_verify(JournalFile *f, uint64_t offset, Object *o) { uint64_t i; @@ -67,7 +63,7 @@ static int journal_file_object_verify(JournalFile *f, uint64_t offset, Object *o } if (le64toh(o->object.size) - offsetof(DataObject, payload) <= 0) { - log_error(OFSfmt": bad object size (<= %"PRIu64"): %"PRIu64, + log_error(OFSfmt": bad object size (<= %zu): %"PRIu64, offset, offsetof(DataObject, payload), le64toh(o->object.size)); @@ -120,7 +116,7 @@ static int journal_file_object_verify(JournalFile *f, uint64_t offset, Object *o case OBJECT_FIELD: if (le64toh(o->object.size) - offsetof(FieldObject, payload) <= 0) { - log_error(OFSfmt": bad field size (<= %"PRIu64"): %"PRIu64, + log_error(OFSfmt": bad field size (<= %zu): %"PRIu64, offset, offsetof(FieldObject, payload), le64toh(o->object.size)); @@ -139,7 +135,7 @@ static int journal_file_object_verify(JournalFile *f, uint64_t offset, Object *o case OBJECT_ENTRY: if ((le64toh(o->object.size) - offsetof(EntryObject, items)) % sizeof(EntryItem) != 0) { - log_error(OFSfmt": bad entry size (<= %"PRIu64"): %"PRIu64, + log_error(OFSfmt": bad entry size (<= %zu): %"PRIu64, offset, offsetof(EntryObject, items), le64toh(o->object.size)); @@ -249,12 +245,12 @@ static int journal_file_object_verify(JournalFile *f, uint64_t offset, Object *o } 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])) { + if (le64toh(o->entry_array.items[i]) != 0 && + !VALID64(le64toh(o->entry_array.items[i]))) { log_error(OFSfmt": invalid object entry array item (%"PRIu64"/%"PRIu64"): "OFSfmt, offset, i, journal_file_entry_array_n_items(o), - o->entry_array.items[i]); + le64toh(o->entry_array.items[i])); return -EBADMSG; } @@ -789,9 +785,6 @@ int journal_file_verify( uint64_t n_weird = 0, n_objects = 0, n_entries = 0, n_data = 0, n_fields = 0, n_data_hash_tables = 0, n_field_hash_tables = 0, n_entry_arrays = 0, n_tags = 0; usec_t last_usec = 0; int data_fd = -1, entry_fd = -1, entry_array_fd = -1; - char data_path[] = "/var/tmp/journal-data-XXXXXX", - entry_path[] = "/var/tmp/journal-entry-XXXXXX", - entry_array_path[] = "/var/tmp/journal-entry-array-XXXXXX"; unsigned i; bool found_last; #ifdef HAVE_GCRYPT @@ -812,29 +805,26 @@ int journal_file_verify( } else if (f->seal) return -ENOKEY; - data_fd = mkostemp(data_path, O_CLOEXEC); + data_fd = open_tmpfile("/var/tmp", O_RDWR | O_CLOEXEC); if (data_fd < 0) { log_error("Failed to create data file: %m"); r = -errno; goto fail; } - unlink(data_path); - entry_fd = mkostemp(entry_path, O_CLOEXEC); + entry_fd = open_tmpfile("/var/tmp", O_RDWR | O_CLOEXEC); if (entry_fd < 0) { log_error("Failed to create entry file: %m"); r = -errno; goto fail; } - unlink(entry_path); - entry_array_fd = mkostemp(entry_array_path, O_CLOEXEC); + entry_array_fd = open_tmpfile("/var/tmp", O_RDWR | O_CLOEXEC); if (entry_array_fd < 0) { log_error("Failed to create entry array file: %m"); r = -errno; goto fail; } - unlink(entry_array_path); #ifdef HAVE_GCRYPT if ((le32toh(f->header->compatible_flags) & ~HEADER_COMPATIBLE_SEALED) != 0)