diff --git a/rtc_base/byte_order.h b/rtc_base/byte_order.h index ae1c6345ba..b8f8ae9f7a 100644 --- a/rtc_base/byte_order.h +++ b/rtc_base/byte_order.h @@ -13,6 +13,8 @@ #include +#include + #if defined(WEBRTC_POSIX) && !defined(__native_client__) #include #endif @@ -107,51 +109,69 @@ inline uint8_t Get8(const void* memory, size_t offset) { } inline void SetBE16(void* memory, uint16_t v) { - *static_cast(memory) = htobe16(v); + uint16_t val = htobe16(v); + memcpy(memory, &val, sizeof(val)); } inline void SetBE32(void* memory, uint32_t v) { - *static_cast(memory) = htobe32(v); + uint32_t val = htobe32(v); + memcpy(memory, &val, sizeof(val)); } inline void SetBE64(void* memory, uint64_t v) { - *static_cast(memory) = htobe64(v); + uint64_t val = htobe64(v); + memcpy(memory, &val, sizeof(val)); } inline uint16_t GetBE16(const void* memory) { - return be16toh(*static_cast(memory)); + uint16_t val; + memcpy(&val, memory, sizeof(val)); + return be16toh(val); } inline uint32_t GetBE32(const void* memory) { - return be32toh(*static_cast(memory)); + uint32_t val; + memcpy(&val, memory, sizeof(val)); + return be32toh(val); } inline uint64_t GetBE64(const void* memory) { - return be64toh(*static_cast(memory)); + uint64_t val; + memcpy(&val, memory, sizeof(val)); + return be64toh(val); } inline void SetLE16(void* memory, uint16_t v) { - *static_cast(memory) = htole16(v); + uint16_t val = htole16(v); + memcpy(memory, &val, sizeof(val)); } inline void SetLE32(void* memory, uint32_t v) { - *static_cast(memory) = htole32(v); + uint32_t val = htole32(v); + memcpy(memory, &val, sizeof(val)); } inline void SetLE64(void* memory, uint64_t v) { - *static_cast(memory) = htole64(v); + uint64_t val = htole64(v); + memcpy(memory, &val, sizeof(val)); } inline uint16_t GetLE16(const void* memory) { - return le16toh(*static_cast(memory)); + uint16_t val; + memcpy(&val, memory, sizeof(val)); + return le16toh(val); } inline uint32_t GetLE32(const void* memory) { - return le32toh(*static_cast(memory)); + uint32_t val; + memcpy(&val, memory, sizeof(val)); + return le32toh(val); } inline uint64_t GetLE64(const void* memory) { - return le64toh(*static_cast(memory)); + uint64_t val; + memcpy(&val, memory, sizeof(val)); + return le64toh(val); } // Check if the current host is big endian. diff --git a/tools_webrtc/ubsan/suppressions.txt b/tools_webrtc/ubsan/suppressions.txt index dc76f38c20..2ece795570 100644 --- a/tools_webrtc/ubsan/suppressions.txt +++ b/tools_webrtc/ubsan/suppressions.txt @@ -6,10 +6,6 @@ # the RTC_NO_SANITIZE macro. Please think twice before adding new exceptions. ############################################################################# -# YASM does some funny things that UBsan doesn't like. -# https://crbug.com/489901 -src:*/third_party/yasm/* - # OpenH264 triggers some errors that are out of our control. src:*/third_party/ffmpeg/libavcodec/* src:*/third_party/openh264/* @@ -22,3 +18,9 @@ src:*/third_party/libvpx/source/libvpx/vp8/* ############################################################################# # Ignore system libraries. src:*/usr/* + +############################################################################# +[alignment] +# Libaom and libsrtp are doing unaligned memory access. +src:*/third_party/libaom/source/libaom/* +src:*/third_party/libsrtp/srtp/srtp.c