From: Peter van Dijk Date: Wed, 6 Jan 2021 16:17:00 +0000 (+0100) Subject: lmdbbackend: avoid unaligned uint32_t reads by using memcpy X-Git-Tag: rec-4.5.0-alpha1~34^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f061d15d3289070750d7213c04cbd93fe6c5ec5c;p=thirdparty%2Fpdns.git lmdbbackend: avoid unaligned uint32_t reads by using memcpy lmdbbackend.cc:942:27: runtime error: load of misaligned address 0x604000b827aa for type 'uint32_t' (aka 'unsigned int'), which requires 4 byte alignment --- diff --git a/modules/lmdbbackend/lmdbbackend.cc b/modules/lmdbbackend/lmdbbackend.cc index 020a275f17..9cf2a90d8d 100644 --- a/modules/lmdbbackend/lmdbbackend.cc +++ b/modules/lmdbbackend/lmdbbackend.cc @@ -824,7 +824,10 @@ bool LMDBBackend::getDomainInfo(const DNSName &domain, DomainInfo &di, bool getS serFromString(val.get(), rr); if(rr.content.size() >= 5 * sizeof(uint32_t)) { - uint32_t serial = *reinterpret_cast(&rr.content[rr.content.size() - (5 * sizeof(uint32_t))]); + uint32_t serial; + // a SOA has five 32 bit fields, the first of which is the serial + // there are two variable length names before the serial, so we calculate from the back + memcpy(&serial, &rr.content[rr.content.size() - (4 * sizeof(uint32_t))], sizeof(serial)); di.serial = ntohl(serial); } } @@ -939,7 +942,10 @@ void LMDBBackend::getAllDomains(vector *domains, bool include_disabl serFromString(val.get(), rr); if(rr.content.size() >= 5 * sizeof(uint32_t)) { - uint32_t serial = *reinterpret_cast(&rr.content[rr.content.size() - (5 * sizeof(uint32_t))]); + uint32_t serial; + // a SOA has five 32 bit fields, the first of which is the serial + // there are two variable length names before the serial, so we calculate from the back + memcpy(&serial, &rr.content[rr.content.size() - (5 * sizeof(uint32_t))], sizeof(serial)); di.serial = ntohl(serial); } } else if(!include_disabled) {