From 116169833dfc7beec384de216f5c3ffccd8b0d60 Mon Sep 17 00:00:00 2001 From: Kevin Lin Date: Tue, 3 Mar 2015 17:47:55 -0500 Subject: [PATCH] generates fmap from desc if no map is NULL --- libclamav/scanners.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/libclamav/scanners.c b/libclamav/scanners.c index 2b709324a..3bdd11bab 100644 --- a/libclamav/scanners.c +++ b/libclamav/scanners.c @@ -3476,9 +3476,25 @@ static int scan_common(int desc, cl_fmap_t *map, const char **virname, unsigned rc = CL_EMEM; } else { - cli_bytecode_context_setctx(bc_ctx, &ctx); - rc = cli_bytecode_runhook(&ctx, ctx.engine, bc_ctx, BC_PRECLASS, map); - cli_bytecode_context_destroy(bc_ctx); + fmap_t *pc_map = map; + + if (!pc_map) { + perf_start(&ctx, PERFT_MAP); + if(!(pc_map = fmap(desc, 0, sb.st_size))) { + perf_stop(&ctx, PERFT_MAP); + rc = CL_EMEM; + } + perf_stop(&ctx, PERFT_MAP); + } + + if (pc_map) { + cli_bytecode_context_setctx(bc_ctx, &ctx); + rc = cli_bytecode_runhook(&ctx, ctx.engine, bc_ctx, BC_PRECLASS, pc_map); + cli_bytecode_context_destroy(bc_ctx); + + if (!map) + funmap(pc_map); + } } //ctx.options &= ~CL_SCAN_FILE_PROPERTIES; //rc = cli_mem_scandesc(jstring, strlen(jstring), &ctx);