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


The following commit has been merged in the debian/unstable branch:
commit b56bea54d3add1fe21a241c8dca1291c2dcd4da0
Author: Török Edvin <edwin at clamav.net>
Date:   Fri Mar 19 13:20:59 2010 +0200

    New API for buffer fill.

diff --git a/libclamav/bytecode_api.c b/libclamav/bytecode_api.c
index e60fc1a..d18e4ce 100644
--- a/libclamav/bytecode_api.c
+++ b/libclamav/bytecode_api.c
@@ -57,10 +57,11 @@ int32_t cli_bcapi_read(struct cli_bc_ctx* ctx, uint8_t *data, int32_t size)
     int n;
     if (!ctx->fmap)
 	return -1;
-    if (size < 0) {
+    if (size < 0 || size > CLI_MAX_ALLOCATION) {
 	cli_errmsg("bytecode: negative read size: %d\n", size);
 	return -1;
     }
+/*    cli_dbgmsg("read data at %d\n", ctx->off);*/
     n = fmap_readn(ctx->fmap, data, ctx->off, size);
     if (n <= 0)
 	return n;
@@ -358,3 +359,27 @@ int32_t cli_bcapi_get_pe_section(struct cli_bc_ctx *ctx, struct cli_exe_section*
     }
     return -1;
 }
+
+int32_t cli_bcapi_fill_buffer(struct cli_bc_ctx *ctx, uint8_t* buf,
+			      uint32_t buflen, uint32_t filled,
+			      uint32_t pos, uint32_t fill)
+{
+    int32_t res, remaining, tofill;
+    if (!buf || !buflen || buflen > CLI_MAX_ALLOCATION || filled > buflen)
+	return -1;
+    if (ctx->off >= ctx->file_size)
+	return 0;
+    remaining = filled - pos;
+    if (remaining) {
+	if (!CLI_ISCONTAINED(buf, buflen, buf+pos, remaining))
+	    return -1;
+	memmove(buf, buf+pos, remaining);
+    }
+    tofill = buflen - remaining;
+    if (!CLI_ISCONTAINED(buf, buflen, buf+remaining, tofill))
+	return -1;
+    res = cli_bcapi_read(ctx, buf+remaining, tofill);
+    if (res <= 0)
+	return res;
+    return remaining + res;
+}
diff --git a/libclamav/bytecode_api.h b/libclamav/bytecode_api.h
index 8892453..d7ed681 100644
--- a/libclamav/bytecode_api.h
+++ b/libclamav/bytecode_api.h
@@ -174,7 +174,7 @@ uint32_t pe_rawaddr(uint32_t rva);
   * @param[in] data the sequence of bytes to look for
   * @param len length of \p data, cannot be more than 1024
   * @return offset in the current file if match is found, -1 otherwise */
-int32_t file_find(const uint8_t* data, uint32_t len); 
+int32_t file_find(const uint8_t* data, uint32_t len);
 
 /** Read a single byte from current file
   * @param offset file offset
@@ -190,7 +190,23 @@ void* malloc(uint32_t size);
 
 uint32_t test2(uint32_t a);
 
+/** Gets information about the specified PE section.
+ * @param[out] section PE section information will be stored here
+ * @param[in] num PE section number */
 int32_t get_pe_section(struct cli_exe_section *section, uint32_t num);
 
+/** Fills the specified buffer with at least \p fill bytes.
+ * @param[out] buffer the buffer to fill
+ * @param[in] len length of buffer
+ * @param[in] filled how much of the buffer is currently filled
+ * @param[in] cursor position of cursor in buffer
+ * @param[in] fill amount of bytes to fill in (0 is valid)
+ * @return <0 on error,
+ *          0 on EOF,
+ *          number bytes available in buffer (starting from 0)
+ * The character at the cursor will be at position 0 after this call.
+ */
+int32_t fill_buffer(uint8_t* buffer, uint32_t len, uint32_t filled, uint32_t cur, uint32_t fill);
+
 #endif
 #endif
diff --git a/libclamav/bytecode_api_decl.c b/libclamav/bytecode_api_decl.c
index 0837ab5..8454355 100644
--- a/libclamav/bytecode_api_decl.c
+++ b/libclamav/bytecode_api_decl.c
@@ -53,6 +53,7 @@ int32_t cli_bcapi_file_byteat(struct cli_bc_ctx *ctx, uint32_t);
 uint8_t* cli_bcapi_malloc(struct cli_bc_ctx *ctx, uint32_t);
 uint32_t cli_bcapi_test2(struct cli_bc_ctx *ctx, uint32_t);
 int32_t cli_bcapi_get_pe_section(struct cli_bc_ctx *ctx, struct cli_exe_section*, uint32_t);
+int32_t cli_bcapi_fill_buffer(struct cli_bc_ctx *ctx, uint8_t*, uint32_t, uint32_t, uint32_t, uint32_t);
 
 const struct cli_apiglobal cli_globals[] = {
 /* Bytecode globals BEGIN */
@@ -75,19 +76,20 @@ static uint16_t cli_tmp4[]={16, 8, 8, 32, 32, 32, 32, 32, 32, 32, 32, 32, 16, 16
 static uint16_t cli_tmp5[]={32, 16, 16, 32, 32, 32, 16, 16};
 static uint16_t cli_tmp6[]={32};
 static uint16_t cli_tmp7[]={32};
-static uint16_t cli_tmp8[]={32, 78, 32};
-static uint16_t cli_tmp9[]={79};
-static uint16_t cli_tmp10[]={32, 32, 32, 32, 32, 32, 32, 32, 32};
-static uint16_t cli_tmp11[]={32, 32};
-static uint16_t cli_tmp12[]={65, 32};
-static uint16_t cli_tmp13[]={32, 65, 32};
-static uint16_t cli_tmp14[]={32, 84, 32};
-static uint16_t cli_tmp15[]={85};
-static uint16_t cli_tmp16[]={16, 8, 8, 8, 87, 86};
-static uint16_t cli_tmp17[]={8};
-static uint16_t cli_tmp18[]={88};
-static uint16_t cli_tmp19[]={8};
-static uint16_t cli_tmp20[]={32, 32, 32};
+static uint16_t cli_tmp8[]={32, 65, 32, 32, 32, 32};
+static uint16_t cli_tmp9[]={32, 79, 32};
+static uint16_t cli_tmp10[]={80};
+static uint16_t cli_tmp11[]={32, 32, 32, 32, 32, 32, 32, 32, 32};
+static uint16_t cli_tmp12[]={32, 32};
+static uint16_t cli_tmp13[]={65, 32};
+static uint16_t cli_tmp14[]={32, 65, 32};
+static uint16_t cli_tmp15[]={32, 85, 32};
+static uint16_t cli_tmp16[]={86};
+static uint16_t cli_tmp17[]={16, 8, 8, 8, 88, 87};
+static uint16_t cli_tmp18[]={8};
+static uint16_t cli_tmp19[]={89};
+static uint16_t cli_tmp20[]={8};
+static uint16_t cli_tmp21[]={32, 32, 32};
 
 const struct cli_bc_type cli_apicall_types[]={
 	{DStructType, cli_tmp0, 11, 0, 0},
@@ -98,44 +100,46 @@ const struct cli_bc_type cli_apicall_types[]={
 	{DStructType, cli_tmp5, 8, 0, 0},
 	{DArrayType, cli_tmp6, 1, 0, 0},
 	{DArrayType, cli_tmp7, 64, 0, 0},
-	{DFunctionType, cli_tmp8, 3, 0, 0},
-	{DPointerType, cli_tmp9, 1, 0, 0},
-	{DStructType, cli_tmp10, 9, 0, 0},
-	{DFunctionType, cli_tmp11, 2, 0, 0},
+	{DFunctionType, cli_tmp8, 6, 0, 0},
+	{DFunctionType, cli_tmp9, 3, 0, 0},
+	{DPointerType, cli_tmp10, 1, 0, 0},
+	{DStructType, cli_tmp11, 9, 0, 0},
 	{DFunctionType, cli_tmp12, 2, 0, 0},
-	{DFunctionType, cli_tmp13, 3, 0, 0},
+	{DFunctionType, cli_tmp13, 2, 0, 0},
 	{DFunctionType, cli_tmp14, 3, 0, 0},
-	{DPointerType, cli_tmp15, 1, 0, 0},
-	{DStructType, cli_tmp16, 6, 0, 0},
-	{DArrayType, cli_tmp17, 29, 0, 0},
-	{DArrayType, cli_tmp18, 3, 0, 0},
-	{DArrayType, cli_tmp19, 10, 0, 0},
-	{DFunctionType, cli_tmp20, 3, 0, 0}
+	{DFunctionType, cli_tmp15, 3, 0, 0},
+	{DPointerType, cli_tmp16, 1, 0, 0},
+	{DStructType, cli_tmp17, 6, 0, 0},
+	{DArrayType, cli_tmp18, 29, 0, 0},
+	{DArrayType, cli_tmp19, 3, 0, 0},
+	{DArrayType, cli_tmp20, 10, 0, 0},
+	{DFunctionType, cli_tmp21, 3, 0, 0}
 };
 
 const unsigned cli_apicall_maxtypes=sizeof(cli_apicall_types)/sizeof(cli_apicall_types[0]);
 const struct cli_apicall cli_apicalls[]={
 /* Bytecode APIcalls BEGIN */
-	{"test1", 20, 0, 0},
-	{"read", 13, 0, 1},
-	{"write", 13, 1, 1},
-	{"seek", 20, 1, 0},
-	{"setvirusname", 13, 2, 1},
-	{"debug_print_str", 13, 3, 1},
-	{"debug_print_uint", 11, 0, 2},
-	{"disasm_x86", 14, 4, 1},
-	{"trace_directory", 13, 5, 1},
-	{"trace_scope", 13, 6, 1},
-	{"trace_source", 13, 7, 1},
-	{"trace_op", 13, 8, 1},
-	{"trace_value", 13, 9, 1},
-	{"trace_ptr", 13, 10, 1},
-	{"pe_rawaddr", 11, 1, 2},
-	{"file_find", 13, 11, 1},
-	{"file_byteat", 11, 2, 2},
-	{"malloc", 12, 0, 3},
-	{"test2", 11, 3, 2},
-	{"get_pe_section", 8, 12, 1}
+	{"test1", 21, 0, 0},
+	{"read", 14, 0, 1},
+	{"write", 14, 1, 1},
+	{"seek", 21, 1, 0},
+	{"setvirusname", 14, 2, 1},
+	{"debug_print_str", 14, 3, 1},
+	{"debug_print_uint", 12, 0, 2},
+	{"disasm_x86", 15, 4, 1},
+	{"trace_directory", 14, 5, 1},
+	{"trace_scope", 14, 6, 1},
+	{"trace_source", 14, 7, 1},
+	{"trace_op", 14, 8, 1},
+	{"trace_value", 14, 9, 1},
+	{"trace_ptr", 14, 10, 1},
+	{"pe_rawaddr", 12, 1, 2},
+	{"file_find", 14, 11, 1},
+	{"file_byteat", 12, 2, 2},
+	{"malloc", 13, 0, 3},
+	{"test2", 12, 3, 2},
+	{"get_pe_section", 9, 12, 1},
+	{"fill_buffer", 8, 0, 4}
 /* Bytecode APIcalls END */
 };
 const cli_apicall_int2 cli_apicalls0[] = {
@@ -166,4 +170,7 @@ const cli_apicall_int1 cli_apicalls2[] = {
 const cli_apicall_malloclike cli_apicalls3[] = {
 	(cli_apicall_malloclike)cli_bcapi_malloc
 };
+const cli_apicall_ptrbuffdata cli_apicalls4[] = {
+	(cli_apicall_ptrbuffdata)cli_bcapi_fill_buffer
+};
 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 a7ef6f3..c186cdf 100644
--- a/libclamav/bytecode_api_impl.h
+++ b/libclamav/bytecode_api_impl.h
@@ -50,5 +50,6 @@ int32_t cli_bcapi_file_byteat(struct cli_bc_ctx *ctx, uint32_t);
 uint8_t* cli_bcapi_malloc(struct cli_bc_ctx *ctx, uint32_t);
 uint32_t cli_bcapi_test2(struct cli_bc_ctx *ctx, uint32_t);
 int32_t cli_bcapi_get_pe_section(struct cli_bc_ctx *ctx, struct cli_exe_section*, uint32_t);
+int32_t cli_bcapi_fill_buffer(struct cli_bc_ctx *ctx, uint8_t*, uint32_t, uint32_t, uint32_t, uint32_t);
 
 #endif
diff --git a/libclamav/c++/ClamBCRTChecks.cpp b/libclamav/c++/ClamBCRTChecks.cpp
index a6024a2..bac1bda 100644
--- a/libclamav/c++/ClamBCRTChecks.cpp
+++ b/libclamav/c++/ClamBCRTChecks.cpp
@@ -125,6 +125,7 @@ namespace {
 		BBI->replaceAllUsesWith(UndefValue::get(BBI->getType()));
 	    BB->getInstList().erase(BBI++);
 	}
+	DEBUG(F.dump());
       }
       return Changed;
     }
diff --git a/libclamav/c++/bytecode2llvm.cpp b/libclamav/c++/bytecode2llvm.cpp
index bb3f8fd..3cb4815 100644
--- a/libclamav/c++/bytecode2llvm.cpp
+++ b/libclamav/c++/bytecode2llvm.cpp
@@ -1399,6 +1399,9 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
 		case 3:
 		    dest = (void*)(intptr_t)cli_apicalls3[api->idx];
 		    break;
+		case 4:
+		    dest = (void*)(intptr_t)cli_apicalls4[api->idx];
+		    break;
 		default:
 		    llvm_unreachable("invalid api type");
 	    }
diff --git a/libclamav/type_desc.h b/libclamav/type_desc.h
index 6614b1b..d9cf85d 100644
--- a/libclamav/type_desc.h
+++ b/libclamav/type_desc.h
@@ -45,6 +45,7 @@ typedef uint32_t (*cli_apicall_int2)(struct cli_bc_ctx *, uint32_t, uint32_t);
 typedef uint32_t (*cli_apicall_pointer)(struct cli_bc_ctx *, void*, uint32_t);
 typedef uint32_t (*cli_apicall_int1)(struct cli_bc_ctx *, uint32_t);
 typedef void* (*cli_apicall_malloclike)(struct cli_bc_ctx *, uint32_t);
+typedef void* (*cli_apicall_ptrbuffdata)(struct cli_bc_ctx *, void*, uint32_t, uint32_t, uint32_t, uint32_t);
 
 struct cli_apicall {
     const char *name;
@@ -73,6 +74,7 @@ extern const cli_apicall_int2 cli_apicalls0[];
 extern const cli_apicall_pointer cli_apicalls1[];
 extern const cli_apicall_int1 cli_apicalls2[];
 extern const cli_apicall_malloclike cli_apicalls3[];
+extern const cli_apicall_ptrbuffdata cli_apicalls4[];
 extern const unsigned cli_apicall_maxapi;
 extern const unsigned cli_apicall_maxglobal;
 
diff --git a/unit_tests/input/apicalls.cbc b/unit_tests/input/apicalls.cbc
index 46e8a04..08dd3a7 100644
--- a/unit_tests/input/apicalls.cbc
+++ b/unit_tests/input/apicalls.cbc
@@ -1,4 +1,4 @@
-ClamBCafhdndbigkd|afefdfggifnf```````|bhacflfafmfbfcfmb`cnb`cacmbacdcmbgfafdfccacacbfgc``agafp`clamcoincidencejb:82
+ClamBCafhkfogjikd|afefdfggifnf```````|ahbf`ceccficacbf``agafp`clamcoincidencejb:82
 
 Tedaaa`aacb`bb`bb`b
 Eaaaaaabfd|afdgefcgdgac``
diff --git a/unit_tests/input/apicalls2.cbc b/unit_tests/input/apicalls2.cbc
index ace3518..c7f6a1e 100644
--- a/unit_tests/input/apicalls2.cbc
+++ b/unit_tests/input/apicalls2.cbc
@@ -1,4 +1,4 @@
-ClamBCafhdndbigkd|afefdfggifnf```````|bhacflfafmfbfcfmb`cnb`cacmbacdcmbgfafdfccacacbfgc``ahafp`clamcoincidencejb:66
+ClamBCafhkfogjikd|afefdfggifnf```````|ahbf`ceccficacbf``ahafp`clamcoincidencejb:66
 
 Tedaaa`aabb`bb`baacb`bb`bb`b
 Ebcaabbcabfd|afdgefcgdgbc``aabgd|afdgefcgdgac``
diff --git a/unit_tests/input/arith.cbc b/unit_tests/input/arith.cbc
index 4f53150..843f7f5 100644
--- a/unit_tests/input/arith.cbc
+++ b/unit_tests/input/arith.cbc
@@ -1,4 +1,4 @@
-ClamBCafhdndbigkd|afefdfggifnf```````|bhacflfafmfbfcfmb`cnb`cacmbacdcmbgfafdfccacacbfgc``afbbep`clamcoincidencejb:418
+ClamBCafhlfogjikd|afefdfggifnf```````|ahbf`ceccficacbf``afbbep`clamcoincidencejb:418
 
 Tedaaa`
 E``
diff --git a/unit_tests/input/div0.cbc b/unit_tests/input/div0.cbc
index c76e410..09d2089 100644
--- a/unit_tests/input/div0.cbc
+++ b/unit_tests/input/div0.cbc
@@ -1,4 +1,4 @@
-ClamBCafhdndbigkd|afefdfggifnf```````|bhacflfafmfbfcfmb`cnb`cacmbacdcmbgfafdfccacacbfgc``afabp`clamcoincidencejb:23
+ClamBCafhlfogjikd|afefdfggifnf```````|ahbf`ceccficacbf``afabp`clamcoincidencejb:23
 
 Tedaaa`
 E``
diff --git a/unit_tests/input/retmagic.cbc b/unit_tests/input/retmagic.cbc
index 8faf4fb..c93a6bf 100644
--- a/unit_tests/input/retmagic.cbc
+++ b/unit_tests/input/retmagic.cbc
@@ -1,4 +1,4 @@
-ClamBCafhdndbigkd|afefdfggifnf```````|bhacflfafmfbfcfmb`cnb`cacmbacdcmbgfafdfccacacbfgc``afaap`clamcoincidencejb:20
+ClamBCafhlfogjikd|afefdfggifnf```````|ahbf`ceccficacbf``afaap`clamcoincidencejb:20
 
 Tedaaa`
 E``

-- 
Debian repository for ClamAV



More information about the Pkg-clamav-commits mailing list