summaryrefslogtreecommitdiff
path: root/lib/common/comp_lzo.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-06-25 13:24:47 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-06-25 17:37:56 +0200
commitf09d9d3cbbb39f94fe9a43b0d90c370d33beafb2 (patch)
treefbe629d8a8ecac46b205b8e4dac93a683e6ceec6 /lib/common/comp_lzo.c
parent9ba4d7a122dfc4e3e03d0112ad03115b3065a238 (diff)
libcommon: remove potentially un-aligned access in LZO compressor
When accessing the 16 bit header, don't cast the buffer pointer to an uint16_t pointer, the result might not be aligned propperly. Instead memcpy to and from an uint16_t. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/common/comp_lzo.c')
-rw-r--r--lib/common/comp_lzo.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/common/comp_lzo.c b/lib/common/comp_lzo.c
index 3452647..b6496b2 100644
--- a/lib/common/comp_lzo.c
+++ b/lib/common/comp_lzo.c
@@ -68,6 +68,7 @@ static int lzo_write_options(sqfs_compressor_t *base, sqfs_file_t *file)
lzo_compressor_t *lzo = (lzo_compressor_t *)base;
sqfs_u8 buffer[sizeof(lzo_options_t) + 2];
lzo_options_t opt;
+ sqfs_u16 header;
int ret;
if (lzo->algorithm == SQFS_LZO_DEFAULT_ALG &&
@@ -83,7 +84,9 @@ static int lzo_write_options(sqfs_compressor_t *base, sqfs_file_t *file)
opt.level = 0;
}
- *((sqfs_u16 *)buffer) = htole16(0x8000 | sizeof(opt));
+ header = htole16(0x8000 | sizeof(opt));
+
+ memcpy(buffer, &header, sizeof(header));
memcpy(buffer + 2, &opt, sizeof(opt));
ret = file->write_at(file, sizeof(sqfs_super_t),
@@ -97,6 +100,7 @@ static int lzo_read_options(sqfs_compressor_t *base, sqfs_file_t *file)
lzo_compressor_t *lzo = (lzo_compressor_t *)base;
sqfs_u8 buffer[sizeof(lzo_options_t) + 2];
lzo_options_t opt;
+ sqfs_u16 header;
int ret;
ret = file->read_at(file, sizeof(sqfs_super_t),
@@ -104,7 +108,8 @@ static int lzo_read_options(sqfs_compressor_t *base, sqfs_file_t *file)
if (ret)
return ret;
- if (le16toh(*((sqfs_u16 *)buffer)) != (0x8000 | sizeof(opt)))
+ memcpy(&header, buffer, sizeof(header));
+ if (le16toh(header) != (0x8000 | sizeof(opt)))
return SQFS_ERROR_CORRUPTED;
memcpy(&opt, buffer + 2, sizeof(opt));