On Sun, Jun 01, 2008 at 01:41:13PM +0100, Martin Guy wrote:
> Package: xulrunner
> Version: 1.9~rc1
> Severity: normal
> User: [EMAIL PROTECTED]
> Usertags: patch
> 
> There is an unaligned word access bug in
> toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp line 2024
> where a char pointer is cast to an int pointer and accessed. On arm
> and armel by default this silently gives junk values. On other
> architectures it will cause a bus faults.
> 
> Fortunately the fix is trivial and local, though there are probably
> more mozilla- o C++-like ways to reimplement this before sending it
> upstream.

It's not more mozilla-o C++-like, but it is less verbose and should work
as fine:

diff --git a/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp 
b/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp
index f454145..eb4513d 100644
--- a/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp
@@ -2020,8 +2020,9 @@ nsUrlClassifierDBServiceWorker::GetShaEntries(PRUint32 
tableId,
           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, reinterpret_cast<const PRUint32*>(str.BeginReading()), 4);
+        entry->mAddChunkId = PR_ntohl(p);
         if (entry->mAddChunkId == 0) {
           NS_WARNING("Received invalid chunk number.");
           return NS_ERROR_FAILURE;
@@ -2049,8 +2050,9 @@ nsUrlClassifierDBServiceWorker::GetShaEntries(PRUint32 
tableId,
 
         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, reinterpret_cast<const PRUint32*>(str.BeginReading()), 4);
+          entry->mAddChunkId = PR_ntohl(p);
           if (entry->mAddChunkId == 0) {
             NS_WARNING("Received invalid chunk number.");
             return NS_ERROR_FAILURE;

Mike



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to