]> granicus.if.org Git - pdns/commitdiff
fix up unaligned access on UltraSPARC in recursor. Analysis provided by Jan Gyselinck.
authorBert Hubert <bert.hubert@netherlabs.nl>
Sat, 12 Mar 2011 21:17:07 +0000 (21:17 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Sat, 12 Mar 2011 21:17:07 +0000 (21:17 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2060 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/dnsparser.cc
pdns/pdns_recursor.cc

index 056bca8d78cef3c87545ff133f4aa636392a5e1c..ed427476c2ca7087a68034c9f4bd210a84ab50f8 100644 (file)
@@ -594,16 +594,17 @@ private:
 // method of operation: silently fail if it doesn't work - we're only trying to be nice, don't fall over on it
 void ageDNSPacket(std::string& packet, uint32_t seconds)
 {
-  if(packet.length() < 12)
+  if(packet.length() < sizeof(dnsheader))
     return;
   try 
   {
-    const dnsheader* dh = (const dnsheader*)packet.c_str();
-    int numrecords = ntohs(dh->ancount) + ntohs(dh->nscount) + ntohs(dh->arcount);
+    dnsheader dh;
+    memcpy((void*)&dh, (const dnsheader*)packet.c_str(), sizeof(dh));
+    int numrecords = ntohs(dh.ancount) + ntohs(dh.nscount) + ntohs(dh.arcount);
     DNSPacketMangler dpm(packet);
     
     int n;
-    for(n=0; n < ntohs(dh->qdcount) ; ++n) {
+    for(n=0; n < ntohs(dh.qdcount) ; ++n) {
       dpm.skipLabel();
       dpm.skipBytes(4); // qtype, qclass
     }
index c2a15f61906429b775e43481bf7617f08874c075..8adac71fe8e0af810fec25b7f92c36b51089439c 100644 (file)
@@ -809,14 +809,14 @@ string* doProcessUDPQuestion(const std::string& question, const ComboAddress& fr
     uint32_t age;
     if(!SyncRes::s_nopacketcache && t_packetCache->getResponsePacket(question, g_now.tv_sec, &response, &age)) {
       if(!g_quiet)
-       L<<Logger::Error<<t_id<< " question answered from packet cache from "<<fromaddr.toString()<<endl;
+        L<<Logger::Error<<t_id<< " question answered from packet cache from "<<fromaddr.toString()<<endl;
 
       g_stats.packetCacheHits++;
       SyncRes::s_queries++;
       ageDNSPacket(response, age);
       sendto(fd, response.c_str(), response.length(), 0, (struct sockaddr*) &fromaddr, fromaddr.getSocklen());
       if(response.length() >= sizeof(struct dnsheader))
-       updateRcodeStats(((struct dnsheader*)response.c_str())->rcode);
+        updateRcodeStats(((struct dnsheader*)response.c_str())->rcode);
       g_stats.avgLatencyUsec=(uint64_t)((1-0.0001)*g_stats.avgLatencyUsec + 0); // we assume 0 usec
       return 0;
     }