[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:26:58 UTC 2010


The following commit has been merged in the debian/unstable branch:
commit 0d9b99f43eb9835612401944eaccd9991d49fce6
Author: Török Edvin <edwin at clamav.net>
Date:   Sun Mar 28 23:27:05 2010 +0300

    Fix bswap.cbc in interpreter mode.

diff --git a/libclamav/bytecode.c b/libclamav/bytecode.c
index 0a77e41..2e1b694 100644
--- a/libclamav/bytecode.c
+++ b/libclamav/bytecode.c
@@ -1529,6 +1529,13 @@ void cli_bytecode_destroy(struct cli_bc *bc)
     }\
     val = map[o]; } while (0)
 
+#define MAPPTR(val) {\
+    if ((val < bcfunc->numValues) && bcfunc->types[val]&0x8000)\
+      val = map[val] | 0x40000000;\
+    else\
+	MAP(val);\
+}
+
 static inline int64_t ptr_compose(int32_t id, uint32_t offset)
 {
     uint64_t i = id;
@@ -1726,7 +1733,7 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc)
 		    break;
 		}
 		case OP_BC_LOAD:
-		    MAP(inst->u.unaryop);
+		    MAPPTR(inst->u.unaryop);
 		    break;
 		case OP_BC_GEP1:
 		case OP_BC_GEPZ:
@@ -1745,10 +1752,9 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc)
 		case OP_BC_MEMCPY:
 		case OP_BC_MEMMOVE:
 		case OP_BC_MEMCMP:
-		    MAP(inst->u.three[0]);
-		    MAP(inst->u.three[1]);
+		    MAPPTR(inst->u.three[0]);
+		    MAPPTR(inst->u.three[1]);
 		    MAP(inst->u.three[2]);
-		    /*TODO*/
 		    break;
 		case OP_BC_ISBIGENDIAN:
 		    /*TODO */
diff --git a/libclamav/bytecode_vm.c b/libclamav/bytecode_vm.c
index 7029124..c65fb9a 100644
--- a/libclamav/bytecode_vm.c
+++ b/libclamav/bytecode_vm.c
@@ -298,6 +298,15 @@ static always_inline struct stack_entry *pop_stack(struct stack *stack,
     }\
     TRACE_R(x)\
 }
+#define READPOP(x, p, asize) {\
+    if ((p)&0x40000000) {\
+	unsigned ptr__ = (p)&0xbfffffff;\
+	CHECK_GT(func->numBytes, ptr__);\
+	x = (void*)&values[ptr__];\
+    } else {\
+	READP(x, p, asize)\
+    }\
+}
 
 #define READOLD8(x, p) CHECK_GT(func->numBytes, p);\
     x = *(uint8_t*)&old_values[p];\
@@ -928,28 +937,28 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
 	    case OP_BC_LOAD*5+1:
 	    {
 		uint8_t *ptr;
-		READP(ptr, inst->u.unaryop, 1);
+		READPOP(ptr, inst->u.unaryop, 1);
 		WRITE8(inst->dest, (*ptr));
 		break;
 	    }
 	    case OP_BC_LOAD*5+2:
 	    {
 		const union unaligned_16 *ptr;
-		READP(ptr, inst->u.unaryop, 2);
+		READPOP(ptr, inst->u.unaryop, 2);
 		WRITE16(inst->dest, (ptr->una_u16));
 		break;
 	    }
 	    case OP_BC_LOAD*5+3:
 	    {
 		const union unaligned_32 *ptr;
-		READP(ptr, inst->u.unaryop, 4);
+		READPOP(ptr, inst->u.unaryop, 4);
 		WRITE32(inst->dest, (ptr->una_u32));
 		break;
 	    }
 	    case OP_BC_LOAD*5+4:
 	    {
 		const union unaligned_64 *ptr;
-		READP(ptr, inst->u.unaryop, 8);
+		READPOP(ptr, inst->u.unaryop, 8);
 		WRITE64(inst->dest, (ptr->una_u64));
 		break;
 	    }
@@ -1020,47 +1029,47 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
 		int32_t arg3;
 		void *arg1, *arg2;
 		READ32(arg3, inst->u.three[2]);
