Commit e94f59ed authored by Robert Schmidt's avatar Robert Schmidt Committed by Laurent THOMAS

IES_DECODE_U16 macro: load from 16-bit aligned address

The IES_DECODE_U16 macro loads a 16 bit integer from an arbitrary
address; this can lead to reads from misaligned addresses, and undefined
behavior sanitizer warns, like, e.g., so:

    openair3/NAS/COMMON/IES/ProtocolConfigurationOptions.c:62:5: runtime error: load of misaligned address 0x7f3c24032c01 for type 'uint16_t', which requires 2 byte alignment

To fix this, first use memcpy() to load to a 16-bit aligned address,
then do the actual decoding.
parent 71bd10b4
......@@ -62,8 +62,12 @@
#define IES_DECODE_U8(bUFFER, dECODED, vALUE) \
DECODE_U8(bUFFER + dECODED, vALUE, dECODED)
#define IES_DECODE_U16(bUFFER, dECODED, vALUE) \
DECODE_U16(bUFFER + dECODED, vALUE, dECODED)
#define IES_DECODE_U16(bUFFER, dECODED, vALUE) \
do { \
uint16_t val; \
memcpy(&val, bUFFER + dECODED, sizeof(val)); \
DECODE_U16(&val, vALUE, dECODED); \
} while (0)
#define IES_DECODE_U24(bUFFER, dECODED, vALUE) \
DECODE_U24(bUFFER + dECODED, vALUE, dECODED)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment