[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:04:44 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit 7189addbde77277e6df7e40bd350be0e4c243865
Author: Török Edvin <edwin at clamav.net>
Date: Fri Sep 11 15:12:17 2009 +0300
WiP on debug APi.
diff --git a/libclamav/bytecode.c b/libclamav/bytecode.c
index 72b51b4..79fc356 100644
--- a/libclamav/bytecode.c
+++ b/libclamav/bytecode.c
@@ -666,10 +666,7 @@ static uint16_t type_components(struct cli_bc *bc, uint16_t id, char *ok)
*ok = 0;
return 0;
case DPointerType:
- cli_errmsg("bytecode: pointer type not accepted for constant: %u\n", id);
- /* don't accept pointer initializers */
- *ok = 0;
- return 0;
+ return 2;
case DStructType:
case DPackedStructType:
for (i=0;i<ty->numElements;i++) {
@@ -690,7 +687,7 @@ static void readConstant(struct cli_bc *bc, unsigned i, unsigned comp,
{
unsigned j=0;
while (*ok && buffer[*offset] != 0x60) {
- if (j > comp) {
+ if (j >= comp) {
cli_errmsg("bytecode: constant has too many subcomponents, expected %u\n", comp);
*ok = 0;
return;
@@ -701,7 +698,7 @@ static void readConstant(struct cli_bc *bc, unsigned i, unsigned comp,
if (*ok && j != comp) {
cli_errmsg("bytecode: constant has too few subcomponents: %u < %u\n", j, comp);
}
- *offset++;
+ (*offset)++;
}
/* parse constant globals with constant initializers */
@@ -741,6 +738,11 @@ static int parseGlobals(struct cli_bc *bc, unsigned char *buffer)
}
if (!ok)
return CL_EMALFDB;
+ if (offset != len) {
+ cli_errmsg("Trailing garbage in globals: %d extra bytes\n",
+ len-offset);
+ return CL_EMALFDB;
+ }
return CL_SUCCESS;
}
diff --git a/libclamav/bytecode_api.c b/libclamav/bytecode_api.c
index 2286fe5..af5bb9f 100644
--- a/libclamav/bytecode_api.c
+++ b/libclamav/bytecode_api.c
@@ -29,6 +29,7 @@
#include "type_desc.h"
#include "bytecode_api.h"
#include "bytecode_api_impl.h"
+#include "others.h"
uint32_t cli_bcapi_test0(struct cli_bc_ctx *ctx, struct foo* s, uint32_t u)
{
@@ -68,3 +69,14 @@ int32_t cli_bcapi_seek(struct cli_bc_ctx* ctx, int32_t pos, uint32_t whence)
ctx->off = off;
return off;
}
+
+uint32_t cli_bcapi_debug_print_str(struct cli_bc_ctx *ctx, uint8_t *str, uint32_t len)
+{
+ cli_dbgmsg("bytecode debug: %s\n", str);
+ return 0;
+}
+
+uint32_t cli_bcapi_debug_print_uint(struct cli_bc_ctx *ctx, uint32_t a, uint32_t b)
+{
+ cli_dbgmsg("bytecode debug: %u\n", a);
+}
diff --git a/libclamav/bytecode_api.h b/libclamav/bytecode_api.h
index 002b47f..eec47cc 100644
--- a/libclamav/bytecode_api.h
+++ b/libclamav/bytecode_api.h
@@ -36,7 +36,7 @@ uint32_t test0(struct foo*, uint32_t);
uint32_t test1(uint32_t, uint32_t);
/* reads @size bytes from current file (if any) to @data, returns amount read */
-int32_t read(uint8_t *data, int32_t size);
+uint32_t read(uint8_t *data, uint32_t size);
enum {
SEEK_SET=0,
@@ -48,4 +48,7 @@ enum {
* start of file */
int32_t seek(int32_t pos, uint32_t whence);
+uint32_t debug_print_str(uint8_t *str, uint32_t len);
+uint32_t debug_print_uint(uint32_t a, uint32_t b);
+
#endif
diff --git a/libclamav/bytecode_api_decl.c b/libclamav/bytecode_api_decl.c
index f4e029b..290e1aa 100644
--- a/libclamav/bytecode_api_decl.c
+++ b/libclamav/bytecode_api_decl.c
@@ -28,6 +28,8 @@ uint32_t cli_bcapi_test0(struct cli_bc_ctx *ctx, struct foo*, uint32_t);
uint32_t cli_bcapi_test1(struct cli_bc_ctx *ctx, uint32_t, uint32_t);
int32_t cli_bcapi_read(struct cli_bc_ctx *ctx, uint8_t*, int32_t);
int32_t cli_bcapi_seek(struct cli_bc_ctx *ctx, int32_t, uint32_t);
+uint32_t cli_bcapi_debug_print_str(struct cli_bc_ctx *ctx, uint8_t*, uint32_t);
+uint32_t cli_bcapi_debug_print_uint(struct cli_bc_ctx *ctx, uint32_t, uint32_t);
static uint16_t cli_tmp0[]={32, 70, 32};
static uint16_t cli_tmp1[]={71};
@@ -49,15 +51,19 @@ const struct cli_apicall cli_apicalls[]={
{"test0", 0, 0, 1},
{"test1", 3, 0, 0},
{"read", 4, 1, 1},
- {"seek", 3, 1, 0}
+ {"seek", 3, 1, 0},
+ {"debug_print_str", 4, 2, 1},
+ {"debug_print_uint", 3, 2, 0}
/* Bytecode APIcalls END */
};
const cli_apicall_int2 cli_apicalls0[] = {
(cli_apicall_int2)cli_bcapi_test1,
- (cli_apicall_int2)cli_bcapi_seek
+ (cli_apicall_int2)cli_bcapi_seek,
+ (cli_apicall_int2)cli_bcapi_debug_print_uint
};
const cli_apicall_pointer cli_apicalls1[] = {
(cli_apicall_pointer)cli_bcapi_test0,
- (cli_apicall_pointer)cli_bcapi_read
+ (cli_apicall_pointer)cli_bcapi_read,
+ (cli_apicall_pointer)cli_bcapi_debug_print_str
};
const unsigned cli_apicall_maxapi = sizeof(cli_apicalls)/sizeof(cli_apicalls[0]);
diff --git a/libclamav/bytecode_api_impl.h b/libclamav/bytecode_api_impl.h
index 0c2191d..be45600 100644
--- a/libclamav/bytecode_api_impl.h
+++ b/libclamav/bytecode_api_impl.h
@@ -25,3 +25,5 @@ uint32_t cli_bcapi_test1(struct cli_bc_ctx *, uint32_t, uint32_t);
int32_t cli_bcapi_read(struct cli_bc_ctx*, uint8_t *data, int32_t size);
int32_t cli_bcapi_seek(struct cli_bc_ctx*, int32_t pos, uint32_t whence);
+uint32_t cli_bcapi_debug_print_str(struct cli_bc_ctx *ctx, uint8_t*, uint32_t);
+uint32_t cli_bcapi_debug_print_uint(struct cli_bc_ctx *ctx, uint32_t, uint32_t);
diff --git a/libclamav/c++/bytecode2llvm.cpp b/libclamav/c++/bytecode2llvm.cpp
index d167d08..0a81258 100644
--- a/libclamav/c++/bytecode2llvm.cpp
+++ b/libclamav/c++/bytecode2llvm.cpp
@@ -234,7 +234,11 @@ private:
operand &= 0x7fffffff;
assert(operand < globals.size() && "Global index out of range");
// Global
- return globals[operand];
+ GlobalVariable *GV = globals[operand];
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(GV->getInitializer())) {
+ return CE;
+ }
+ return GV;
}
// Constant
operand -= func->numValues;
@@ -292,6 +296,14 @@ private:
Constant *buildConstant(const Type *Ty, uint64_t *components, unsigned &c)
{
+ if (isa<PointerType>(Ty)) {
+ Constant *idxs[2] = {
+ ConstantInt::get(Type::getInt32Ty(Context), 0),
+ ConstantInt::get(Type::getInt32Ty(Context), components[c++])
+ };
+ GlobalVariable *GV = globals[components[c++]];
+ return ConstantExpr::getInBoundsGetElementPtr(GV, idxs, 2);
+ }
if (isa<IntegerType>(Ty)) {
return ConstantInt::get(Ty, components[c++]);
}
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list