Browse code

libclamav/readdb.c: return error if lsig contains redundant subsigs

Tomasz Kojm authored on 2009/11/03 23:19:43
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Tue Nov  3 15:18:14 CET 2009 )tk)
2
+---------------------------------
3
+ * libclamav/readdb.c: return error if lsig contains redundant subsigs
4
+
1 5
 Sun Nov  1 21:26:10 CET 2009 (acab)
2 6
 -----------------------------------
3 7
  * win32: improve build system
... ...
@@ -856,7 +856,7 @@ static int lsigattribs(char *attribs, struct cli_lsig_tdb *tdb)
856 856
 #define LDB_TOKENS 67
857 857
 static int cli_loadldb(FILE *fs, struct cl_engine *engine, unsigned int *signo, unsigned int options, struct cli_dbio *dbio, const char *dbname)
858 858
 {
859
-	char *tokens[LDB_TOKENS];
859
+	char *tokens[LDB_TOKENS + 1];
860 860
 	char buffer[CLI_DEFAULT_LSIG_BUFSIZE + 1], *buffer_cpy, *pt;
861 861
 	const char *sig, *virname, *offset, *logic;
862 862
 	struct cli_matcher *root;
... ...
@@ -882,7 +882,7 @@ static int cli_loadldb(FILE *fs, struct cl_engine *engine, unsigned int *signo,
882 882
 	if(engine->ignored)
883 883
 	    strcpy(buffer_cpy, buffer);
884 884
 
885
-	tokens_count = cli_strtokenize(buffer, ';', LDB_TOKENS, (const char **) tokens);
885
+	tokens_count = cli_strtokenize(buffer, ';', LDB_TOKENS + 1, (const char **) tokens);
886 886
 	if(tokens_count < 4) {
887 887
 	    ret = CL_EMALFDB;
888 888
 	    break;
... ...
@@ -911,6 +911,12 @@ static int cli_loadldb(FILE *fs, struct cl_engine *engine, unsigned int *signo,
911 911
 	    break;
912 912
 	}
913 913
 
914
+	if(subsigs != tokens_count - 3) {
915
+	    cli_errmsg("cli_loadldb: The number of subsignatures (== %u) doesn't match the IDs in the logical expression (== %u)\n", tokens_count - 3, subsigs);
916
+	    ret = CL_EMALFDB;
917
+	    break;
918
+	}
919
+
914 920
 	/* TDB */
915 921
 	memset(&tdb, 0, sizeof(tdb));
916 922
 #ifdef USE_MPOOL
... ...
@@ -984,11 +990,6 @@ static int cli_loadldb(FILE *fs, struct cl_engine *engine, unsigned int *signo,
984 984
 	root->ac_lsigtable = newtable;
985 985
 
986 986
 	for(i = 0; i < subsigs; i++) {
987
-	    if(i + 3 >= tokens_count) {
988
-		cli_errmsg("cli_loadldb: Missing subsignature id %u\n", i);
989
-		ret = CL_EMALFDB;
990
-		break;
991
-	    }
992 987
 	    lsigid[1] = i;
993 988
 	    sig = tokens[3 + i];
994 989