This function basically did: | memcpy(out, val, <len of requested type>); which works only for little endian integer types. Fix this by assigning the 64bit input value to a variable of the right size and use that as input for above memcpy() call. Signed-off-by: Phil Sutter <phil@xxxxxx> --- src/utils.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/utils.c b/src/utils.c index 3e449609395e4..4d9ee782b56b3 100644 --- a/src/utils.c +++ b/src/utils.c @@ -72,6 +72,15 @@ static struct { int nftnl_get_value(enum nftnl_type type, void *val, void *out) { + union { + uint8_t u8; + uint16_t u16; + uint32_t u32; + int8_t s8; + int16_t s16; + int32_t s32; + } values; + void *valuep = NULL; int64_t sval; uint64_t uval; @@ -85,7 +94,6 @@ int nftnl_get_value(enum nftnl_type type, void *val, void *out) errno = ERANGE; return -1; } - memcpy(out, &uval, basetype[type].len); break; case NFTNL_TYPE_S8: case NFTNL_TYPE_S16: @@ -97,10 +105,42 @@ int nftnl_get_value(enum nftnl_type type, void *val, void *out) errno = ERANGE; return -1; } - memcpy(out, &sval, basetype[type].len); break; } + switch (type) { + case NFTNL_TYPE_U8: + values.u8 = uval; + valuep = &values.u8; + break; + case NFTNL_TYPE_U16: + values.u16 = uval; + valuep = &values.u16; + break; + case NFTNL_TYPE_U32: + values.u32 = uval; + valuep = &values.u32; + break; + case NFTNL_TYPE_U64: + valuep = &uval; + break; + case NFTNL_TYPE_S8: + values.s8 = sval; + valuep = &values.s8; + break; + case NFTNL_TYPE_S16: + values.s16 = sval; + valuep = &values.s16; + break; + case NFTNL_TYPE_S32: + values.s32 = sval; + valuep = &values.s32; + break; + case NFTNL_TYPE_S64: + valuep = &sval; + break; + } + memcpy(out, valuep, basetype[type].len); return 0; } -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html