b=477727; fix unaligned access in URL classifier; r=dcamp,sr=stuart
authorVladimir Vukicevic <vladimir@pobox.com>
Tue, 10 Feb 2009 15:10:08 -0800
changeset 24899 4151690668c7554aa7c78212508df13a2000c44b
parent 24898 cb3832f7c448d77f89f2d40c471a94507b5cbad1
child 24900 d347911289b8d6c31714454f2635809007d95301
push idunknown
push userunknown
push dateunknown
reviewersdcamp, stuart
bugs477727
milestone1.9.2a1pre
b=477727; fix unaligned access in URL classifier; r=dcamp,sr=stuart
toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp
--- a/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp
@@ -2164,18 +2164,19 @@ nsUrlClassifierDBServiceWorker::GetShaEn
 
       if (chunkType == CHUNK_SUB) {
         if (start + 4 > chunk.Length()) {
           // there isn't as much data as there should be.
           NS_WARNING("Received a zero-entry sub chunk without an associated add.");
           return NS_ERROR_FAILURE;
         }
         const nsCSubstring& str = Substring(chunk, start, 4);
-        const PRUint32 *p = reinterpret_cast<const PRUint32*>(str.BeginReading());
-        entry->mAddChunkId = PR_ntohl(*p);
+        PRUint32 p;
+        memcpy(&p, str.BeginReading(), 4);
+        entry->mAddChunkId = PR_ntohl(p);
         if (entry->mAddChunkId == 0) {
           NS_WARNING("Received invalid chunk number.");
           return NS_ERROR_FAILURE;
         }
         start += 4;
       }
     } else {
       PRUint32 entrySize = fragmentSize;
@@ -2193,18 +2194,19 @@ nsUrlClassifierDBServiceWorker::GetShaEn
         if (!entry) return NS_ERROR_OUT_OF_MEMORY;
 
         entry->mKey = domain;
         entry->mTableId = tableId;
         entry->mChunkId = chunkNum;
 
         if (chunkType == CHUNK_SUB) {
           const nsCSubstring& str = Substring(chunk, start, 4);
-          const PRUint32 *p = reinterpret_cast<const PRUint32*>(str.BeginReading());
-          entry->mAddChunkId = PR_ntohl(*p);
+          PRUint32 p;
+          memcpy(&p, str.BeginReading(), 4);
+          entry->mAddChunkId = PR_ntohl(p);
           if (entry->mAddChunkId == 0) {
             NS_WARNING("Received invalid chunk number.");
             return NS_ERROR_FAILURE;
           }
           start += 4;
         }
 
         if (fragmentSize == PARTIAL_LENGTH) {