]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Fix data allignment issue 175/head
authorJörg Krause <joerg.krause@embedded.rocks>
Sat, 12 Dec 2015 20:44:16 +0000 (21:44 +0100)
committerJörg Krause <joerg.krause@embedded.rocks>
Sat, 12 Dec 2015 21:11:19 +0000 (22:11 +0100)
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

diff --git a/rtsp.c b/rtsp.c
index 2657b4d0fdc7596f1c7dfcc815747ae3c7825ca9..d046249dca24e3e8399cd399d027c69837f4b796 100644 (file)
--- 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