Blame SOURCES/bz1616389-2-libgfs2_Fix_pointer_cast_byte_order_issue.patch

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