From: Otto Moerbeek Date: Wed, 10 Apr 2019 08:01:10 +0000 (+0200) Subject: Fix unaligned access. Spotted in the wild on OpenBSD/armv7. X-Git-Tag: dnsdist-1.4.0-alpha1~7^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3857e22ebbed824f4a9d9c7ce068b5e17715f8ab;p=pdns Fix unaligned access. Spotted in the wild on OpenBSD/armv7. --- diff --git a/pdns/recursordist/test-ednsoptions_cc.cc b/pdns/recursordist/test-ednsoptions_cc.cc index d62a64c19..a49068f38 100644 --- a/pdns/recursordist/test-ednsoptions_cc.cc +++ b/pdns/recursordist/test-ednsoptions_cc.cc @@ -126,7 +126,9 @@ static void checkECSOptionValidity(const std::string& sourceStr, uint8_t sourceM uint8_t sourceBytes = ((sourceMask - 1) >> 3) + 1; BOOST_REQUIRE_EQUAL(ecsOptionStr.size(), (ecsHeaderSize + sourceBytes)); /* family */ - BOOST_REQUIRE_EQUAL(ntohs(*(reinterpret_cast(&ecsOptionStr.at(0)))), source.isIPv4() ? 1 : 2); + uint16_t u; + memcpy(&u, ecsOptionStr.c_str(), sizeof(u)); + BOOST_REQUIRE_EQUAL(ntohs(u), source.isIPv4() ? 1 : 2); /* source mask */ BOOST_REQUIRE_EQUAL(static_cast(ecsOptionStr.at(2)), sourceMask); BOOST_REQUIRE_EQUAL(static_cast(ecsOptionStr.at(3)), scopeMask);