Browse code

Limit exits on scanraw return codes bb#5252

David Raynor authored on 2012/06/27 01:23:44
Showing 1 changed files
... ...
@@ -2361,26 +2361,38 @@ static int magic_scandesc(int desc, cli_ctx *ctx, cli_file_t type)
2361 2361
     if(type != CL_TYPE_IGNORED && (type != CL_TYPE_HTML || !(DCONF_DOC & DOC_CONF_HTML_SKIPRAW)) && !ctx->engine->sdb) {
2362 2362
 	res = cli_scanraw(ctx, type, typercg, &dettype, hash);
2363 2363
 	if(res != CL_CLEAN) {
2364
-	    if(res == CL_VIRUS)
2365
-		ret =  cli_checkfp(hash, hashed_size, ctx);
2366
-	    else
2367
-		ret = res;
2368
-	    funmap(*ctx->fmap);
2369
-	    ctx->fmap--;
2370
-	    cli_bitset_free(ctx->hook_lsig_matches);
2371
-	    ctx->hook_lsig_matches = old_hook_lsig_matches;
2372
-	    /* Same switch as end of magic_scandesc function */
2373
-	    switch(ret) {
2374
-		case CL_EFORMAT:
2364
+	    switch(res) {
2365
+		/* Short list of scan halts, major runtime errors only! */
2366
+		case CL_EREAD:
2367
+		case CL_ESEEK:
2368
+		case CL_EMEM:
2369
+		    cli_dbgmsg("Descriptor[%d]: cli_scanraw error %s\n", desc, cl_strerror(res));
2370
+		    funmap(*ctx->fmap);
2371
+		    ctx->fmap--;
2372
+		    cli_bitset_free(ctx->hook_lsig_matches);
2373
+		    ctx->hook_lsig_matches = old_hook_lsig_matches;
2374
+		    ret_from_magicscan(res);
2375
+		/* CL_VIRUS = malware found, check FP and report */
2376
+		case CL_VIRUS:
2377
+		    ret = cli_checkfp(hash, hashed_size, ctx);
2378
+		    funmap(*ctx->fmap);
2379
+		    ctx->fmap--;
2380
+		    cli_bitset_free(ctx->hook_lsig_matches);
2381
+		    ctx->hook_lsig_matches = old_hook_lsig_matches;
2382
+		    ret_from_magicscan(ret);
2383
+		/* "MAX" conditions should still fully scan the current file */
2375 2384
 		case CL_EMAXREC:
2376 2385
 		case CL_EMAXSIZE:
2377 2386
 		case CL_EMAXFILES:
2378
-		    cli_dbgmsg("Descriptor[%d]: %s\n", desc, cl_strerror(ret));
2379
-		case CL_CLEAN: /* here, only from cli_checkfp() */
2380
-		    cache_add(hash, hashed_size, ctx);
2381
-		    ret_from_magicscan(CL_CLEAN);
2387
+		    ret = res;
2388
+		    cli_dbgmsg("Descriptor[%d]: Continuing after cli_scanraw reached %s\n",
2389
+			desc, cl_strerror(res));
2390
+		    break;
2391
+		/* Other errors should not prevent later attempts to scan */
2382 2392
 		default:
2383
-		    ret_from_magicscan(ret);
2393
+		    ret = res;
2394
+		    cli_dbgmsg("Descriptor[%d]: Continuing after cli_scanraw error %s\n",
2395
+			desc, cl_strerror(res));
2384 2396
 	    }
2385 2397
 	}
2386 2398
     }