commit 9349bf264b3a8e60f071ab0f9c11859ca6342395
Author: Andrew Price <anprice@redhat.com>
Date: Thu Sep 6 14:28:19 2018 +0100
libgfs2: Fix pointer cast byte order issue
lgfs2_field_assign() currently uses pointer casting to achieve generic
integer assignment based on the width of the field, but this is broken
as a uin32_t field can be assigned the value from the high bytes of the
uint64_t value, for instance. To fix this, store the value into a
uint64_t before casting to the narrower types.
Signed-off-by: Andrew Price <anprice@redhat.com>
diff --git a/gfs2/libgfs2/meta.c b/gfs2/libgfs2/meta.c
index 500757d9..55133b1d 100644
--- a/gfs2/libgfs2/meta.c
+++ b/gfs2/libgfs2/meta.c
@@ -919,6 +919,7 @@ int lgfs2_field_str(char *str, const size_t size, const char *blk, const struct
int lgfs2_field_assign(char *blk, const struct lgfs2_metafield *field, const void *val)
{
char *fieldp = blk + field->offset;
+ uint64_t num = *(uint64_t *)val;
if (field->flags & LGFS2_MFF_UUID) {
memcpy(fieldp, val, 16);
@@ -938,16 +939,16 @@ int lgfs2_field_assign(char *blk, const struct lgfs2_metafield *field, const voi
switch(field->length) {
case sizeof(uint8_t):
- *fieldp = *(uint8_t *)val;
+ *fieldp = (uint8_t)num;
return 0;
case sizeof(uint16_t):
- *(uint16_t *)fieldp = cpu_to_be16(*(uint16_t *)val);
+ *(uint16_t *)fieldp = cpu_to_be16((uint16_t)num);
return 0;
case sizeof(uint32_t):
- *(uint32_t *)fieldp = cpu_to_be32(*(uint32_t *)val);
+ *(uint32_t *)fieldp = cpu_to_be32((uint32_t)num);
return 0;
case sizeof(uint64_t):
- *(uint64_t *)fieldp = cpu_to_be64(*(uint64_t *)val);
+ *(uint64_t *)fieldp = cpu_to_be64((uint64_t)num);
return 0;
default:
/* Will never happen */