tags 289187 + patch
thanks

Hi,

the error is in libclamav/others.c:cli_readint32. When scanning for
example contrib/Windows/clamav.exe from the clamav source, it is
called with an unaligned pointer. Unfortunately, the function is
undocumented, so it is not clear whether the fault is in the function
or in its caller; I assume the former. Another problem is in
upx.c. The author's trick only works on little endian architectures
that don't mind unaligned accesses, which is basically only i386, so I
have conditionalized it on that. Here's a patch.

--- libclamav/others.c~ 2005-04-20 01:33:17.000000000 +0200
+++ libclamav/others.c  2005-05-07 15:45:11.000000000 +0200
@@ -546,12 +546,13 @@
         return count;
 }
 
+/* Return a potentially unaligned 32-bit little endian value from BUFF.  */
 int32_t cli_readint32(const char *buff)
 {
        int32_t ret;
 
-#if WORDS_BIGENDIAN == 0
-    ret = *(int32_t *) buff;
+#if WORDS_BIGENDIAN == 0 && defined(__GNUC__)
+    ret = ((struct { int32_t x; } __attribute__((packed)) *) buff)->x;
 #else
     ret = buff[0] & 0xff;
     ret |= (buff[1] & 0xff) << 8;
--- libclamav/upx.c~    2005-04-27 23:53:57.000000000 +0200
+++ libclamav/upx.c     2005-05-07 16:14:46.000000000 +0200
@@ -193,7 +193,7 @@
 static int doubleebx(char *src, int32_t *myebx, int *scur, int ssize)
 {
   int32_t oldebx = *myebx;
-#if WORDS_BIGENDIAN == 1
+#ifndef __i386__
   char *pt;
   int32_t shift, i = 0;
 #endif
@@ -202,7 +202,7 @@
   if ( !(oldebx & 0x7fffffff)) {
     if (*scur<0 || ssize-*scur<4)
       return -1;
-#if WORDS_BIGENDIAN == 0
+#ifdef __i386__
     oldebx = *(int*)(src+*scur);
 #else
     oldebx = 0;


-- 
        Falk


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

Reply via email to