Browse code

libclamav: report error instead of crashing when engine is not compiled (bb#1416)

git-svn: trunk@4882

Tomasz Kojm authored on 2009/03/03 01:36:23
Showing 4 changed files
... ...
@@ -1,3 +1,8 @@
1
+Mon Mar  2 17:37:50 CET 2009 (tk)
2
+---------------------------------
3
+ * libclamav: report error instead of crashing when engine is not compiled
4
+	      (bb#1416)
5
+
1 6
 Mon Mar  2 17:09:33 CET 2009 (tk)
2 7
 ---------------------------------
3 8
  * shared/optparser.c: fix handling of options which are enabled by default
... ...
@@ -72,10 +72,11 @@ typedef enum {
72 72
 #define CL_DB_PHISHING_URLS 0x8
73 73
 #define CL_DB_PUA	    0x10
74 74
 #define CL_DB_CVDNOTMP	    0x20
75
-#define CL_DB_OFFICIAL	    0x40
75
+#define CL_DB_OFFICIAL	    0x40    /* internal */
76 76
 #define CL_DB_PUA_MODE	    0x80
77 77
 #define CL_DB_PUA_INCLUDE   0x100
78 78
 #define CL_DB_PUA_EXCLUDE   0x200
79
+#define CL_DB_COMPILED	    0x400   /* internal */
79 80
 
80 81
 /* recommended db settings */
81 82
 #define CL_DB_STDOPT	    (CL_DB_PHISHING | CL_DB_PHISHING_URLS)
... ...
@@ -2044,6 +2044,7 @@ int cl_engine_compile(struct cl_engine *engine)
2044 2044
     cli_dconf_print(engine->dconf);
2045 2045
     mpool_flush(engine->mempool);
2046 2046
 
2047
+    engine->dboptions |= CL_DB_COMPILED;
2047 2048
     return CL_SUCCESS;
2048 2049
 }
2049 2050
 
... ...
@@ -1862,6 +1862,11 @@ int cli_magic_scandesc(int desc, cli_ctx *ctx)
1862 1862
 
1863 1863
     if(!ctx->engine) {
1864 1864
 	cli_errmsg("CRITICAL: engine == NULL\n");
1865
+	return CL_ENULLARG;
1866
+    }
1867
+
1868
+    if(!(ctx->engine->dboptions & CL_DB_COMPILED)) {
1869
+	cli_errmsg("CRITICAL: engine not compiled\n");
1865 1870
 	return CL_EMALFDB;
1866 1871
     }
1867 1872