From 194cd03d0e32656c2786ec01e9f22d4a9c6921fc Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Tue, 8 Oct 2019 00:33:25 +0200 Subject: Fix unaligned reads in write_dir_index Signed-off-by: David Oberhollenzer --- lib/sqfs/write_inode.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/sqfs/write_inode.c b/lib/sqfs/write_inode.c index c78c852..f1f8abf 100644 --- a/lib/sqfs/write_inode.c +++ b/lib/sqfs/write_inode.c @@ -13,6 +13,8 @@ #include "sqfs/dir.h" #include "util/compat.h" +#include + static int write_block_sizes(sqfs_meta_writer_t *ir, const sqfs_inode_generic_t *n) { @@ -29,24 +31,24 @@ static int write_block_sizes(sqfs_meta_writer_t *ir, static int write_dir_index(sqfs_meta_writer_t *ir, const sqfs_u8 *data, size_t count) { - sqfs_dir_index_t *ent, copy; + sqfs_dir_index_t ent; size_t len; int err; - while (count > sizeof(*ent)) { - ent = (sqfs_dir_index_t *)data; - data += sizeof(*ent); - count -= sizeof(*ent); - len = ent->size + 1; + while (count > sizeof(ent)) { + memcpy(&ent, data, sizeof(ent)); + data += sizeof(ent); + count -= sizeof(ent); + len = ent.size + 1; if (len > count) return SQFS_ERROR_CORRUPTED; - copy.start_block = htole32(ent->start_block); - copy.index = htole32(ent->index); - copy.size = htole32(ent->size); + ent.start_block = htole32(ent.start_block); + ent.index = htole32(ent.index); + ent.size = htole32(ent.size); - err = sqfs_meta_writer_append(ir, ©, sizeof(copy)); + err = sqfs_meta_writer_append(ir, &ent, sizeof(ent)); if (err) return err; -- cgit v1.2.3