Blame SOURCES/bz1616389-2-libgfs2_Fix_pointer_cast_byte_order_issue.patch

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