From 3857e22ebbed824f4a9d9c7ce068b5e17715f8ab Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Wed, 10 Apr 2019 10:01:10 +0200 Subject: [PATCH] Fix unaligned access. Spotted in the wild on OpenBSD/armv7. --- pdns/recursordist/test-ednsoptions_cc.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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); -- 2.40.0