[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:01:09 UTC 2010


The following commit has been merged in the debian/unstable branch:
commit 7a14dc4ce98fd4bc6252360d0082bb4617167c02
Author: Török Edvin <edwin at clamav.net>
Date:   Mon Aug 24 13:43:08 2009 +0300

    bytecode: prepare for implementing gep.

diff --git a/libclamav/bytecode.c b/libclamav/bytecode.c
index 370bcef..1e80813 100644
--- a/libclamav/bytecode.c
+++ b/libclamav/bytecode.c
@@ -69,13 +69,16 @@ static unsigned typesize(const struct cli_bc *bc, uint16_t type)
 	return 4;
     if (type <= 64)
 	return 8;
-    return 0;
+    return bc->types[type-65].size;
 }
 
 static unsigned typealign(const struct cli_bc *bc, uint16_t type)
 {
-    unsigned size = typesize(bc, type);
-    return size ? size : 1;
+    if (type <= 64) {
+	unsigned size = typesize(bc, type);
+	return size ? size : 1;
+    }
+    return bc->types[type-65].align;
 }
 
 int cli_bytecode_context_setfuncid(struct cli_bc_ctx *ctx, const struct cli_bc *bc, unsigned funcid)
@@ -456,6 +459,7 @@ static void add_static_types(struct cli_bc *bc)
 	bc->types[i].kind = PointerType;
 	bc->types[i].numElements = 1;
 	bc->types[i].containedTypes = &containedTy[i];
+	bc->types[i].size = bc->types[i].align = sizeof(void*);
     }
 }
 
@@ -485,6 +489,7 @@ static int parseTypes(struct cli_bc *bc, unsigned char *buffer)
 	switch (t) {
 	    case 1:
 		ty->kind = FunctionType;
+		ty->size = ty->align = sizeof(void*);
 		parseType(bc, ty, buffer, &offset, len, &ok);
 		if (!ok) {
 		    cli_errmsg("Error parsing type %u\n", i);
@@ -494,6 +499,7 @@ static int parseTypes(struct cli_bc *bc, unsigned char *buffer)
 	    case 2:
 	    case 3:
 		ty->kind = (t == 2) ? StructType : PackedStructType;
+		ty->size = ty->align = 0;/* TODO:calculate size/align of structs */
 		parseType(bc, ty, buffer, &offset, len, &ok);
 		if (!ok) {
 		    cli_errmsg("Error parsing type %u\n", i);
@@ -524,6 +530,12 @@ static int parseTypes(struct cli_bc *bc, unsigned char *buffer)
 		    cli_errmsg("Error parsing type %u\n", i);
 		    return CL_EMALFDB;
 		}
+		if (t == 5) {
+		    ty->size = ty->align = sizeof(void);
+		} else {
+		    ty->size = ty->numElements*typesize(bc, ty->containedTypes[0]);
+		    ty->align = typealign(bc, ty->containedTypes[0]);
+		}
 		break;
 	    default:
 		cli_errmsg("Invalid type kind: %u\n", t);
@@ -1074,10 +1086,6 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc)
 	for (j=0;j<bcfunc->numValues;j++) {
 	    uint16_t ty = bcfunc->types[j];
 	    unsigned align;
-	    if (ty > 64) {
-		cli_errmsg("Bytecode: non-integer types not yet implemented\n");
-		return CL_EMALFDB;
-	    }
 	    align = typealign(bc, ty);
 	    bcfunc->numBytes  = (bcfunc->numBytes + align-1)&(~(align-1));
 	    map[j] = bcfunc->numBytes;
@@ -1179,6 +1187,15 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc)
 		case OP_LOAD:
 		    MAP(inst->u.unaryop);
 		    break;
+		case OP_GEP1:
+		    MAP(inst->u.binop[0]);
+		    MAP(inst->u.binop[1]);
+		    break;
+		case OP_GEP2:
+		    MAP(inst->u.three[0]);
+		    MAP(inst->u.three[1]);
+		    MAP(inst->u.three[2]);
+		    break;
 		default:
 		    cli_dbgmsg("Unhandled opcode: %d\n", inst->opcode);
 		    return CL_EBYTECODE;
diff --git a/libclamav/bytecode_vm.c b/libclamav/bytecode_vm.c
index 49cd564..c094c64 100644
--- a/libclamav/bytecode_vm.c
+++ b/libclamav/bytecode_vm.c
@@ -601,6 +601,10 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
 		old_values = values;
 		stack_entry = allocate_stack(&stack, stack_entry, func2, func, inst->dest,
 					     bb, bb_inst);
+		if (!stack_entry) {
+		    stop = CL_EMEM;
+		    break;
+		}
 		values = stack_entry->values;
 		TRACE_EXEC(inst->u.ops.funcid, inst->dest, inst->type, stack_depth);
 		if (stack_depth > 10000) {
@@ -764,7 +768,7 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
 		ptr->una_u64 = v;
 		break;
 	    }
-
+	    /* TODO: implement OP_GEP1, OP_GEP2, OP_GEPN */
 	    default:
 		cli_errmsg("Opcode %u of type %u is not implemented yet!\n",
 			   inst->interp_op/5, inst->interp_op%5);
@@ -773,7 +777,8 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
 	}
 	bb_inst++;
 	inst++;
-	CHECK_GT(bb->numInsts, bb_inst);
+	if (bb)
+	    CHECK_GT(bb->numInsts, bb_inst);
     } while (stop == CL_SUCCESS);
 
     cli_stack_destroy(&stack);
diff --git a/libclamav/type_desc.h b/libclamav/type_desc.h
index c90451b..77455e6 100644
--- a/libclamav/type_desc.h
+++ b/libclamav/type_desc.h
@@ -33,7 +33,9 @@ enum derived_t {
 struct cli_bc_type {
     enum derived_t kind;
     uint16_t *containedTypes;
+    uint32_t size;
     unsigned numElements;
+    unsigned align;
 };
 
 typedef int32_t (*cli_apicall_int2)(int32_t, int32_t);

-- 
Debian repository for ClamAV



More information about the Pkg-clamav-commits mailing list