git-svn: trunk@3903
Tomasz Kojm authored on 2008/07/03 20:19:21... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Thu Jul 3 12:47:38 CEST 2008 (tk) |
|
2 |
+---------------------------------- |
|
3 |
+ * libclamav: add ".UNOFFICIAL" suffix to 3rd party signatures (bb#1061) |
|
4 |
+ |
|
1 | 5 |
Wed Jul 2 13:24:25 CEST 2008 (tk) |
2 | 6 |
---------------------------------- |
3 | 7 |
* sigtool/sigtool.c: make use of the UNLINK command in cdiffs (bb#1080) |
... | ... |
@@ -545,7 +545,7 @@ int cli_cvdload(FILE *fs, struct cl_engine **engine, unsigned int *signo, short |
545 | 545 |
|
546 | 546 |
if(options & CL_DB_CVDNOTMP) { |
547 | 547 |
|
548 |
- return cli_tgzload(cfd, engine, signo, options); |
|
548 |
+ return cli_tgzload(cfd, engine, signo, options | CL_DB_OFFICIAL); |
|
549 | 549 |
|
550 | 550 |
} else { |
551 | 551 |
|
... | ... |
@@ -565,7 +565,7 @@ int cli_cvdload(FILE *fs, struct cl_engine **engine, unsigned int *signo, short |
565 | 565 |
} |
566 | 566 |
|
567 | 567 |
/* load extracted directory */ |
568 |
- ret = cl_load(dir, engine, signo, options); |
|
568 |
+ ret = cl_load(dir, engine, signo, options | CL_DB_OFFICIAL); |
|
569 | 569 |
|
570 | 570 |
cli_rmdirs(dir); |
571 | 571 |
free(dir); |
... | ... |
@@ -36,6 +36,7 @@ |
36 | 36 |
#include "filetypes.h" |
37 | 37 |
#include "cltypes.h" |
38 | 38 |
#include "str.h" |
39 |
+#include "readdb.h" |
|
39 | 40 |
|
40 | 41 |
uint8_t cli_ac_mindepth = AC_DEFAULT_MIN_DEPTH; |
41 | 42 |
uint8_t cli_ac_maxdepth = AC_DEFAULT_MAX_DEPTH; |
... | ... |
@@ -760,12 +761,12 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v |
760 | 760 |
} |
761 | 761 |
|
762 | 762 |
/* FIXME: clean up the code */ |
763 |
-int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hexsig, uint32_t sigid, uint16_t parts, uint16_t partno, uint16_t rtype, uint16_t type, uint32_t mindist, uint32_t maxdist, const char *offset, uint8_t target) |
|
763 |
+int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hexsig, uint32_t sigid, uint16_t parts, uint16_t partno, uint16_t rtype, uint16_t type, uint32_t mindist, uint32_t maxdist, const char *offset, uint8_t target, unsigned int options) |
|
764 | 764 |
{ |
765 | 765 |
struct cli_ac_patt *new; |
766 | 766 |
char *pt, *pt2, *hex = NULL, *hexcpy = NULL; |
767 | 767 |
uint16_t i, j, ppos = 0, pend, *dec; |
768 |
- uint8_t wprefix = 0, zprefix = 1, namelen, plen = 0; |
|
768 |
+ uint8_t wprefix = 0, zprefix = 1, plen = 0; |
|
769 | 769 |
struct cli_ac_alt *newalt, *altpt, **newtable; |
770 | 770 |
int ret, error = CL_SUCCESS; |
771 | 771 |
|
... | ... |
@@ -1059,27 +1060,13 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex |
1059 | 1059 |
if(new->length > root->maxpatlen) |
1060 | 1060 |
root->maxpatlen = new->length; |
1061 | 1061 |
|
1062 |
- if((pt = strstr(virname, " (Clam)"))) |
|
1063 |
- namelen = strlen(virname) - strlen(pt); |
|
1064 |
- else |
|
1065 |
- namelen = strlen(virname); |
|
1066 |
- |
|
1067 |
- if(!namelen) { |
|
1068 |
- cli_errmsg("cli_ac_addsig: No virus name\n"); |
|
1069 |
- new->prefix ? free(new->prefix) : free(new->pattern); |
|
1070 |
- ac_free_alt(new); |
|
1071 |
- free(new); |
|
1072 |
- return CL_EMALFDB; |
|
1073 |
- } |
|
1074 |
- |
|
1075 |
- if((new->virname = cli_calloc(namelen + 1, sizeof(char))) == NULL) { |
|
1062 |
+ new->virname = cli_virname((char *) virname, options & CL_DB_OFFICIAL, 0); |
|
1063 |
+ if(!new->virname) { |
|
1076 | 1064 |
new->prefix ? free(new->prefix) : free(new->pattern); |
1077 | 1065 |
ac_free_alt(new); |
1078 | 1066 |
free(new); |
1079 | 1067 |
return CL_EMEM; |
1080 | 1068 |
} |
1081 |
- strncpy(new->virname, virname, namelen); |
|
1082 |
- new->virname[namelen]='\0'; |
|
1083 | 1069 |
|
1084 | 1070 |
if(offset) { |
1085 | 1071 |
new->offset = cli_strdup(offset); |
... | ... |
@@ -78,7 +78,7 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v |
78 | 78 |
int cli_ac_buildtrie(struct cli_matcher *root); |
79 | 79 |
int cli_ac_init(struct cli_matcher *root, uint8_t mindepth, uint8_t maxdepth); |
80 | 80 |
void cli_ac_free(struct cli_matcher *root); |
81 |
-int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hexsig, uint32_t sigid, uint16_t parts, uint16_t partno, uint16_t rtype, uint16_t type, uint32_t mindist, uint32_t maxdist, const char *offset, uint8_t target); |
|
81 |
+int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hexsig, uint32_t sigid, uint16_t parts, uint16_t partno, uint16_t rtype, uint16_t type, uint32_t mindist, uint32_t maxdist, const char *offset, uint8_t target, unsigned int options); |
|
82 | 82 |
void cli_ac_setdepth(uint8_t mindepth, uint8_t maxdepth); |
83 | 83 |
|
84 | 84 |
#endif |
... | ... |
@@ -92,11 +92,62 @@ struct cli_ignored { |
92 | 92 |
int cl_loaddb(const char *filename, struct cl_engine **engine, unsigned int *signo); |
93 | 93 |
int cl_loaddbdir(const char *dirname, struct cl_engine **engine, unsigned int *signo); |
94 | 94 |
|
95 |
-int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hexsig, uint16_t rtype, uint16_t type, const char *offset, uint8_t target) |
|
95 |
+ |
|
96 |
+char *cli_virname(char *virname, unsigned int official, unsigned int allocated) |
|
97 |
+{ |
|
98 |
+ unsigned int len; |
|
99 |
+ char *newname, *pt; |
|
100 |
+ |
|
101 |
+ |
|
102 |
+ if(!virname) |
|
103 |
+ return NULL; |
|
104 |
+ |
|
105 |
+ if((pt = strstr(virname, " (Clam)"))) |
|
106 |
+ len = strlen(virname) - strlen(pt); |
|
107 |
+ else |
|
108 |
+ len = strlen(virname); |
|
109 |
+ |
|
110 |
+ if(!len) { |
|
111 |
+ cli_errmsg("cli_virname: Empty virus name\n"); |
|
112 |
+ return NULL; |
|
113 |
+ } |
|
114 |
+ |
|
115 |
+ if(!official) { |
|
116 |
+ newname = (char *) cli_malloc(len + 11 + 1); |
|
117 |
+ if(!newname) { |
|
118 |
+ cli_errmsg("cli_virname: Can't allocate memory for newname\n"); |
|
119 |
+ if(allocated) |
|
120 |
+ free(virname); |
|
121 |
+ return NULL; |
|
122 |
+ } |
|
123 |
+ strncpy(newname, virname, len); |
|
124 |
+ newname[len] = 0; |
|
125 |
+ strcat(newname, ".UNOFFICIAL"); |
|
126 |
+ newname[len + 11] = 0; |
|
127 |
+ if(allocated) |
|
128 |
+ free(virname); |
|
129 |
+ return newname; |
|
130 |
+ } |
|
131 |
+ |
|
132 |
+ if(!allocated) { |
|
133 |
+ newname = (char *) cli_malloc(len + 1); |
|
134 |
+ if(!newname) { |
|
135 |
+ cli_errmsg("cli_virname: Can't allocate memory for newname\n"); |
|
136 |
+ return NULL; |
|
137 |
+ } |
|
138 |
+ strncpy(newname, virname, len); |
|
139 |
+ newname[len] = 0; |
|
140 |
+ return newname; |
|
141 |
+ } |
|
142 |
+ |
|
143 |
+ return virname; |
|
144 |
+} |
|
145 |
+ |
|
146 |
+static int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hexsig, uint16_t rtype, uint16_t type, const char *offset, uint8_t target, unsigned int options) |
|
96 | 147 |
{ |
97 | 148 |
struct cli_bm_patt *bm_new; |
98 | 149 |
char *pt, *hexcpy, *start, *n; |
99 |
- int ret, virlen, asterisk = 0; |
|
150 |
+ int ret, asterisk = 0; |
|
100 | 151 |
unsigned int i, j, len, parts = 0; |
101 | 152 |
int mindist = 0, maxdist = 0, error = 0; |
102 | 153 |
|
... | ... |
@@ -135,7 +186,7 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex |
135 | 135 |
*pt++ = 0; |
136 | 136 |
} |
137 | 137 |
|
138 |
- if((ret = cli_ac_addsig(root, virname, start, root->ac_partsigs, parts, i, rtype, type, mindist, maxdist, offset, target))) { |
|
138 |
+ if((ret = cli_ac_addsig(root, virname, start, root->ac_partsigs, parts, i, rtype, type, mindist, maxdist, offset, target, options))) { |
|
139 | 139 |
cli_errmsg("cli_parse_add(): Problem adding signature (1).\n"); |
140 | 140 |
error = 1; |
141 | 141 |
break; |
... | ... |
@@ -215,7 +266,7 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex |
215 | 215 |
return CL_EMALFDB; |
216 | 216 |
} |
217 | 217 |
|
218 |
- if((ret = cli_ac_addsig(root, virname, pt, root->ac_partsigs, parts, i, rtype, type, 0, 0, offset, target))) { |
|
218 |
+ if((ret = cli_ac_addsig(root, virname, pt, root->ac_partsigs, parts, i, rtype, type, 0, 0, offset, target, options))) { |
|
219 | 219 |
cli_errmsg("cli_parse_add(): Problem adding signature (2).\n"); |
220 | 220 |
free(pt); |
221 | 221 |
return ret; |
... | ... |
@@ -225,7 +276,7 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex |
225 | 225 |
} |
226 | 226 |
|
227 | 227 |
} else if(root->ac_only || strpbrk(hexsig, "?(") || type) { |
228 |
- if((ret = cli_ac_addsig(root, virname, hexsig, 0, 0, 0, rtype, type, 0, 0, offset, target))) { |
|
228 |
+ if((ret = cli_ac_addsig(root, virname, hexsig, 0, 0, 0, rtype, type, 0, 0, offset, target, options))) { |
|
229 | 229 |
cli_errmsg("cli_parse_add(): Problem adding signature (3).\n"); |
230 | 230 |
return ret; |
231 | 231 |
} |
... | ... |
@@ -239,29 +290,15 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex |
239 | 239 |
free(bm_new); |
240 | 240 |
return CL_EMALFDB; |
241 | 241 |
} |
242 |
- |
|
243 | 242 |
bm_new->length = strlen(hexsig) / 2; |
244 | 243 |
|
245 |
- if((pt = strstr(virname, "(Clam)"))) |
|
246 |
- virlen = strlen(virname) - strlen(pt) - 1; |
|
247 |
- else |
|
248 |
- virlen = strlen(virname); |
|
249 |
- |
|
250 |
- if(virlen <= 0) { |
|
251 |
- free(bm_new->pattern); |
|
252 |
- free(bm_new); |
|
253 |
- return CL_EMALFDB; |
|
254 |
- } |
|
255 |
- |
|
256 |
- if((bm_new->virname = cli_calloc(virlen + 1, sizeof(char))) == NULL) { |
|
244 |
+ bm_new->virname = cli_virname((char *) virname, options & CL_DB_OFFICIAL, 0); |
|
245 |
+ if(!bm_new->virname) { |
|
257 | 246 |
free(bm_new->pattern); |
258 | 247 |
free(bm_new); |
259 | 248 |
return CL_EMEM; |
260 | 249 |
} |
261 | 250 |
|
262 |
- strncpy(bm_new->virname, virname, virlen); |
|
263 |
- bm_new->virname[virlen]='\0'; |
|
264 |
- |
|
265 | 251 |
if(offset) { |
266 | 252 |
bm_new->offset = cli_strdup(offset); |
267 | 253 |
if(!bm_new->offset) { |
... | ... |
@@ -453,7 +490,7 @@ static int cli_loaddb(FILE *fs, struct cl_engine **engine, unsigned int *signo, |
453 | 453 |
|
454 | 454 |
if(*pt == '=') continue; |
455 | 455 |
|
456 |
- if((ret = cli_parse_add(root, start, pt, 0, 0, NULL, 0))) { |
|
456 |
+ if((ret = cli_parse_add(root, start, pt, 0, 0, NULL, 0, options))) { |
|
457 | 457 |
ret = CL_EMALFDB; |
458 | 458 |
break; |
459 | 459 |
} |
... | ... |
@@ -632,7 +669,7 @@ static int cli_loadndb(FILE *fs, struct cl_engine **engine, unsigned int *signo, |
632 | 632 |
break; |
633 | 633 |
} |
634 | 634 |
|
635 |
- if((ret = cli_parse_add(root, virname, sig, 0, 0, offset, target))) { |
|
635 |
+ if((ret = cli_parse_add(root, virname, sig, 0, 0, offset, target, options))) { |
|
636 | 636 |
ret = CL_EMALFDB; |
637 | 637 |
break; |
638 | 638 |
} |
... | ... |
@@ -729,7 +766,7 @@ static int cli_loadftm(FILE *fs, struct cl_engine **engine, unsigned int options |
729 | 729 |
} |
730 | 730 |
|
731 | 731 |
if(atoi(tokens[0]) == 1) { /* A-C */ |
732 |
- if((ret = cli_parse_add((*engine)->root[0], tokens[3], tokens[2], rtype, type, strcmp(tokens[1], "*") ? tokens[1] : NULL, 0))) |
|
732 |
+ if((ret = cli_parse_add((*engine)->root[0], tokens[3], tokens[2], rtype, type, strcmp(tokens[1], "*") ? tokens[1] : NULL, 0, options))) |
|
733 | 733 |
break; |
734 | 734 |
|
735 | 735 |
} else if(atoi(tokens[0]) == 0) { /* memcmp() */ |
... | ... |
@@ -973,7 +1010,7 @@ static int cli_loadmd5(FILE *fs, struct cl_engine **engine, unsigned int *signo, |
973 | 973 |
} |
974 | 974 |
size = atoi(pt); |
975 | 975 |
|
976 |
- if(!(new->virname = cli_strdup(tokens[2]))) { |
|
976 |
+ if(!(new->virname = cli_virname((char *) tokens[2], options & CL_DB_OFFICIAL, 0))) { |
|
977 | 977 |
free(new->pattern); |
978 | 978 |
free(new); |
979 | 979 |
ret = CL_EMALFDB; |
... | ... |
@@ -1059,9 +1096,9 @@ static int cli_loadmd(FILE *fs, struct cl_engine **engine, unsigned int *signo, |
1059 | 1059 |
break; |
1060 | 1060 |
} |
1061 | 1061 |
|
1062 |
- if(!(new->virname = cli_strtok(buffer, 0, ":"))) { |
|
1062 |
+ if(!(new->virname = cli_virname(cli_strtok(buffer, 0, ":"), options & CL_DB_OFFICIAL, 1))) { |
|
1063 | 1063 |
free(new); |
1064 |
- ret = CL_EMALFDB; |
|
1064 |
+ ret = CL_EMEM; |
|
1065 | 1065 |
break; |
1066 | 1066 |
} |
1067 | 1067 |
|
... | ... |
@@ -51,7 +51,7 @@ |
51 | 51 |
cli_strbcasestr(ext, ".cld") \ |
52 | 52 |
) |
53 | 53 |
|
54 |
-int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hexsig, uint16_t rtype, uint16_t type, const char *offset, uint8_t target); |
|
54 |
+char *cli_virname(char *virname, unsigned int official, unsigned int allocated); |
|
55 | 55 |
|
56 | 56 |
int cli_initengine(struct cl_engine **engine, unsigned int options); |
57 | 57 |
|