From af34d9815eff676af49f1ba76e19cb3964285f64 Mon Sep 17 00:00:00 2001 From: David Raynor Date: Wed, 11 Dec 2013 14:58:07 -0500 Subject: [PATCH] Put engine option checks in the right place for cache functions --- libclamav/cache.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/libclamav/cache.c b/libclamav/cache.c index 376273d48..1ad2b2655 100644 --- a/libclamav/cache.c +++ b/libclamav/cache.c @@ -743,16 +743,16 @@ int cli_cache_init(struct cl_engine *engine) { struct CACHE *cache; unsigned int i, j; - if (engine->engine_options & ENGINE_OPTIONS_DISABLE_CACHE) { - cli_dbgmsg("cli_cache_init: Caching disabled.\n"); - return 0; - } - if(!engine) { cli_errmsg("cli_cache_init: mpool malloc fail\n"); return 1; } + if (engine->engine_options & ENGINE_OPTIONS_DISABLE_CACHE) { + cli_dbgmsg("cli_cache_init: Caching disabled.\n"); + return 0; + } + if(!(cache = mpool_malloc(engine->mempool, sizeof(struct CACHE) * TREES))) { cli_errmsg("cli_cache_init: mpool malloc fail\n"); return 1; @@ -782,13 +782,13 @@ void cli_cache_destroy(struct cl_engine *engine) { struct CACHE *cache; unsigned int i; + if(!engine || !(cache = engine->cache)) + return; + if (engine->engine_options & ENGINE_OPTIONS_DISABLE_CACHE) { return; } - if(!engine || !(cache = engine->cache)) - return; - for(i=0; imempool); pthread_mutex_destroy(&cache[i].mutex); @@ -822,14 +822,14 @@ void cache_add(unsigned char *md5, size_t size, cli_ctx *ctx) { uint32_t level; struct CACHE *c; + if(!ctx || !ctx->engine || !ctx->engine->cache) + return; + if (ctx->engine->engine_options & ENGINE_OPTIONS_DISABLE_CACHE) { cli_dbgmsg("cache_add: Caching disabled. Not adding sample to cache.\n"); return; } - if(!ctx || !ctx->engine || !ctx->engine->cache) - return; - level = (*ctx->fmap && (*ctx->fmap)->dont_cache_flag) ? ctx->recursion : 0; if (ctx->found_possibly_unwanted && (level || !ctx->recursion)) return; @@ -865,14 +865,14 @@ void cache_remove(unsigned char *md5, size_t size, const struct cl_engine *engin unsigned int key = getkey(md5); struct CACHE *c; + if(!engine || !engine->cache) + return; + if (engine->engine_options & ENGINE_OPTIONS_DISABLE_CACHE) { cli_dbgmsg("cache_remove: Caching disabled.\n"); return; } - if(!engine || !engine->cache) - return; - /* cli_warnmsg("cache_remove: key is %u\n", key); */ c = &engine->cache[key]; @@ -905,14 +905,14 @@ int cache_check(unsigned char *hash, cli_ctx *ctx) { cli_md5_ctx md5; int ret; + if(!ctx || !ctx->engine || !ctx->engine->cache) + return CL_VIRUS; + if (ctx->engine->engine_options & ENGINE_OPTIONS_DISABLE_CACHE) { cli_dbgmsg("cache_check: Caching disabled. Returning CL_VIRUS.\n"); return CL_VIRUS; } - if(!ctx || !ctx->engine || !ctx->engine->cache) - return CL_VIRUS; - map = *ctx->fmap; todo = map->len;