[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:27:23 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit 44e134312c60e84b152a6a0187a996a763883133
Author: Török Edvin <edwin at clamav.net>
Date: Mon Mar 29 21:06:47 2010 +0300
More fixes for pdf.cbc.
diff --git a/libclamav/bytecode.c b/libclamav/bytecode.c
index 2e1b694..36ca917 100644
--- a/libclamav/bytecode.c
+++ b/libclamav/bytecode.c
@@ -1542,6 +1542,25 @@ static inline int64_t ptr_compose(int32_t id, uint32_t offset)
return (i << 32) | offset;
}
+static inline int get_geptypesize(const struct cli_bc *bc, uint16_t tid)
+{
+ const struct cli_bc_type *ty;
+ if (tid >= bc->num_types+65) {
+ cli_errmsg("bytecode: typeid out of range %u >= %u\n", tid, bc->num_types);
+ return -1;
+ }
+ if (tid <= 64) {
+ cli_errmsg("bytecode: invalid type for gep (%u)\n", tid);
+ return -1;
+ }
+ ty = &bc->types[tid - 65];
+ if (ty->kind != DPointerType) {
+ cli_errmsg("bytecode: invalid gep type, must be pointer: %u\n", tid);
+ return -1;
+ }
+ return typesize(bc, ty->containedTypes[0]);
+}
+
static int cli_bytecode_prepare_interpreter(struct cli_bc *bc)
{
unsigned i, j, k;
@@ -1736,6 +1755,16 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc)
MAPPTR(inst->u.unaryop);
break;
case OP_BC_GEP1:
+ if (bcfunc->types[inst->u.binop[1]]&0x8000) {
+ cli_errmsg("bytecode: gep1 of alloca is not allowed\n");
+ return CL_EBYTECODE;
+ }
+ MAP(inst->u.three[1]);
+ MAP(inst->u.three[2]);
+ inst->u.three[0] = get_geptypesize(bc, inst->u.three[0]);
+ if (inst->u.three[0] == -1)
+ return CL_EBYTECODE;
+ break;
case OP_BC_GEPZ:
/*three[0] is the type*/
if (bcfunc->types[inst->u.three[1]]&0x8000)
@@ -1756,11 +1785,10 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc)
MAPPTR(inst->u.three[1]);
MAP(inst->u.three[2]);
break;
+ case OP_BC_RET_VOID:
case OP_BC_ISBIGENDIAN:
- /*TODO */
- break;
case OP_BC_ABORT:
- /* TODO */
+ /* no operands */
break;
case OP_BC_BSWAP16:
case OP_BC_BSWAP32:
@@ -1768,7 +1796,11 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc)
MAP(inst->u.unaryop);
break;
case OP_BC_PTRDIFF32:
- /*TODO */
+ MAPPTR(inst->u.binop[0]);
+ MAPPTR(inst->u.binop[1]);
+ break;
+ case OP_BC_PTRTOINT64:
+ MAPPTR(inst->u.unaryop);
break;
default:
cli_dbgmsg("Unhandled opcode: %d\n", inst->opcode);
diff --git a/libclamav/bytecode_vm.c b/libclamav/bytecode_vm.c
index ea6779a..44b7de6 100644
--- a/libclamav/bytecode_vm.c
+++ b/libclamav/bytecode_vm.c
@@ -100,7 +100,7 @@ static always_inline int jump(const struct cli_bc_func *func, uint16_t bbid, str
return 0;
}
-#define STACK_CHUNKSIZE 16384
+#define STACK_CHUNKSIZE 32768
struct stack_chunk {
struct stack_chunk *prev;
@@ -485,6 +485,18 @@ static inline int64_t ptr_compose(int32_t id, uint32_t offset)
return (i << 32) | offset;
}
+static inline int32_t ptr_diff32(int64_t ptr1, int64_t ptr2)
+{
+ int32_t ptrid1 = ptr1 >> 32;
+ int32_t ptrid2 = ptr2 >> 32;
+ if (ptrid1 != ptrid2) {
+ bcfail("difference of pointers not pointing to same object!", ptrid1, ptrid2, __FILE__, __LINE__);
+ /* invalid diff */
+ return 0x40000000;
+ }
+ return (uint32_t)ptr1 - (uint32_t)ptr2;
+}
+
static inline int64_t ptr_register_stack(struct ptr_infos *infos,
unsigned char *values,
uint32_t off, uint32_t size)
@@ -643,7 +655,7 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
if (tv1.tv_sec > timeout.tv_sec ||
(tv1.tv_sec == timeout.tv_sec &&
tv1.tv_usec > timeout.tv_usec)) {
- cli_warnmsg("Bytecode run timed out in interpreter\n");
+ cli_warnmsg("Bytecode run timed out in interpreter after %u opcodes\n", pc);
stop = CL_ETIMEOUT;
break;
}
@@ -948,8 +960,8 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
case OP_BC_COPY*5+4:
{
uint64_t op;
- READ32(op, BINOP(0));
- WRITE32(BINOP(1), op);
+ READ64(op, BINOP(0));
+ WRITE64(BINOP(1), op);
break;
}
@@ -1111,6 +1123,41 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
WRITE64(inst->dest, cbswap64(arg1));
break;
}
+ DEFINE_OP(OP_BC_PTRDIFF32) {
+ int64_t ptr1, ptr2;
+ if (BINOP(0)&0x40000000)
+ ptr1 = ptr_compose(stackid, BINOP(0)&0xbfffffff);
+ else
+ READ64(ptr1, BINOP(0));
+ if (BINOP(1)&0x40000000)
+ ptr2 = ptr_compose(stackid, BINOP(1)&0xbfffffff);
+ else
+ READ64(ptr2, BINOP(1));
+ WRITE32(inst->dest, ptr_diff32(ptr1, ptr2));
+ break;
+ }
+ DEFINE_OP(OP_BC_PTRTOINT64) {
+ int64_t ptr;
+ if (inst->u.unaryop&0x40000000)
+ ptr = ptr_compose(stackid, inst->u.unaryop&0xbfffffff);
+ else
+ READ64(ptr, BINOP(0));
+ WRITE64(inst->dest, ptr);
+ break;
+ }
+ DEFINE_OP(OP_BC_GEP1) {
+ int64_t ptr;
+ if (!(inst->interp_op%5)) {
+ int32_t off;
+ READ32(off, inst->u.three[2]);
+ WRITE64(inst->dest, ptr_compose(stackid,
+ inst->u.three[1]+off));
+ } else {
+ READ64(ptr, inst->u.three[1]);
+ WRITE64(inst->dest, ptr);
+ }
+ break;
+ }
/* TODO: implement OP_BC_GEP1, OP_BC_GEP2, OP_BC_GEPN */
default:
cli_errmsg("Opcode %u of type %u is not implemented yet!\n",
@@ -1128,8 +1175,8 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
gettimeofday(&tv1, NULL);
tv1.tv_sec -= tv0.tv_sec;
tv1.tv_usec -= tv0.tv_usec;
- cli_dbgmsg("intepreter bytecode run finished in %luus\n",
- tv1.tv_sec*1000000 + tv1.tv_usec);
+ cli_dbgmsg("intepreter bytecode run finished in %luus, after executing %u opcodes\n",
+ tv1.tv_sec*1000000 + tv1.tv_usec, pc);
}
cli_stack_destroy(&stack);
diff --git a/libclamav/c++/bytecode2llvm.cpp b/libclamav/c++/bytecode2llvm.cpp
index aa8aaaa..1627fb5 100644
--- a/libclamav/c++/bytecode2llvm.cpp
+++ b/libclamav/c++/bytecode2llvm.cpp
@@ -982,6 +982,7 @@ public:
case OP_BC_COPY:
case OP_BC_RET:
case OP_BC_PTRDIFF32:
+ case OP_BC_PTRTOINT64:
// these instructions represents operands differently
break;
default:
@@ -1333,6 +1334,13 @@ public:
Store(inst->dest, R);
break;
}
+ case OP_BC_PTRTOINT64:
+ {
+ Value *P1 = convertOperand(func, inst, inst->u.unaryop);
+ P1 = Builder.CreatePtrToInt(P1, Type::getInt64Ty(Context));
+ Store(inst->dest, P1);
+ break;
+ }
default:
errs() << MODULE << "JIT doesn't implement opcode " <<
inst->opcode << " yet!\n";
diff --git a/libclamav/clambc.h b/libclamav/clambc.h
index 8b4200c..c268b05 100644
--- a/libclamav/clambc.h
+++ b/libclamav/clambc.h
@@ -87,6 +87,7 @@ enum bc_opcode {
OP_BC_BSWAP32,
OP_BC_BSWAP64,
OP_BC_PTRDIFF32,
+ OP_BC_PTRTOINT64,
OP_BC_INVALID /* last */
};
@@ -112,8 +113,8 @@ static const unsigned char operand_counts[] = {
3, 3, 3, 3,
/* OP_BC_ISBIGENDIAN */
0,
- /* OP_BC_ABORT, OP_BSWAP*, OP_PTRDIFF32 */
- 0, 1, 1, 1, 2
+ /* OP_BC_ABORT, OP_BSWAP*, OP_PTRDIFF32, OP_PTRINT64 */
+ 0, 1, 1, 1, 2, 1
};
enum bc_global {
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list