[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:10:21 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit 74b00233749c253fa1672ea3ce2a6a62f475b04a
Author: Török Edvin <edwin at clamav.net>
Date: Thu Dec 3 11:37:38 2009 +0200
Fix after merge: update to fmap API.
diff --git a/clambc/bcrun.c b/clambc/bcrun.c
index 8cf73aa..1f8eb5e 100644
--- a/clambc/bcrun.c
+++ b/clambc/bcrun.c
@@ -23,6 +23,8 @@
#include "clamav-config.h"
#endif
#include "cltypes.h"
+#include <sys/time.h>
+#include <stdlib.h>
#include "bytecode.h"
#include "clamav.h"
#include "shared/optparser.h"
@@ -158,18 +160,24 @@ int main(int argc, char *argv[])
}
if ((opt = optget(opts,"input"))->enabled) {
+ fmap_t *map;
fd = open(opt->strarg, O_RDONLY);
if (fd == -1) {
fprintf(stderr, "Unable to open input file %s: %s\n", opt->strarg, strerror(errno));
optfree(opts);
exit(5);
}
- rc = cli_bytecode_context_setfile(ctx, fd);
+ map = fmap(fd, 0, 0);
+ if (!map) {
+ fprintf(stderr, "Unable to map input file %s\n", opt->strarg);
+ }
+ rc = cli_bytecode_context_setfile(ctx, map);
if (rc != CL_SUCCESS) {
fprintf(stderr, "Unable to set file %s: %s\n", opt->strarg, cl_strerror(rc));
optfree(opts);
exit(5);
}
+ funmap(map);
}
diff --git a/libclamav/bytecode.c b/libclamav/bytecode.c
index 3d6e0b1..92688b8 100644
--- a/libclamav/bytecode.c
+++ b/libclamav/bytecode.c
@@ -43,7 +43,7 @@ struct cli_bc_ctx *cli_bytecode_context_alloc(void)
ctx->values = NULL;
ctx->operands = NULL;
ctx->opsizes = NULL;
- ctx->fd = -1;
+ ctx->fmap = NULL;
ctx->off = 0;
ctx->ctx = NULL;
ctx->hooks.match_counts = nomatch;
@@ -1541,24 +1541,22 @@ int cli_bytecode_done(struct cli_all_bc *allbc)
return cli_bytecode_done_jit(allbc);
}
-int cli_bytecode_context_setfile(struct cli_bc_ctx *ctx, int fd)
+int cli_bytecode_context_setfile(struct cli_bc_ctx *ctx, fmap_t *map)
{
struct stat buf;
- ctx->fd = fd;
- if (fstat(fd, &buf) == -1)
- return CL_ESTAT;
- ctx->file_size = buf.st_size;
+ ctx->fmap = map;
+ ctx->file_size = map->len + map->offset;
return 0;
}
-int cli_bytecode_runlsig(const struct cli_all_bc *bcs, const struct cli_bc *bc, const char **virname, const uint32_t* lsigcnt, int fd)
+int cli_bytecode_runlsig(const struct cli_all_bc *bcs, const struct cli_bc *bc, const char **virname, const uint32_t* lsigcnt, fmap_t *map)
{
int ret;
struct cli_bc_ctx ctx;
memset(&ctx, 0, sizeof(ctx));
cli_bytecode_context_setfuncid(&ctx, bc, 0);
ctx.hooks.match_counts = lsigcnt;
- cli_bytecode_context_setfile(&ctx, fd);
+ cli_bytecode_context_setfile(&ctx, map);
cli_dbgmsg("Running bytecode for logical signature match\n");
ret = cli_bytecode_run(bcs, bc, &ctx);
@@ -1580,13 +1578,13 @@ int cli_bytecode_runlsig(const struct cli_all_bc *bcs, const struct cli_bc *bc,
}
int cli_bytecode_runhook(const struct cl_engine *engine, struct cli_bc_ctx *ctx,
- unsigned id, int fd, const char **virname)
+ unsigned id, fmap_t *map, const char **virname)
{
const unsigned *hooks = engine->hooks[id - _BC_START_HOOKS];
unsigned i, hooks_cnt = engine->hooks_cnt[id - _BC_START_HOOKS];
int ret;
- cli_bytecode_context_setfile(ctx, fd);
+ cli_bytecode_context_setfile(ctx, map);
cli_dbgmsg("Bytecode executing hook id %u (%u hooks)\n", id, hooks_cnt);
for (i=0;i < hooks_cnt;i++) {
const struct cli_bc *bc = &engine->bcs.all_bcs[hooks[i]];
diff --git a/libclamav/bytecode.h b/libclamav/bytecode.h
index bc4ec4d..ec33e00 100644
--- a/libclamav/bytecode.h
+++ b/libclamav/bytecode.h
@@ -24,6 +24,7 @@
#include <stdint.h>
#include "clambc.h"
#include <stdio.h>
+#include "fmap.h"
struct cli_dbio;
struct cli_bc_ctx;
@@ -80,7 +81,7 @@ void cli_bytecode_context_setctx(struct cli_bc_ctx *ctx, void *cctx);
int cli_bytecode_context_setfuncid(struct cli_bc_ctx *ctx, const struct cli_bc *bc, unsigned funcid);
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_setfile(struct cli_bc_ctx *ctx, int fd);
+int cli_bytecode_context_setfile(struct cli_bc_ctx *ctx, fmap_t *map);
int cli_bytecode_context_setpe(struct cli_bc_ctx *ctx, const struct cli_pe_hook_data *data);
int cli_bytecode_context_clear(struct cli_bc_ctx *ctx);
/* returns file descriptor, sets tempfile. Caller takes ownership, and is
@@ -99,8 +100,8 @@ int cli_bytecode_done(struct cli_all_bc *allbc);
/* Hooks */
struct cli_exe_info;
-int cli_bytecode_runlsig(const struct cli_all_bc *bcs, const struct cli_bc* bc, const char **virname, const uint32_t* lsigcnt, int fd);
-int cli_bytecode_runhook(const struct cl_engine *engine, struct cli_bc_ctx *ctx, unsigned id, int fd, const char **virname);
+int cli_bytecode_runlsig(const struct cli_all_bc *bcs, const struct cli_bc* bc, const char **virname, const uint32_t* lsigcnt, fmap_t *fmap);
+int cli_bytecode_runhook(const struct cl_engine *engine, struct cli_bc_ctx *ctx, unsigned id, fmap_t *map, const char **virname);
#ifdef __cplusplus
extern "C" {
diff --git a/libclamav/bytecode_api.c b/libclamav/bytecode_api.c
index e3207c9..9fa265a 100644
--- a/libclamav/bytecode_api.c
+++ b/libclamav/bytecode_api.c
@@ -45,15 +45,15 @@ uint32_t cli_bcapi_test1(struct cli_bc_ctx *ctx, uint32_t a, uint32_t b)
int32_t cli_bcapi_read(struct cli_bc_ctx* ctx, uint8_t *data, int32_t size)
{
- if (ctx->fd == -1)
+ if (!ctx->fmap)
return -1;
- return pread(ctx->fd, data, size, ctx->off);
+ return fmap_readn(ctx->fmap, data, ctx->off, size);
}
int32_t cli_bcapi_seek(struct cli_bc_ctx* ctx, int32_t pos, uint32_t whence)
{
off_t off;
- if (ctx->fd == -1)
+ if (!ctx->fmap)
return -1;
switch (whence) {
case 0:
diff --git a/libclamav/bytecode_priv.h b/libclamav/bytecode_priv.h
index 61cc8db..1e371eb 100644
--- a/libclamav/bytecode_priv.h
+++ b/libclamav/bytecode_priv.h
@@ -26,6 +26,7 @@
#include "type_desc.h"
#include "execs.h"
#include "bytecode_hooks.h"
+#include "fmap.h"
typedef uint32_t operand_t;
typedef uint16_t bbid_t;
@@ -114,7 +115,7 @@ struct cli_bc_ctx {
unsigned numParams;
size_t file_size;
off_t off;
- int fd;
+ fmap_t *fmap;
const char *virname;
struct cli_bc_hooks hooks;
int outfd;
diff --git a/libclamav/matcher.c b/libclamav/matcher.c
index e98968f..b009779 100644
--- a/libclamav/matcher.c
+++ b/libclamav/matcher.c
@@ -460,7 +460,7 @@ int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli
ret = CL_VIRUS;
break;
}
- if (cli_bytecode_runlsig(&ctx->engine->bcs, troot->ac_lsigtable[i]->bc, ctx->virname, tdata.lsigcnt[i], desc) == CL_VIRUS) {
+ if (cli_bytecode_runlsig(&ctx->engine->bcs, troot->ac_lsigtable[i]->bc, ctx->virname, tdata.lsigcnt[i], map) == CL_VIRUS) {
ret = CL_VIRUS;
break;
}
@@ -482,7 +482,7 @@ int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli
ret = CL_VIRUS;
break;
}
- if (cli_bytecode_runlsig(&ctx->engine->bcs, groot->ac_lsigtable[i]->bc, ctx->virname, gdata.lsigcnt[i], desc) == CL_VIRUS) {
+ if (cli_bytecode_runlsig(&ctx->engine->bcs, groot->ac_lsigtable[i]->bc, ctx->virname, gdata.lsigcnt[i], map) == CL_VIRUS) {
ret = CL_VIRUS;
break;
}
diff --git a/libclamav/pe.c b/libclamav/pe.c
index 12d67be..9f73d83 100644
--- a/libclamav/pe.c
+++ b/libclamav/pe.c
@@ -424,7 +424,6 @@ int cli_scanpe(cli_ctx *ctx)
cli_errmsg("cli_scanpe: ctx == NULL\n");
return CL_ENULLARG;
}
- offset = lseek(desc, 0, SEEK_CUR);
map = *ctx->fmap;
if(fmap_readn(map, &e_magic, 0, sizeof(e_magic)) != sizeof(e_magic)) {
cli_dbgmsg("Can't read DOS signature\n");
@@ -2130,7 +2129,7 @@ int cli_scanpe(cli_ctx *ctx)
pedata.overlays_sz = fsize - overlays;
cli_bytecode_context_setpe(bc_ctx, &pedata);
cli_bytecode_context_setctx(bc_ctx, ctx);
- ret = cli_bytecode_runhook(ctx->engine, bc_ctx, BC_PE_UNPACKER, desc, ctx->virname);
+ ret = cli_bytecode_runhook(ctx->engine, bc_ctx, BC_PE_UNPACKER, map, ctx->virname);
switch (ret) {
case CL_VIRUS:
return CL_VIRUS;
diff --git a/libclamav/readdb.c b/libclamav/readdb.c
index 1685344..5545857 100644
--- a/libclamav/readdb.c
+++ b/libclamav/readdb.c
@@ -900,14 +900,11 @@ static int load_oneldb(char *buffer, int chkpua, int chkign, struct cl_engine *e
return CL_EMALFDB;
}
subsigs = tokens_count-3;
+ } else if(subsigs != tokens_count - 3) {
+ cli_errmsg("cli_loadldb: The number of subsignatures (== %u) doesn't match the IDs in the logical expression (== %u)\n", tokens_count - 3, subsigs);
+ return CL_EMALFDB;
}
- if(subsigs != tokens_count - 3) {
- cli_errmsg("cli_loadldb: The number of subsignatures (== %u) doesn't match the IDs in the logical expression (== %u)\n", tokens_count - 3, subsigs);
- ret = CL_EMALFDB;
- break;
- }
-
/* TDB */
memset(&tdb, 0, sizeof(tdb));
#ifdef USE_MPOOL
@@ -962,10 +959,6 @@ static int load_oneldb(char *buffer, int chkpua, int chkign, struct cl_engine *e
root->ac_lsigtable = newtable;
for(i = 0; i < subsigs; i++) {
- if(i + 3 >= tokens_count) {
- cli_errmsg("cli_loadldb: Missing subsignature id %u\n", i);
- return CL_EMALFDB;
- }
lsigid[1] = i;
sig = tokens[3 + i];
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list