From b2ae39a67ffb1b8953aa5fddffed218494f032a7 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 23 Mar 2022 08:55:05 -0400 Subject: [PATCH] TT#14008 fix unaligned 64-bit memory access Change-Id: I429afb528c68c78a1a4755e52a466e1282beffc2 --- daemon/stun.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/daemon/stun.c b/daemon/stun.c index 19da778e3..838c4d618 100644 --- a/daemon/stun.c +++ b/daemon/stun.c @@ -113,6 +113,12 @@ struct software { /* XXX add const in functions */ +static uint64_t be64toh_unaligned(const char *s) { + uint64_t u; + memcpy(&u, s, sizeof(u)); + return be64toh(u); +} + static int stun_attributes(struct stun_attrs *out, str *s, uint16_t *unknowns, struct header *req) { struct tlv *tlv; int len, type, uc; @@ -170,7 +176,7 @@ static int stun_attributes(struct stun_attrs *out, str *s, uint16_t *unknowns, s return -1; if (attr.len != 8) return -1; - out->tiebreaker = be64toh(*((uint64_t *) attr.s)); + out->tiebreaker = be64toh_unaligned(attr.s); out->controlled = 1; break; @@ -179,7 +185,7 @@ static int stun_attributes(struct stun_attrs *out, str *s, uint16_t *unknowns, s return -1; if (attr.len != 8) return -1; - out->tiebreaker = be64toh(*((uint64_t *) attr.s)); + out->tiebreaker = be64toh_unaligned(attr.s); out->controlling = 1; break;