git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@125 77e5149b-7576-45b1-b177-96237e5ba77b
Tomasz Kojm authored on 2003/11/25 01:19:39... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Mon Nov 24 17:18:03 CET 2003 (tk) |
|
2 |
+--------------------------------- |
|
3 |
+ * libclamav: cvd.c: small cleanups |
|
4 |
+ * included mbox testing tool (test/mbox/debugm.c) from Nigel |
|
5 |
+ |
|
1 | 6 |
Mon Nov 24 10:19:48 IST 2003 (njh) |
2 | 7 |
---------------------------------- |
3 | 8 |
* clamav-milter: Support AllowSupplementaryGroups |
... | ... |
@@ -152,23 +152,63 @@ struct cl_cvd *cl_cvdparse(const char *head) |
152 | 152 |
} |
153 | 153 |
|
154 | 154 |
cvd = (struct cl_cvd *) cli_calloc(1, sizeof(struct cl_cvd)); |
155 |
- cvd->time = cli_tok(head, 2, ':'); |
|
156 | 155 |
|
157 |
- pt = cli_tok(head, 3, ':'); |
|
156 |
+ if(!(cvd->time = cli_tok(head, 2, ':'))) { |
|
157 |
+ cli_errmsg("CVD -> Can't extract time from header.\n"); |
|
158 |
+ free(cvd); |
|
159 |
+ return NULL; |
|
160 |
+ } |
|
161 |
+ |
|
162 |
+ if(!(pt = cli_tok(head, 3, ':'))) { |
|
163 |
+ cli_errmsg("CVD -> Can't extract version from header.\n"); |
|
164 |
+ free(cvd->time); |
|
165 |
+ free(cvd); |
|
166 |
+ return NULL; |
|
167 |
+ } |
|
158 | 168 |
cvd->version = atoi(pt); |
159 | 169 |
free(pt); |
160 | 170 |
|
161 |
- pt = cli_tok(head, 4, ':'); |
|
171 |
+ if(!(pt = cli_tok(head, 4, ':'))) { |
|
172 |
+ cli_errmsg("CVD -> Can't extract signature number from header.\n"); |
|
173 |
+ free(cvd->time); |
|
174 |
+ free(cvd); |
|
175 |
+ return NULL; |
|
176 |
+ } |
|
162 | 177 |
cvd->sigs = atoi(pt); |
163 | 178 |
free(pt); |
164 | 179 |
|
165 |
- pt = cli_tok(head, 5, ':'); |
|
180 |
+ if(!(pt = cli_tok(head, 5, ':'))) { |
|
181 |
+ cli_errmsg("CVD -> Can't extract functionality level from header.\n"); |
|
182 |
+ free(cvd->time); |
|
183 |
+ free(cvd); |
|
184 |
+ return NULL; |
|
185 |
+ } |
|
166 | 186 |
cvd->fl = (short int) atoi(pt); |
167 | 187 |
free(pt); |
168 | 188 |
|
169 |
- cvd->md5 = cli_tok(head, 6, ':'); |
|
170 |
- cvd->dsig = cli_tok(head, 7, ':'); |
|
171 |
- cvd->builder = cli_tok(head, 8, ':'); |
|
189 |
+ if(!(cvd->md5 = cli_tok(head, 6, ':'))) { |
|
190 |
+ cli_errmsg("CVD -> Can't extract MD5 checksum from header.\n"); |
|
191 |
+ free(cvd->time); |
|
192 |
+ free(cvd); |
|
193 |
+ return NULL; |
|
194 |
+ } |
|
195 |
+ |
|
196 |
+ if(!(cvd->dsig = cli_tok(head, 7, ':'))) { |
|
197 |
+ cli_errmsg("CVD -> Can't extract digital signature from header.\n"); |
|
198 |
+ free(cvd->time); |
|
199 |
+ free(cvd->md5); |
|
200 |
+ free(cvd); |
|
201 |
+ return NULL; |
|
202 |
+ } |
|
203 |
+ |
|
204 |
+ if(!(cvd->builder = cli_tok(head, 8, ':'))) { |
|
205 |
+ cli_errmsg("CVD -> Can't extract builder name from header.\n"); |
|
206 |
+ free(cvd->time); |
|
207 |
+ free(cvd->md5); |
|
208 |
+ free(cvd->dsig); |
|
209 |
+ free(cvd); |
|
210 |
+ return NULL; |
|
211 |
+ } |
|
172 | 212 |
|
173 | 213 |
return cvd; |
174 | 214 |
} |
... | ... |
@@ -149,7 +149,11 @@ int cl_loaddb(const char *filename, struct cl_node **root, int *virnum) |
149 | 149 |
if(parts) /* there's always one part more */ |
150 | 150 |
parts++; |
151 | 151 |
for(i = 1; i <= parts; i++) { |
152 |
- pt2 = cli_tok(pt, i, '*'); |
|
152 |
+ if((pt2 = cli_tok(pt, i, '*')) == NULL) { |
|
153 |
+ cli_errmsg("Can't extract part %d of partial signature in line %d\n", i, line); |
|
154 |
+ return CL_EMALFDB; |
|
155 |
+ } |
|
156 |
+ |
|
153 | 157 |
if((ret = cli_parse_add(*root, start, pt2, sigid, parts, i))) { |
154 | 158 |
cli_dbgmsg("parse_add() return code: %d\n", ret); |
155 | 159 |
cli_errmsg("readdb(): Malformed pattern line %d (file %s).\n", line, filename); |
... | ... |
@@ -118,11 +118,14 @@ int cli_strbcasestr(const char *haystack, const char *needle) |
118 | 118 |
|
119 | 119 |
void cli_chomp(char *string) |
120 | 120 |
{ |
121 |
- if(string[strlen(string) - 1] == 10 || string[strlen(string) - 1 ] == 13) |
|
122 |
- string[strlen(string) -1] = 0; |
|
121 |
+ int l = strlen(string); |
|
123 | 122 |
|
124 |
- if(string[strlen(string) - 1] == '\r') |
|
125 |
- string[strlen(string) -1] = 0; |
|
123 |
+ if(string[l - 1] == 10 || string[l - 1] == 13) |
|
124 |
+ string[l - 1] = 0; |
|
125 |
+ |
|
126 |
+ l = strlen(string); |
|
127 |
+ if(string[l - 1] == '\r') |
|
128 |
+ string[l - 1] = 0; |
|
126 | 129 |
} |
127 | 130 |
|
128 | 131 |
char *cli_tok(const char *line, int field, char delimiter) |
... | ... |
@@ -131,7 +134,9 @@ char *cli_tok(const char *line, int field, char delimiter) |
131 | 131 |
char *buffer; |
132 | 132 |
|
133 | 133 |
|
134 |
- length = strlen(line); |
|
134 |
+ if(!(length = strlen(line))) |
|
135 |
+ return NULL; |
|
136 |
+ |
|
135 | 137 |
buffer = (char *) cli_calloc(length, sizeof(char)); |
136 | 138 |
|
137 | 139 |
for(i = 0; i < length; i++) { |
... | ... |
@@ -150,5 +155,10 @@ char *cli_tok(const char *line, int field, char delimiter) |
150 | 150 |
|
151 | 151 |
cli_chomp(buffer); /* preventive */ |
152 | 152 |
|
153 |
- return (char *) cli_realloc(buffer, strlen(buffer) + 1); |
|
153 |
+ if((length = strlen(buffer))) |
|
154 |
+ return (char *) cli_realloc(buffer, strlen(buffer) + 1); |
|
155 |
+ else { |
|
156 |
+ free(buffer); |
|
157 |
+ return NULL; |
|
158 |
+ } |
|
154 | 159 |
} |
676 | 676 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,55 @@ |
0 |
+/* |
|
1 |
+ * $CC $CFLAGS debugm.c -lclamav -lefence (or what ever memory debugger) |
|
2 |
+ * |
|
3 |
+ * njh@bandsman.co.uk |
|
4 |
+ */ |
|
5 |
+#include <stdio.h> |
|
6 |
+#include <errno.h> |
|
7 |
+#include <sys/stat.h> |
|
8 |
+#include <sys/types.h> |
|
9 |
+#include <fcntl.h> |
|
10 |
+#include <malloc.h> |
|
11 |
+#include <clamav.h> |
|
12 |
+#include <signal.h> |
|
13 |
+#include <sys/resource.h> |
|
14 |
+ |
|
15 |
+static void |
|
16 |
+cleanup() |
|
17 |
+{ |
|
18 |
+ exit(SIGINT); |
|
19 |
+} |
|
20 |
+ |
|
21 |
+int |
|
22 |
+main(int argc, char **argv) |
|
23 |
+{ |
|
24 |
+ struct rlimit rlim; |
|
25 |
+ |
|
26 |
+ if(argc == 1) { |
|
27 |
+ fprintf(stderr, "Usage: %s files...\n", argv[0]); |
|
28 |
+ return 1; |
|
29 |
+ } |
|
30 |
+ rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY; |
|
31 |
+ if(setrlimit(RLIMIT_CORE, &rlim) < 0) |
|
32 |
+ perror("setrlimit"); |
|
33 |
+ |
|
34 |
+ if(mkdir("/tmp/mboxtest", 0750) < 0) { |
|
35 |
+ perror("/tmp/mboxtest"); |
|
36 |
+ return errno; |
|
37 |
+ } |
|
38 |
+ signal(SIGINT, cleanup); |
|
39 |
+ while(*++argv) { |
|
40 |
+ int fd = open(*argv, 0); |
|
41 |
+ |
|
42 |
+ if(fd < 0) { |
|
43 |
+ perror(*argv); |
|
44 |
+ return errno; |
|
45 |
+ } |
|
46 |
+ printf("cl_mbox(%s) returns %d\n", |
|
47 |
+ *argv, cl_mbox("/tmp/mboxtest", fd)); |
|
48 |
+ close(fd); |
|
49 |
+ } |
|
50 |
+ puts("Finished - don't forget to rm -rf /tmp/mboxtest"); |
|
51 |
+ |
|
52 |
+ exit(0); |
|
53 |
+} |
|
54 |
+ |