]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mpls: fix misaligned read
authorJason Ish <ish@unx.ca>
Tue, 26 Mar 2019 22:28:17 +0000 (16:28 -0600)
committerVictor Julien <victor@inliniac.net>
Thu, 18 Apr 2019 10:47:37 +0000 (12:47 +0200)
Instead of casting the packet buffer to a uint32, memcpy it to
avoid misaligned read error, as caught by the undefined behavior
detector (ubsan).

Redmine issue:
https://redmine.openinfosecfoundation.org/issues/2903

src/decode-mpls.c

index 53d7ec18820ef0708b31d820a9f61543c675dfe5..e5bcea39f6edb57261b2c2ac1ad4d3733d2c0eca 100644 (file)
@@ -58,7 +58,7 @@ int DecodeMPLS(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt,
             ENGINE_SET_INVALID_EVENT(p, MPLS_HEADER_TOO_SMALL);
             return TM_ECODE_FAILED;
         }
-        shim = *(uint32_t *)pkt;
+        memcpy(&shim, pkt, sizeof(shim));
         pkt += MPLS_HEADER_LEN;
         len -= MPLS_HEADER_LEN;
     } while (MPLS_BOTTOM(shim) == 0);