]> git.puffer.fish Git - mirror/frr.git/commitdiff
pimd: fix unaligned access parsing tlvs 6159/head
authorQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 6 Apr 2020 04:14:14 +0000 (00:14 -0400)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 6 Apr 2020 05:28:27 +0000 (01:28 -0400)
Can't use a uint8_t as a uint32_t

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
pimd/pim_tlv.h

index 657675b312362cc0fcaed6bd1c0ec3f79cf130c4..ef764656d3cf10773dc6f0a2effa26f72079627c 100644 (file)
@@ -48,8 +48,18 @@ typedef uint32_t pim_hello_options;
 #define PIM_OPTION_UNSET(options, option_mask) ((options) &= ~(option_mask))
 #define PIM_OPTION_IS_SET(options, option_mask) ((options) & (option_mask))
 
-#define PIM_TLV_GET_UINT16(buf) ntohs(*(const uint16_t *)(buf))
-#define PIM_TLV_GET_UINT32(buf) ntohl(*(const uint32_t *)(buf))
+#define PIM_TLV_GET_UINT16(buf)                                                \
+       ({                                                                     \
+               uint16_t _tmp;                                                 \
+               memcpy(&_tmp, (buf), sizeof(uint16_t));                        \
+               ntohs(_tmp);                                                   \
+       })
+#define PIM_TLV_GET_UINT32(buf)                                                \
+       ({                                                                     \
+               uint32_t _tmp;                                                 \
+               memcpy(&_tmp, (buf), sizeof(uint32_t));                        \
+               ntohl(_tmp);                                                   \
+       })
 #define PIM_TLV_GET_TYPE(buf) PIM_TLV_GET_UINT16(buf)
 #define PIM_TLV_GET_LENGTH(buf) PIM_TLV_GET_UINT16(buf)
 #define PIM_TLV_GET_HOLDTIME(buf) PIM_TLV_GET_UINT16(buf)