[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b
aCaB
acab at clamav.net
Sun Apr 4 01:02:50 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit cceea458224919672d7adda06721dc07b4c25658
Author: aCaB <acab at clamav.net>
Date: Mon Aug 31 04:41:06 2009 +0200
cli_fmap_scandesc
diff --git a/libclamav/fmap.c b/libclamav/fmap.c
index 732de30..493a293 100644
--- a/libclamav/fmap.c
+++ b/libclamav/fmap.c
@@ -53,19 +53,6 @@
#define READAHEAD_PAGES 4
-struct F_MAP {
- int fd;
- time_t mtime;
- size_t offset;
- size_t len;
- unsigned int pages;
- unsigned int hdrsz;
- unsigned int pgsz;
- unsigned int paged;
- uint32_t bitmap[]; /* FIXME: do not use flexible arrays */
-};
-
-
static unsigned int fmap_align_items(unsigned int sz, unsigned int al) {
return sz / al + (sz % al != 0);
}
diff --git a/libclamav/fmap.h b/libclamav/fmap.h
index fa9889f..b07a9e2 100644
--- a/libclamav/fmap.h
+++ b/libclamav/fmap.h
@@ -21,7 +21,19 @@
#ifndef __FMAP_H
#define __FMAP_H
-struct F_MAP;
+#include "cltypes.h"
+
+struct F_MAP {
+ int fd;
+ time_t mtime;
+ size_t offset;
+ size_t len;
+ unsigned int pages;
+ unsigned int hdrsz;
+ unsigned int pgsz;
+ unsigned int paged;
+ uint32_t bitmap[]; /* FIXME: do not use flexible arrays */
+};
struct F_MAP *fmap(int fd, off_t offset, size_t len);
void fmunmap(struct F_MAP *m);
diff --git a/libclamav/matcher.c b/libclamav/matcher.c
index e4e83b2..5e14ca2 100644
--- a/libclamav/matcher.c
+++ b/libclamav/matcher.c
@@ -498,3 +498,156 @@ int cli_scandesc(int desc, cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struc
return (acmode & AC_SCAN_FT) ? type : CL_CLEAN;
}
+
+
+int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli_matched_type **ftoffset, unsigned int acmode)
+{
+ unsigned char *buff;
+ int ret = CL_CLEAN, type = CL_CLEAN, bytes;
+ unsigned int i, evalcnt;
+ uint32_t maxpatlen, offset = 0;
+ uint64_t evalids;
+ struct cli_ac_data gdata, tdata;
+ cli_md5_ctx md5ctx;
+ unsigned char digest[16];
+ struct cli_matcher *groot = NULL, *troot = NULL;
+ struct F_MAP *map = *ctx->fmap;
+
+ if(!ctx->engine) {
+ cli_errmsg("cli_scandesc: engine == NULL\n");
+ return CL_ENULLARG;
+ }
+
+ if(!ftonly)
+ groot = ctx->engine->root[0]; /* generic signatures */
+
+ if(ftype) {
+ for(i = 1; i < CLI_MTARGETS; i++) {
+ if(cli_mtargets[i].target == ftype) {
+ troot = ctx->engine->root[i];
+ break;
+ }
+ }
+ }
+
+ if(ftonly) {
+ if(!troot)
+ return CL_CLEAN;
+
+ maxpatlen = troot->maxpatlen;
+ } else {
+ if(troot)
+ maxpatlen = MAX(troot->maxpatlen, groot->maxpatlen);
+ else
+ maxpatlen = groot->maxpatlen;
+ }
+
+ if(!ftonly)
+ if((ret = cli_ac_initdata(&gdata, groot->ac_partsigs, groot->ac_lsigs, groot->ac_reloff_num, CLI_DEFAULT_AC_TRACKLEN)) || (ret = cli_ac_caloff(groot, &gdata, map->fd)))
+ return ret;
+
+ if(troot) {
+ if((ret = cli_ac_initdata(&tdata, troot->ac_partsigs, troot->ac_lsigs, troot->ac_reloff_num, CLI_DEFAULT_AC_TRACKLEN)) || (ret = cli_ac_caloff(troot, &tdata, map->fd))) {
+ if(!ftonly)
+ cli_ac_freedata(&gdata);
+ return ret;
+ }
+ }
+
+ if(!ftonly && ctx->engine->md5_hdb)
+ cli_md5_init(&md5ctx);
+
+ while(1) {
+ bytes = map->len - offset > SCANBUFF ? SCANBUFF : map->len - offset;
+ if(!(buff = fmap_need_off_once(map, offset, bytes))) {
+ /* FIXME: FAIL HERE */
+ }
+ if(ctx->scanned)
+ *ctx->scanned += bytes / CL_COUNT_PRECISION;
+
+ if(troot) {
+ if(troot->ac_only || (ret = cli_bm_scanbuff(buff, bytes, ctx->virname, troot, offset, map->fd)) != CL_VIRUS)
+ ret = cli_ac_scanbuff(buff, bytes, ctx->virname, NULL, NULL, troot, &tdata, offset, ftype, ftoffset, acmode, NULL);
+
+ if(ret == CL_VIRUS) {
+ if(!ftonly)
+ cli_ac_freedata(&gdata);
+ cli_ac_freedata(&tdata);
+
+ if(cli_checkfp(map->fd, ctx))
+ return CL_CLEAN;
+ else
+ return CL_VIRUS;
+ }
+ }
+
+ if(!ftonly) {
+ if(groot->ac_only || (ret = cli_bm_scanbuff(buff, bytes, ctx->virname, groot, offset, map->fd)) != CL_VIRUS)
+ ret = cli_ac_scanbuff(buff, bytes, ctx->virname, NULL, NULL, groot, &gdata, offset, ftype, ftoffset, acmode, NULL);
+
+ if(ret == CL_VIRUS) {
+ cli_ac_freedata(&gdata);
+ if(troot)
+ cli_ac_freedata(&tdata);
+ if(cli_checkfp(map->fd, ctx))
+ return CL_CLEAN;
+ else
+ return CL_VIRUS;
+
+ } else if((acmode & AC_SCAN_FT) && ret >= CL_TYPENO) {
+ if(ret > type)
+ type = ret;
+ }
+
+ if(ctx->engine->md5_hdb)
+ cli_md5_update(&md5ctx, buff + maxpatlen * (offset!=0), bytes);
+ }
+
+ if(bytes < SCANBUFF) break;
+ offset += SCANBUFF - maxpatlen;
+ }
+
+ if(troot) {
+ for(i = 0; i < troot->ac_lsigs; i++) {
+ evalcnt = 0;
+ evalids = 0;
+ if(cli_ac_chklsig(troot->ac_lsigtable[i]->logic, troot->ac_lsigtable[i]->logic + strlen(troot->ac_lsigtable[i]->logic), tdata.lsigcnt[i], &evalcnt, &evalids, 0) == 1) {
+ if(ctx->virname)
+ *ctx->virname = troot->ac_lsigtable[i]->virname;
+ ret = CL_VIRUS;
+ break;
+ }
+ }
+ cli_ac_freedata(&tdata);
+ }
+
+ if(groot) {
+ if(ret != CL_VIRUS) for(i = 0; i < groot->ac_lsigs; i++) {
+ evalcnt = 0;
+ evalids = 0;
+ if(cli_ac_chklsig(groot->ac_lsigtable[i]->logic, groot->ac_lsigtable[i]->logic + strlen(groot->ac_lsigtable[i]->logic), gdata.lsigcnt[i], &evalcnt, &evalids, 0) == 1) {
+ if(ctx->virname)
+ *ctx->virname = groot->ac_lsigtable[i]->virname;
+ ret = CL_VIRUS;
+ break;
+ }
+ }
+ cli_ac_freedata(&gdata);
+ }
+
+ if(ret == CL_VIRUS) {
+ lseek(map->fd, 0, SEEK_SET);
+ if(cli_checkfp(map->fd, ctx))
+ return CL_CLEAN;
+ else
+ return CL_VIRUS;
+ }
+
+ if(!ftonly && ctx->engine->md5_hdb) {
+ cli_md5_final(digest, &md5ctx);
+ if(cli_bm_scanbuff(digest, 16, ctx->virname, ctx->engine->md5_hdb, 0, -1) == CL_VIRUS && (cli_bm_scanbuff(digest, 16, NULL, ctx->engine->md5_fp, 0, -1) != CL_VIRUS))
+ return CL_VIRUS;
+ }
+
+ return (acmode & AC_SCAN_FT) ? type : CL_CLEAN;
+}
diff --git a/libclamav/matcher.h b/libclamav/matcher.h
index 6074263..1b94198 100644
--- a/libclamav/matcher.h
+++ b/libclamav/matcher.h
@@ -140,6 +140,7 @@ struct cli_target_info {
int cli_scanbuff(const unsigned char *buffer, uint32_t length, uint32_t offset, cli_ctx *ctx, cli_file_t ftype, struct cli_ac_data **acdata);
int cli_scandesc(int desc, cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli_matched_type **ftoffset, unsigned int acmode);
+int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli_matched_type **ftoffset, unsigned int acmode);
int cli_caloff(const char *offstr, struct cli_target_info *info, int fd, unsigned int target, uint32_t *offdata, uint32_t *offset_min, uint32_t *offset_max);
diff --git a/libclamav/scanners.c b/libclamav/scanners.c
index f997114..bcdba87 100644
--- a/libclamav/scanners.c
+++ b/libclamav/scanners.c
@@ -1894,7 +1894,7 @@ int cli_magic_scandesc(int desc, cli_ctx *ctx)
cli_dbgmsg("cli_magic_scandesc: Hit recursion limit, only scanning raw file\n");
else
cli_dbgmsg("Raw mode: No support for special files\n");
- if((ret = cli_scandesc(desc, ctx, 0, 0, NULL, AC_SCAN_VIR)) == CL_VIRUS)
+ if((ret = cli_fmap_scandesc(ctx, 0, 0, NULL, AC_SCAN_VIR)) == CL_VIRUS)
cli_dbgmsg("%s found in descriptor %d\n", *ctx->virname, desc);
fmunmap(*ctx->fmap);
ctx->fmap--;
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list