]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
lmdbbackend: avoid unaligned uint32_t reads by using memcpy
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Wed, 6 Jan 2021 16:17:00 +0000 (17:17 +0100)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Thu, 7 Jan 2021 11:48:06 +0000 (12:48 +0100)
lmdbbackend.cc:942:27: runtime error: load of misaligned address 0x604000b827aa for type 'uint32_t' (aka 'unsigned int'), which requires 4 byte alignment

modules/lmdbbackend/lmdbbackend.cc

index 020a275f179755c3dec37f77faca8f56c9899063..9cf2a90d8d60087cc03a4a5070089e67a3a51294 100644 (file)
@@ -824,7 +824,10 @@ bool LMDBBackend::getDomainInfo(const DNSName &domain, DomainInfo &di, bool getS
       serFromString(val.get<string_view>(), rr);
 
       if(rr.content.size() >= 5 * sizeof(uint32_t)) {
-        uint32_t serial = *reinterpret_cast<uint32_t*>(&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<DomainInfo> *domains, bool include_disabl
       serFromString(val.get<string_view>(), rr);
 
       if(rr.content.size() >= 5 * sizeof(uint32_t)) {
-        uint32_t serial = *reinterpret_cast<uint32_t*>(&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) {