From faa583398dfe5c0aa55d3b4574dc43c9e15eb43e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=B6rg=20Krause?= Date: Sat, 12 Dec 2015 21:44:16 +0100 Subject: [PATCH] Fix data allignment issue Different processor targets may have different word alignment restrictions. Typically, a two or four byte integer should start on a four-byte address in order to be fetched correctly over a bus. An access of a misaligned memory element may cause a bus error. Therefore, we need to adjust the contents of a message by copying it into a new location, before interpreting it. --- rtsp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rtsp.c b/rtsp.c index 2657b4d0..d046249d 100644 --- a/rtsp.c +++ b/rtsp.c @@ -1085,13 +1085,16 @@ static void handle_set_parameter_metadata(rtsp_conn_info *conn, rtsp_message *re unsigned int off = 8; + uint32_t itag, vl; while (off < cl) { // pick up the metadata tag as an unsigned longint - uint32_t itag = ntohl(*(uint32_t *)(cp + off)); + memcpy(&itag, (uint32_t *)(cp + off), sizeof(uint32_t)); /* can be misaligned, thus memcpy */ + itag = ntohl(itag); off += sizeof(uint32_t); // pick up the length of the data - uint32_t vl = ntohl(*(uint32_t *)(cp + off)); + memcpy(&vl, (uint32_t *)(cp + off), sizeof(uint32_t)); /* can be misaligned, thus memcpy */ + vl = ntohl(vl); off += sizeof(uint32_t); // pass the data over -- 2.47.3