Blame SOURCES/bz1616389-2-libgfs2_Fix_pointer_cast_byte_order_issue.patch

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