[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 00:57:50 UTC 2010


The following commit has been merged in the debian/unstable branch:
commit f3b2dc9e28873266ef702f7167c1824e5148a11b
Author: Török Edvin <edwin at clamav.net>
Date:   Wed Jul 8 12:45:06 2009 +0300

    Implement ICMP_*.

diff --git a/clambc/bcrun.c b/clambc/bcrun.c
index 858558b..db7201c 100644
--- a/clambc/bcrun.c
+++ b/clambc/bcrun.c
@@ -120,7 +120,10 @@ int main(int argc, char *argv[])
     if (rc != CL_SUCCESS) {
 	fprintf(stderr,"Unable to run bytecode: %s\n", cl_strerror(rc));
     } else {
+	uint64_t v;
 	printf("Bytecode run finished\n");
+	v = cli_bytecode_context_getresult_int(ctx);
+	printf("Bytecode returned: %llx\n", (long long)v);
     }
     cli_bytecode_context_destroy(ctx);
     cli_bytecode_destroy(bc);
diff --git a/libclamav/bytecode.c b/libclamav/bytecode.c
index c6b9fce..05ea51d 100644
--- a/libclamav/bytecode.c
+++ b/libclamav/bytecode.c
@@ -81,7 +81,7 @@ int cli_bytecode_context_setfuncid(struct cli_bc_ctx *ctx, struct cli_bc *bc, un
     }
     for (i=0;i<func->numArgs;i++) {
 	ctx->values[i].ref = MAX_OP;
-	ctx->operands[i+1] = i;
+	ctx->operands[i] = i;
     }
     return CL_SUCCESS;
 }
@@ -453,8 +453,10 @@ static int parseBB(struct cli_bc *bc, unsigned func, unsigned bb, unsigned char
 	    offset++;
 	    /* terminators are void */
 	    inst.type = 0;
+	    inst.dest = 0;
 	} else {
 	    inst.type = readNumber(buffer, &offset, len, &ok);
+	    inst.dest = readNumber(buffer, &offset, len, &ok);
 	}
 	inst.opcode = readFixedNumber(buffer, &offset, len, &ok, 2);
 	if (!ok) {
@@ -527,6 +529,22 @@ static int parseBB(struct cli_bc *bc, unsigned func, unsigned bb, unsigned char
 	    cli_errmsg("More instructions than declared in total!\n");
 	    return CL_EMALFDB;
 	}
+	switch (inst.opcode) {
+	    default:
+		break;
+	    case OP_ICMP_EQ:
+	    case OP_ICMP_NE:
+	    case OP_ICMP_UGT:
+	    case OP_ICMP_UGE:
+	    case OP_ICMP_ULT:
+	    case OP_ICMP_ULE:
+	    case OP_ICMP_SGT:
+	    case OP_ICMP_SGE:
+	    case OP_ICMP_SLE:
+	    case OP_ICMP_SLT:
+		inst.type = bcfunc->allinsts[inst.u.binop[0]].type;
+		break;
+	}
 	BB->insts[BB->numInsts++] = inst;
     }
     if (bb+1 == bc->funcs[func].numBB) {
@@ -542,6 +560,7 @@ static int parseBB(struct cli_bc *bc, unsigned func, unsigned bb, unsigned char
 		   len-offset);
 	return CL_EMALFDB;
     }
+    bcfunc->insn_idx += BB->numInsts;
     return CL_SUCCESS;
 }
 
@@ -628,11 +647,17 @@ int cli_bytecode_run(struct cli_bc *bc, struct cli_bc_ctx *ctx)
     func.numInsts = 1;
 
     inst.opcode = OP_CALL_DIRECT;
+    inst.dest = func.numArgs;
     inst.type = 0;/* TODO: support toplevel functions with return values */
     inst.u.ops.numOps = ctx->numParams;
     inst.u.ops.funcid = ctx->funcid;
     inst.u.ops.ops = ctx->operands;
-    return cli_vm_execute(ctx->bc, ctx, &func, &inst, func.values);
+    return cli_vm_execute(ctx->bc, ctx, &func, &inst);
+}
+
+uint64_t cli_bytecode_context_getresult_int(struct cli_bc_ctx *ctx)
+{
+    return ctx->values[ctx->numParams].v;
 }
 
 void cli_bytecode_destroy(struct cli_bc *bc)
