diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2021-12-20 14:55:02 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-12-20 18:29:57 +0100 |
commit | 94c5a83c6eedec472e9867dcd55e42e9601695bc (patch) | |
tree | 362e7cb57113ecefba74e810201ddb38c1d42042 /src | |
parent | nss-resolve: expose various source-disablement settings as variables (diff) | |
download | systemd-94c5a83c6eedec472e9867dcd55e42e9601695bc.tar.xz systemd-94c5a83c6eedec472e9867dcd55e42e9601695bc.zip |
journal: Handle partially read HashItem's when punching holes
Diffstat (limited to '')
-rw-r--r-- | src/journal/journald-file.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/journal/journald-file.c b/src/journal/journald-file.c index 503900d5bc..35ca305384 100644 --- a/src/journal/journald-file.c +++ b/src/journal/journald-file.c @@ -81,7 +81,7 @@ static int journald_file_entry_array_punch_hole(JournalFile *f, uint64_t p, uint static int journald_file_punch_holes(JournalFile *f) { HashItem items[PAYLOAD_BUFFER_SIZE / sizeof(HashItem)]; uint64_t p, sz; - ssize_t n; + ssize_t n = SSIZE_MAX; int r; r = journald_file_entry_array_punch_hole( @@ -92,11 +92,14 @@ static int journald_file_punch_holes(JournalFile *f) { p = le64toh(f->header->data_hash_table_offset); sz = le64toh(f->header->data_hash_table_size); - for (uint64_t i = p; i < p + sz; i += n) { + for (uint64_t i = p; i < p + sz && n > 0; i += n) { n = pread(f->fd, items, MIN(sizeof(items), p + sz - i), i); if (n < 0) return n; + /* Let's ignore any partial hash items by rounding down to the nearest multiple of HashItem. */ + n -= n % sizeof(HashItem); + for (size_t j = 0; j < (size_t) n / sizeof(HashItem); j++) { Object o; |