[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b

Török Edvin edwin at clamav.net
Sun Apr 4 01:17:50 UTC 2010


The following commit has been merged in the debian/unstable branch:
commit e3540e0a5f54460d2f6a88253e65b8d63a61bc73
Author: Török Edvin <edwin at clamav.net>
Date:   Fri Jan 29 12:17:07 2010 +0200

    Add sanity check for struct packing (bb #1752).
    
    Also move some #pragma pack() to the proper position.

diff --git a/configure b/configure
index 8a93060..dc1ed2d 100755
--- a/configure
+++ b/configure
@@ -17613,6 +17613,82 @@ $as_echo "#define HAVE_ATTRIB_ALIGNED 1" >>confdefs.h
 
 fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking that structure packing works" >&5
+$as_echo_n "checking that structure packing works... " >&6; }
+if test "${have_cv_struct_pack+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+
+    if test "$cross_compiling" = yes; then :
+  have_cv_struct_pack=yes
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#ifndef HAVE_ATTRIB_PACKED
+#define __attribute__(x)
+#endif
+#ifdef HAVE_PRAGMA_PACK
+#pragma pack(1) /* has to be in column 1 ! */
+#endif
+#ifdef HAVE_PRAGMA_PACK_HPPA
+#pragma pack 1 /* has to be in column 1 ! */
+#endif
+
+struct { char c __attribute__((packed)); long l __attribute__((packed)); } s;
+
+#ifdef HAVE_PRAGMA_PACK
+#pragma pack()
+#endif
+#ifdef HAVE_PRAGMA_PACK_HPPA
+#pragma pack
+#endif
+
+struct { char c; long l;} s2;
+
+#ifdef HAVE_PRAGMA_PACK
+#pragma pack(1) /* has to be in column 1 ! */
+#endif
+#ifdef HAVE_PRAGMA_PACK_HPPA
+#pragma pack 1 /* has to be in column 1 ! */
+#endif
+
+struct { char c; long l; } __attribute__((packed)) s3;
+
+#ifdef HAVE_PRAGMA_PACK
+#pragma pack()
+#endif
+#ifdef HAVE_PRAGMA_PACK_HPPA
+#pragma pack
+#endif
+
+    int main(int argc, char **argv) {
+        if (sizeof(s)!=sizeof(s.c)+sizeof(s.l))
+	    return 1;
+	if (sizeof(s) != sizeof(s3))
+	    return 2;
+	return (sizeof(s2) >= sizeof(s)) ? 0 : 3;
+    }
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  have_cv_struct_pack=yes
+else
+  have_cv_struct_pack=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_cv_struct_pack" >&5
+$as_echo "$have_cv_struct_pack" >&6; }
+
+if test "$have_cv_struct_pack" = "no"; then
+    as_fn_error "Structure packing seems to be available, but is not working with this compiler" "$LINENO" 5
+fi
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for fd_set" >&5
 $as_echo_n "checking for fd_set... " >&6; }
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
diff --git a/configure.in b/configure.in
index cf3732a..54a4d1e 100644
--- a/configure.in
+++ b/configure.in
@@ -1396,6 +1396,64 @@ if test "$have_cv_attrib_aligned" = yes; then
 	AC_DEFINE([HAVE_ATTRIB_ALIGNED], 1, [attrib aligned])
 fi
 
+dnl Sanity check that struct packing works
+AC_MSG_CHECKING([that structure packing works])
+AC_CACHE_VAL([have_cv_struct_pack],[
+    AC_TRY_RUN([
+#ifndef HAVE_ATTRIB_PACKED
+#define __attribute__(x)
+#endif
+#ifdef HAVE_PRAGMA_PACK
+#pragma pack(1) /* has to be in column 1 ! */
+#endif
+#ifdef HAVE_PRAGMA_PACK_HPPA
+#pragma pack 1 /* has to be in column 1 ! */
+#endif
+
+struct { char c __attribute__((packed)); long l __attribute__((packed)); } s;
+
+#ifdef HAVE_PRAGMA_PACK
+#pragma pack()
+#endif
+#ifdef HAVE_PRAGMA_PACK_HPPA
+#pragma pack
+#endif
+
+struct { char c; long l;} s2;
+
+#ifdef HAVE_PRAGMA_PACK
+#pragma pack(1) /* has to be in column 1 ! */
+#endif
+#ifdef HAVE_PRAGMA_PACK_HPPA
+#pragma pack 1 /* has to be in column 1 ! */
+#endif
+
+struct { char c; long l; } __attribute__((packed)) s3;
+
+#ifdef HAVE_PRAGMA_PACK
+#pragma pack()
+#endif
+#ifdef HAVE_PRAGMA_PACK_HPPA
+#pragma pack
+#endif
+
+    int main(int argc, char **argv) {
+        if (sizeof(s)!=sizeof(s.c)+sizeof(s.l))
+	    return 1;
+	if (sizeof(s) != sizeof(s3))
+	    return 2;
+	return (sizeof(s2) >= sizeof(s)) ? 0 : 3;
+    }],
+    [have_cv_struct_pack=yes],
+    [have_cv_struct_pack=no],
+    [have_cv_struct_pack=yes])
+])
+AC_MSG_RESULT([$have_cv_struct_pack])
+
+if test "$have_cv_struct_pack" = "no"; then
+    AC_MSG_ERROR([Structure packing seems to be available, but is not working with this compiler])
+fi
+
 dnl Check if <sys/select.h> needs to be included for fd_set
 AC_MSG_CHECKING([for fd_set])
 AC_HEADER_EGREP([fd_mask], [sys/select.h], [have_fd_set=yes])