diff --git a/libclamav/bytecode.h b/libclamav/bytecode.h
index d565248..8e04bde 100644
--- a/libclamav/bytecode.h
+++ b/libclamav/bytecode.h
@@ -44,6 +44,7 @@ int cli_bytecode_context_setfuncid(struct cli_bc_ctx *ctx, struct cli_bc *bc, un
 int cli_bytecode_context_setparam_int(struct cli_bc_ctx *ctx, unsigned i, uint64_t c);
 int cli_bytecode_context_setparam_ptr(struct cli_bc_ctx *ctx, unsigned i, void *data, unsigned datalen);
 int cli_bytecode_context_clear(struct cli_bc_ctx *ctx);
+uint64_t cli_bytecode_context_getresult_int(struct cli_bc_ctx *ctx);
 void cli_bytecode_context_destroy(struct cli_bc_ctx *ctx);
 
 int cli_bytecode_load(struct cli_bc *bc, FILE *f, struct cli_dbio *dbio);
diff --git a/libclamav/bytecode_priv.h b/libclamav/bytecode_priv.h
index cfb90bd..479739b 100644
--- a/libclamav/bytecode_priv.h
+++ b/libclamav/bytecode_priv.h
@@ -53,6 +53,7 @@ struct cli_bc_cast {
 struct cli_bc_inst {
     enum bc_opcode opcode;
     uint16_t type;
+    operand_t dest;
     union {
 	operand_t unaryop;
 	struct cli_bc_cast cast;
@@ -92,5 +93,5 @@ struct cli_bc_ctx {
     unsigned numParams;
 };
 
-int cli_vm_execute(struct cli_bc *bc, struct cli_bc_ctx *ctx, struct cli_bc_func *func, struct cli_bc_inst *inst, struct cli_bc_value *value);
+int cli_vm_execute(struct cli_bc *bc, struct cli_bc_ctx *ctx, struct cli_bc_func *func, struct cli_bc_inst *inst);
 #endif
diff --git a/libclamav/bytecode_vm.c b/libclamav/bytecode_vm.c
index ec1b251..214c345 100644
--- a/libclamav/bytecode_vm.c
+++ b/libclamav/bytecode_vm.c
@@ -72,7 +72,10 @@ struct stack_entry {
 #define BINOP(i) (BINOPNOMOD(i)&((1 << inst->type)-1))
 #define UNOP(x) (UNOPNOMOD(i)&((1 << inst->type)-1))
 
-/* get the operand as a signed value */
+/* get the operand as a signed value.
+ * Warning: this assumes that result type is same as operand type.
+ * This is usually true, except for icmp_* and select.
+ * For icmp_* we fix it up in the loader. */
 #define SIGNEXT(a) CLI_SRS(((int64_t)(a)) << (64-inst->type), (64-inst->type))
 #define BINOPS(i) SIGNEXT(BINOPNOMOD(i))
 
@@ -86,31 +89,34 @@ static void jump(struct cli_bc_func *func, uint16_t bbid, struct cli_bc_bb **bb,
     *bb_inst = 0;
 }
 
-int cli_vm_execute(struct cli_bc *bc, struct cli_bc_ctx *ctx, struct cli_bc_func *func, struct cli_bc_inst *inst, struct cli_bc_value *value)
+int cli_vm_execute(struct cli_bc *bc, struct cli_bc_ctx *ctx, struct cli_bc_func *func, struct cli_bc_inst *inst)
 {
     unsigned i, stack_depth=0, bb_inst=0, stop=0;
     struct cli_bc_func *func2;
     struct stack_entry *stack = NULL;
     struct cli_bc_bb *bb = NULL;
-    struct cli_bc_value *values = NULL;
+    struct cli_bc_value *values = func->values;
+    struct cli_bc_value *value;
 
     do {
+	value = &values[inst->dest];
+	CHECK_GT(func->values + func->numArgs+func->numInsts+func->numConstants, value);
 	switch (inst->opcode) {
 	    case OP_ADD:
-		values->v = BINOPNOMOD(0) + BINOPNOMOD(1);
+		value->v = BINOPNOMOD(0) + BINOPNOMOD(1);
 		break;
 	    case OP_SUB:
-		values->v = BINOPNOMOD(0) - BINOPNOMOD(1);
+		value->v = BINOPNOMOD(0) - BINOPNOMOD(1);
 		break;
 	    case OP_MUL:
-		values->v = BINOPNOMOD(0) * BINOPNOMOD(1);
+		value->v = BINOPNOMOD(0) * BINOPNOMOD(1);
 		break;
 	    case OP_UDIV:
 		{
 		    uint64_t d = BINOP(1);
 		    if (UNLIKELY(!d))
 			return CL_EBYTECODE;
-		    values->v = BINOP(0) / d;
+		    value->v = BINOP(0) / d;
 		    break;
 		}
 	    case OP_SDIV:
@@ -119,7 +125,7 @@ int cli_vm_execute(struct cli_bc *bc, struct cli_bc_ctx *ctx, struct cli_bc_func
 		    int64_t b = BINOPS(1);
 		    if (UNLIKELY(b == 0 || (b == -1 && a == (-9223372036854775807LL-1LL))))
 			return CL_EBYTECODE;
-		    values->v = a / b;
+		    value->v = a / b;
 		    break;
 		}
 	    case OP_UREM:
@@ -127,7 +133,7 @@ int cli_vm_execute(struct cli_bc *bc, struct cli_bc_ctx *ctx, struct cli_bc_func
 		    uint64_t d = BINOP(1);
 		    if (UNLIKELY(!d))
 			return CL_EBYTECODE;
-		    values->v = BINOP(0) % d;
+		    value->v = BINOP(0) % d;
 		    break;
 		}
 	    case OP_SREM:
@@ -136,37 +142,37 @@ int cli_vm_execute(struct cli_bc *bc, struct cli_bc_ctx *ctx, struct cli_bc_func
 		    int64_t b = BINOPS(1);
 		    if (UNLIKELY(b == 0 || (b == -1 && (a == -9223372036854775807LL-1LL))))
 			return CL_EBYTECODE;
-		    values->v = a % b;
+		    value->v = a % b;
 		    break;
 		}
 	    case OP_SHL:
-		values->v = BINOPNOMOD(0) << BINOP(1);
+		value->v = BINOPNOMOD(0) << BINOP(1);
 		break;
 	    case OP_LSHR:
-		values->v = BINOP(0) >> BINOP(1);
+		value->v = BINOP(0) >> BINOP(1);
 		break;
 	    case OP_ASHR:
 		{
 		    int64_t v = BINOPS(0);
-		    values->v = CLI_SRS(v, BINOP(1));
+		    value->v = CLI_SRS(v, BINOP(1));
 		    break;
 		}
 	    case OP_AND:
-		values->v = BINOPNOMOD(0) & BINOPNOMOD(1);
+		value->v = BINOPNOMOD(0) & BINOPNOMOD(1);
 		break;
 	    case OP_OR:
-		values->v = BINOPNOMOD(0) | BINOPNOMOD(1);
+		value->v = BINOPNOMOD(0) | BINOPNOMOD(1);
 		break;
 	    case OP_XOR:
-		values->v = BINOPNOMOD(0) ^ BINOPNOMOD(1);
+		value->v = BINOPNOMOD(0) ^ BINOPNOMOD(1);
 		break;
 	    case OP_SEXT:
-		values->v = SIGNEXT(values[inst->u.cast.source].v);
+		value->v = SIGNEXT(values[inst->u.cast.source].v);
 		break;
 	    case OP_TRUNC:
 		/* fall-through */
 	    case OP_ZEXT:
-		values->v = values[inst->u.cast.source].v & values[inst->u.cast.mask].v;
+		value->v = values[inst->u.cast.source].v & values[inst->u.cast.mask].v;
 		break;
 	    case OP_BRANCH:
 		jump(func, (values[inst->u.branch.condition].v&1) ?
@@ -225,7 +231,7 @@ int cli_vm_execute(struct cli_bc *bc, struct cli_bc_ctx *ctx, struct cli_bc_func
 		value->v = BINOPS(0) < BINOPS(1) ? 1 : 0;
 		break;
 	    case OP_SELECT:
-		values->v = (values[inst->u.three[0]].v&1) ?
+		value->v = (values[inst->u.three[0]].v&1) ?
 		    values[inst->u.three[1]].v : values[inst->u.three[2]].v;
 		break;
 	    case OP_CALL_DIRECT:
@@ -257,7 +263,6 @@ int cli_vm_execute(struct cli_bc *bc, struct cli_bc_ctx *ctx, struct cli_bc_func
 	}
 	bb_inst++;
 	inst++;
-	value++;
 	CHECK_GT(bb->numInsts, bb_inst);
     } while (stop == CL_SUCCESS);
 
diff --git a/libclamav/libclamav.map b/libclamav/libclamav.map
index 35aa258..ea2d7be 100644
--- a/libclamav/libclamav.map
+++ b/libclamav/libclamav.map
@@ -152,6 +152,7 @@ CLAMAV_PRIVATE {
     cli_bytecode_context_setfuncid;
     cli_bytecode_context_setparam_int;
     cli_bytecode_context_setparam_ptr;
+    cli_bytecode_context_getresult_int;
     cli_bytecode_context_clear;
   local:
     *;

-- 
Debian repository for ClamAV



More information about the Pkg-clamav-commits mailing list