-		READP(arg1, inst->u.three[0], arg3);
-		READP(arg2, inst->u.three[1], arg3);
+		READPOP(arg1, inst->u.three[0], arg3);
+		READPOP(arg2, inst->u.three[1], arg3);
 		WRITE32(inst->dest, memcmp(arg1, arg2, arg3));
 		break;
 	    }
 	    DEFINE_OP(OP_BC_MEMCPY) {
 		int32_t arg3;
 		void *arg1, *arg2, *resp;
-		int64_t res;
+		int64_t res=0;
 
 		READ32(arg3, inst->u.three[2]);
-		READP(arg1, inst->u.three[0], arg3);
-		READP(arg2, inst->u.three[1], arg3);
+		READPOP(arg1, inst->u.three[0], arg3);
+		READPOP(arg2, inst->u.three[1], arg3);
 		memcpy(arg1, arg2, arg3);
-		READ64(res, inst->u.three[0]);
+/*		READ64(res, inst->u.three[0]);*/
 		WRITE64(inst->dest, res);
 		break;
 	    }
 	    DEFINE_OP(OP_BC_MEMMOVE) {
 		int32_t arg3;
 		void *arg1, *arg2, *resp;
-		int64_t res;
+		int64_t res=0;
 
 		READ32(arg3, inst->u.three[2]);
-		READP(arg1, inst->u.three[0], arg3);
-		READP(arg2, inst->u.three[1], arg3);
+		READPOP(arg1, inst->u.three[0], arg3);
+		READPOP(arg2, inst->u.three[1], arg3);
 		memmove(arg1, arg2, arg3);
-		READ64(res, inst->u.three[0]);
+/*		READ64(res, inst->u.three[0]);*/
 		WRITE64(inst->dest, res);
 		break;
 	    }
 	    DEFINE_OP(OP_BC_MEMSET) {
 		int32_t arg2, arg3;
 		void *arg1;
-		int64_t res;
+		int64_t res=0;
 
 		READ32(arg3, inst->u.three[2]);
-		READP(arg1, inst->u.three[0], arg3);
+		READPOP(arg1, inst->u.three[0], arg3);
 		READ32(arg2, inst->u.three[1]);
 		memset(arg1, arg2, arg3);
-		READ64(res, inst->u.three[0]);
+/*		READ64(res, inst->u.three[0]);*/
 		WRITE64(inst->dest, res);
 		break;
 	    }
diff --git a/unit_tests/check_bytecode.c b/unit_tests/check_bytecode.c
index fdf44c0..c00f214 100644
--- a/unit_tests/check_bytecode.c
+++ b/unit_tests/check_bytecode.c
@@ -213,9 +213,8 @@ END_TEST
 START_TEST (test_bswap)
 {
     cl_init(CL_INIT_DEFAULT);
-    if (have_clamjit)
-	runtest("input/bswap.cbc", 0xbeef, 0, 0, NULL, NULL, NULL, NULL);
-//    runtest("input/bswap.cbc", 0xbeef, 0, 1, NULL, NULL, NULL, NULL);
+    runtest("input/bswap.cbc", 0xbeef, 0, 0, NULL, NULL, NULL, NULL);
+    runtest("input/bswap.cbc", 0xbeef, 0, 1, NULL, NULL, NULL, NULL);
 }
 END_TEST
 
@@ -233,7 +232,6 @@ Suite *test_bytecode_suite(void)
     Suite *s = suite_create("bytecode");
     TCase *tc_cli_arith = tcase_create("arithmetic");
     suite_add_tcase(s, tc_cli_arith);
-#if 0
     tcase_add_test(tc_cli_arith, test_retmagic);
     tcase_add_test(tc_cli_arith, test_arith);
     tcase_add_test(tc_cli_arith, test_apicalls);
@@ -244,7 +242,6 @@ Suite *test_bytecode_suite(void)
     tcase_add_test(tc_cli_arith, test_matchwithread);
     tcase_add_test(tc_cli_arith, test_pdf);
     tcase_add_test(tc_cli_arith, test_bswap);
-#endif
     tcase_add_test(tc_cli_arith, test_inflate);
     return s;
 }

-- 
Debian repository for ClamAV



More information about the Pkg-clamav-commits mailing list