diff --git a/libclamav/others.c b/libclamav/others.c
index e1156bd..59b3a02 100644
--- a/libclamav/others.c
+++ b/libclamav/others.c
@@ -1,5 +1,5 @@
 /*
- *  Copyright (C) 2007-2009 Sourcefire, Inc.
+ *  Copyright (C) 2007-2010 Sourcefire, Inc.
  *
  *  Authors: Tomasz Kojm, Trog
  *
@@ -259,6 +259,11 @@ int cl_init(unsigned int initoptions)
 	struct timeval tv;
 	unsigned int pid = (unsigned int) getpid();
 
+    if (sizeof(unrar_main_header_t) != UNRAR_MAIN_HEADER_TAG_LEN) {
+	cli_errmsg("Structure packing not working, expected %u bytes, got %u bytes\n",
+		   sizeof(unrar_main_header_t), UNRAR_MAIN_HEADER_TAG_LEN);
+	return CL_EARG;
+    }
     /* put dlopen() stuff here, etc. */
     if (lt_init() == 0) {
 	cli_rarload();
diff --git a/libclamav/others.h b/libclamav/others.h
index 3562257..0847f79 100644
--- a/libclamav/others.h
+++ b/libclamav/others.h
@@ -300,6 +300,15 @@ extern int have_rar;
 		     (((v) & 0x00ff000000000000ULL) >> 40) | \
 		     (((v) & 0xff00000000000000ULL) >> 56))
 
+#ifndef HAVE_ATTRIB_PACKED 
+#define __attribute__(x)
+#endif
+#ifdef HAVE_PRAGMA_PACK
+#pragma pack(1)
+#endif
+#ifdef HAVE_PRAGMA_PACK_HPPA
+#pragma pack 1
+#endif
 
 union unaligned_64 {
 	uint64_t una_u64;
@@ -315,18 +324,6 @@ union unaligned_16 {
 	uint16_t una_u16;
 	int16_t una_s16;
 } __attribute__((packed));
-#if WORDS_BIGENDIAN == 0
-
-#ifndef HAVE_ATTRIB_PACKED 
-#define __attribute__(x)
-#endif
-#ifdef HAVE_PRAGMA_PACK
-#pragma pack(1)
-#endif
-#ifdef HAVE_PRAGMA_PACK_HPPA
-#pragma pack 1
-#endif
-
 
 #ifdef HAVE_PRAGMA_PACK
 #pragma pack()
@@ -334,6 +331,9 @@ union unaligned_16 {
 #ifdef HAVE_PRAGMA_PACK_HPPA
 #pragma pack
 #endif
+
+#if WORDS_BIGENDIAN == 0
+
 /* Little endian */
 #define le16_to_host(v)	(v)
 #define le32_to_host(v)	(v)
diff --git a/libclamunrar_iface/unrar_iface.h b/libclamunrar_iface/unrar_iface.h
index da645b0..1024c02 100644
--- a/libclamunrar_iface/unrar_iface.h
+++ b/libclamunrar_iface/unrar_iface.h
@@ -59,6 +59,7 @@ typedef struct unrar_comment_header_tag
     uint16_t comm_crc __attribute__ ((packed));
 } unrar_comment_header_t;
 
+#define UNRAR_MAIN_HEADER_TAG_LEN 13
 typedef struct unrar_main_header_tag
 {
     uint16_t head_crc __attribute__ ((packed));
@@ -91,6 +92,14 @@ typedef struct unrar_file_header_tag
     off_t next_offset __attribute__ ((packed));
 } unrar_fileheader_t;
 
+#ifdef HAVE_PRAGMA_PACK
+#pragma pack()
+#endif
+
+#ifdef HAVE_PRAGMA_PATCH_HPPA
+#pragma pack
+#endif
+
 typedef struct unrar_metadata_tag
 {
     uint64_t pack_size;
@@ -115,13 +124,6 @@ typedef struct unrar_state_tag {
     char filename[1024];
 } unrar_state_t;
 
-#ifdef HAVE_PRAGMA_PACK
-#pragma pack()
-#endif
-
-#ifdef HAVE_PRAGMA_PATCH_HPPA
-#pragma pack
-#endif
 
 int unrar_open(int fd, const char *dirname, unrar_state_t *state);
 int unrar_extract_next_prepare(unrar_state_t *state, const char *dirname);

-- 
Debian repository for ClamAV



More information about the Pkg-clamav-commits mailing list