diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-10-08 00:33:25 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-10-08 00:44:54 +0200 |
commit | 194cd03d0e32656c2786ec01e9f22d4a9c6921fc (patch) | |
tree | 3beb6686e271a4a7878e06a4a16d01f6c1d77738 | |
parent | 5cdaa85085810cc329654248be1ec5206367f68c (diff) |
Fix unaligned reads in write_dir_index
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r-- | lib/sqfs/write_inode.c | 22 |
1 files 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 <string.h> + 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; |