Browse code

mempool deuglification

git-svn: trunk@4333

aCaB authored on 2008/11/05 04:18:27
Showing 6 changed files
... ...
@@ -1,3 +1,7 @@
1
+Tue Nov  4 20:47:14 CET 2008 (acab)
2
+-----------------------------------
3
+ * libclamav: mempool de-uglify
4
+
1 5
 Tue Nov  4 20:15:55 CET 2008 (tk)
2 6
 ---------------------------------
3 7
  * libclamav, clamd: always return correct db version in VERSION (bb#1168)
... ...
@@ -1426,18 +1426,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1426 1426
     if(new->length > root->maxpatlen)
1427 1427
 	root->maxpatlen = new->length;
1428 1428
 
1429
-#ifdef USE_MPOOL
1430
-{
1431
-    char *mpoolvirname = cli_virname((char *) virname, options & CL_DB_OFFICIAL, 0);
1432
-    if(mpoolvirname) {
1433
-        if((new->virname = mp_malloc(root->mempool, strlen(mpoolvirname) + 1)) != NULL)
1434
-	    strcpy(new->virname, mpoolvirname);
1435
-	free(mpoolvirname);
1436
-    } else new->virname = NULL;
1437
-}
1438
-#else
1439
-    new->virname = cli_virname((char *) virname, options & CL_DB_OFFICIAL, 0);
1440
-#endif
1429
+    new->virname = cli_mp_virname(root->mempool, (char *) virname, options & CL_DB_OFFICIAL);
1441 1430
     if(!new->virname) {
1442 1431
 	mp_free(root->mempool, new->prefix ? new->prefix : new->pattern);
1443 1432
 	mp_ac_free_alt(root->mempool, new);
... ...
@@ -1449,12 +1438,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1449 1449
 	root->ac_lsigtable[new->lsigid[1]]->virname = new->virname;
1450 1450
 
1451 1451
     if(offset) {
1452
-#ifdef USE_MPOOL
1453
-        if((new->offset = mp_malloc(root->mempool, strlen(offset) + 1)))
1454
-	    strcpy(new->offset, offset);
1455
-#else
1456
-	new->offset = cli_strdup(offset);
1457
-#endif
1452
+	new->offset = cli_mp_strdup(root->mempool, offset);
1458 1453
 	if(!new->offset) {
1459 1454
 	    mp_free(root->mempool, new->prefix ? new->prefix : new->pattern);
1460 1455
 	    mp_ac_free_alt(root->mempool, new);
... ...
@@ -40,6 +40,7 @@
40 40
 
41 41
 #include "others.h"
42 42
 #include "str.h"
43
+#include "readdb.h"
43 44
 #ifndef CL_DEBUG
44 45
 #define NDEBUG
45 46
 #endif
... ...
@@ -328,7 +329,7 @@ struct FRAG {
328 328
 #define FRAG_OVERHEAD (offsetof(struct FRAG, fake))
329 329
 
330 330
 #define align_to_voidptr(size) (((size) / sizeof(void *) + ((size) % sizeof(void *) != 0)) * sizeof(void *))
331
-#define roundup(size) (FRAG_OVERHEAD + align_to_voidptr(size))
331
+#define mp_roundup(size) (FRAG_OVERHEAD + align_to_voidptr(size))
332 332
 
333 333
 static unsigned int align_to_pagesize(struct MP *mp, unsigned int size) {
334 334
   return (size / mp->psize + (size % mp->psize != 0)) * mp->psize;
... ...
@@ -399,7 +400,7 @@ void *mp_malloc(struct MP *mp, size_t size) {
399 399
 
400 400
   /* Case 1: We have a free'd frag */
401 401
   if((f = mp->avail[sbits])) {
402
-    spam("malloc %p size %u (freed)\n", f, roundup(size));
402
+    spam("malloc %p size %u (freed)\n", f, mp_roundup(size));
403 403
     mp->avail[sbits] = f->next;
404 404
 #ifdef CL_DEBUG
405 405
       f->magic = MPOOLMAGIC;
... ...
@@ -416,7 +417,7 @@ void *mp_malloc(struct MP *mp, size_t size) {
416 416
   while(mpm) {
417 417
     if(mpm->size - mpm->usize >= needed) {
418 418
       f = (struct FRAG *)((void *)mpm + mpm->usize);
419
-      spam("malloc %p size %u (hole)\n", f, roundup(size));
419
+      spam("malloc %p size %u (hole)\n", f, mp_roundup(size));
420 420
       mpm->usize += needed;
421 421
       f->sbits = sbits;
422 422
 #ifdef CL_DEBUG
... ...
@@ -443,7 +444,7 @@ void *mp_malloc(struct MP *mp, size_t size) {
443 443
   mpm->next = mp->mpm.next;
444 444
   mp->mpm.next = mpm;
445 445
   f = (struct FRAG *)((void *)mpm + align_to_voidptr(sizeof(*mpm)));
446
-  spam("malloc %p size %u (new map)\n", f, roundup(size));
446
+  spam("malloc %p size %u (new map)\n", f, mp_roundup(size));
447 447
   f->sbits = sbits;
448 448
 #ifdef CL_DEBUG
449 449
       f->magic = MPOOLMAGIC;
... ...
@@ -528,6 +529,50 @@ unsigned char *cli_mp_hex2str(mp_t *mp, const unsigned char *str)
528 528
 	return NULL;
529 529
 }
530 530
 
531
+char *cli_mp_strdup(mp_t *mp, const char *s) {
532
+  char *alloc;
533
+  unsigned int strsz;
534
+
535
+  if(s == NULL) {
536
+    cli_errmsg("cli_mp_strdup(): s == NULL. Please report to http://bugs.clamav.net\n");
537
+    return NULL;
538
+  }
539
+
540
+  strsz = strlen(s) + 1;
541
+  alloc = mp_malloc(mp, strsz);
542
+  if(!alloc)
543
+    cli_errmsg("cli_mp_strdup(): Can't allocate memory (%u bytes).\n", (unsigned int) strsz);
544
+  else
545
+    memcpy(alloc, s, strsz);
546
+  return alloc;
547
+}
548
+
549
+char *cli_mp_virname(mp_t *mp, char *virname, unsigned int official) {
550
+  char *newname, *pt;
551
+  if(!virname)
552
+    return NULL;
553
+
554
+  if((pt = strstr(virname, " (Clam)")))
555
+    *pt='\0';
556
+
557
+  if(!virname[0]) {
558
+    cli_errmsg("cli_virname: Empty virus name\n");
559
+    return NULL;
560
+  }
561
+
562
+  if(official)
563
+    return cli_mp_strdup(mp, virname);
564
+
565
+  newname = (char *)mp_malloc(mp, strlen(virname) + 11 + 1);
566
+  if(!newname) {
567
+    cli_errmsg("cli_virname: Can't allocate memory for newname\n");
568
+    return NULL;
569
+  }
570
+  sprintf(newname, "%s.UNOFFICIAL", virname);
571
+  return newname;
572
+}
573
+
574
+
531 575
 #ifdef DEBUGMPOOL
532 576
 void mp_stats(struct MP *mp) {
533 577
   unsigned int i=0, ta=0, tu=0;
... ...
@@ -33,6 +33,8 @@ void *mp_calloc(mp_t *mp, size_t nmemb, size_t size);
33 33
 void *mp_realloc(mp_t *mp, void *ptr, size_t size);
34 34
 void *mp_realloc2(mp_t *mp, void *ptr, size_t size);
35 35
 unsigned char *cli_mp_hex2str(mp_t* mp, const unsigned char *src);
36
+char *cli_mp_strdup(mp_t *mp, const char *s);
37
+char *cli_mp_virname(mp_t *mp, char *virname, unsigned int official);
36 38
 #else /* USE_MPOOL */
37 39
 
38 40
 #define mp_malloc(a, b) cli_malloc(b)
... ...
@@ -41,7 +43,8 @@ unsigned char *cli_mp_hex2str(mp_t* mp, const unsigned char *src);
41 41
 #define mp_realloc(a, b, c) cli_realloc(b, c)
42 42
 #define mp_realloc2(a, b, c) cli_realloc2(b, c)
43 43
 #define cli_mp_hex2str(mp, src) cli_hex2str(src)
44
-
44
+#define cli_mp_strdup(mp, s) cli_strdup(s)
45
+#define cli_mp_virname(mp, a, b) cli_virname(a, b)
45 46
 #endif /* USE_MPOOL */
46 47
 
47 48
 #endif
... ...
@@ -92,9 +92,8 @@ int cl_loaddb(const char *filename, struct cl_engine **engine, unsigned int *sig
92 92
 int cl_loaddbdir(const char *dirname, struct cl_engine **engine, unsigned int *signo);
93 93
 
94 94
 
95
-char *cli_virname(char *virname, unsigned int official, unsigned int allocated)
95
+char *cli_virname(char *virname, unsigned int official)
96 96
 {
97
-	unsigned int len;
98 97
 	char *newname, *pt;
99 98
 
100 99
 
... ...
@@ -102,44 +101,23 @@ char *cli_virname(char *virname, unsigned int official, unsigned int allocated)
102 102
 	return NULL;
103 103
 
104 104
     if((pt = strstr(virname, " (Clam)")))
105
-	len = strlen(virname) - strlen(pt);
106
-    else
107
-	len = strlen(virname);
105
+	*pt='\0';
108 106
 
109
-    if(!len) {
107
+    if(!virname[0]) {
110 108
 	cli_errmsg("cli_virname: Empty virus name\n");
111 109
 	return NULL;
112 110
     }
113 111
 
114
-    if(!official) {
115
-	newname = (char *) cli_malloc(len + 11 + 1);
116
-	if(!newname) {
117
-	    cli_errmsg("cli_virname: Can't allocate memory for newname\n");
118
-	    if(allocated)
119
-		free(virname);
120
-	    return NULL;
121
-	}
122
-	strncpy(newname, virname, len);
123
-	newname[len] = 0;
124
-	strcat(newname, ".UNOFFICIAL");
125
-	newname[len + 11] = 0;
126
-	if(allocated)
127
-	    free(virname);
128
-	return newname;
129
-    }
112
+    if(official)
113
+        return cli_strdup(virname);
130 114
 
131
-    if(!allocated) {
132
-	newname = (char *) cli_malloc(len + 1);
133
-	if(!newname) {
134
-	    cli_errmsg("cli_virname: Can't allocate memory for newname\n");
135
-	    return NULL;
136
-	}
137
-	strncpy(newname, virname, len);
138
-	newname[len] = 0;
139
-	return newname;
115
+    newname = (char *) cli_malloc(strlen(virname) + 11 + 1);
116
+    if(!newname) {
117
+      cli_errmsg("cli_virname: Can't allocate memory for newname\n");
118
+      return NULL;
140 119
     }
141
-
142
-    return virname;
120
+    sprintf(newname, "%s.UNOFFICIAL", virname);
121
+    return newname;
143 122
 }
144 123
 
145 124
 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, const uint32_t *lsigid, unsigned int options)
... ...
@@ -284,38 +262,14 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex
284 284
 	bm_new = (struct cli_bm_patt *) mp_calloc(root->mempool, 1, sizeof(struct cli_bm_patt));
285 285
 	if(!bm_new)
286 286
 	    return CL_EMEM;
287
-
288
-#ifdef USE_MPOOL
289
-{
290
-    unsigned char *mpoolhexsig = (unsigned char *) cli_hex2str(hexsig);
291
-    if(mpoolhexsig) {
292
-        unsigned int mpoolhexsigsz = strlen(hexsig) / 2 + 1;
293
-	if((bm_new->pattern = mp_malloc(root->mempool, mpoolhexsigsz)))
294
-	    memcpy(bm_new->pattern, mpoolhexsig, mpoolhexsigsz);
295
-	free(mpoolhexsig);
296
-    } else bm_new->pattern = NULL;
297
-}
298
-#else
299
-        bm_new->pattern = (unsigned char *) cli_hex2str(hexsig);
300
-#endif
287
+        bm_new->pattern = (unsigned char *) cli_mp_hex2str(root->mempool, hexsig);
301 288
 	if(!bm_new->pattern) {
302 289
 	    mp_free(root->mempool, bm_new);
303 290
 	    return CL_EMALFDB;
304 291
 	}
305 292
 	bm_new->length = strlen(hexsig) / 2;
306 293
 
307
-#ifdef USE_MPOOL
308
-{
309
-    char *mpoolvirname = cli_virname((char *) virname, options & CL_DB_OFFICIAL, 0);
310
-    if(mpoolvirname) {
311
-	if((bm_new->virname = mp_malloc(root->mempool, strlen(mpoolvirname) + 1)))
312
-	    strcpy(bm_new->virname, mpoolvirname);
313
-	free(mpoolvirname);
314
-    } else bm_new->virname = NULL;
315
-}
316
-#else
317
-	bm_new->virname = cli_virname((char *) virname, options & CL_DB_OFFICIAL, 0);
318
-#endif
294
+	bm_new->virname = cli_mp_virname(root->mempool, (char *) virname, options & CL_DB_OFFICIAL);
319 295
 	if(!bm_new->virname) {
320 296
 	    mp_free(root->mempool, bm_new->pattern);
321 297
 	    mp_free(root->mempool, bm_new);
... ...
@@ -323,12 +277,7 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex
323 323
 	}
324 324
 
325 325
 	if(offset) {
326
-#ifdef USE_MPOOL
327
-	    if((bm_new->offset = mp_malloc(root->mempool, strlen(offset) + 1)))
328
-	        strcpy(bm_new->offset, offset);
329
-#else
330
-	    bm_new->offset = cli_strdup(offset);
331
-#endif
326
+	    bm_new->offset = cli_mp_strdup(root->mempool, offset);
332 327
 	    if(!bm_new->offset) {
333 328
 	        mp_free(root->mempool, bm_new->pattern);
334 329
 		mp_free(root->mempool, bm_new->virname);
... ...
@@ -1014,12 +963,8 @@ static int cli_loadldb(FILE *fs, struct cl_engine **engine, unsigned int *signo,
1014 1014
 	    ret = CL_EMEM;
1015 1015
 	    break;
1016 1016
 	}
1017
-#ifdef USE_MPOOL
1018
-	if((lsig->logic = mp_malloc((*engine)->mempool, strlen(logic)+1)))
1019
-	    strcpy(lsig->logic, logic);
1020
-#else
1021
-	lsig->logic = cli_strdup(logic);
1022
-#endif
1017
+
1018
+	lsig->logic = cli_mp_strdup((*engine)->mempool, logic);
1023 1019
 	if(!lsig->logic) {
1024 1020
 	    cli_errmsg("cli_loadldb: Can't allocate memory for lsig->logic\n");
1025 1021
 	    FREE_TDB(tdb);
... ...
@@ -1164,19 +1109,7 @@ static int cli_loadftm(FILE *fs, struct cl_engine **engine, unsigned int options
1164 1164
 	    }
1165 1165
 	    new->type = type;
1166 1166
 	    new->offset = atoi(tokens[1]);
1167
-#ifdef USE_MPOOL
1168
-{
1169
-    unsigned char *mpoolmagic = cli_hex2str(tokens[2]);
1170
-    if(mpoolmagic) {
1171
-	unsigned int mpoolmagicsz = strlen(tokens[2]) / 2 + 1;
1172
-        if((new->magic = mp_malloc((*engine)->mempool, mpoolmagicsz)))
1173
-	    memcpy(new->magic, mpoolmagic, mpoolmagicsz);
1174
-	free(mpoolmagic);
1175
-    } else new->magic = NULL;
1176
-}
1177
-#else
1178
-	    new->magic = (unsigned char *) cli_hex2str(tokens[2]);
1179
-#endif
1167
+	    new->magic = (unsigned char *) cli_mp_hex2str((*engine)->mempool, tokens[2]);
1180 1168
 	    if(!new->magic) {
1181 1169
 		cli_errmsg("cli_loadftm: Can't decode the hex string\n");
1182 1170
 		ret = CL_EMALFDB;
... ...
@@ -1184,12 +1117,7 @@ static int cli_loadftm(FILE *fs, struct cl_engine **engine, unsigned int options
1184 1184
 		break;
1185 1185
 	    }
1186 1186
 	    new->length = strlen(tokens[2]) / 2;
1187
-#ifdef USE_MPOOL
1188
-	   if((new->tname = mp_malloc((*engine)->mempool, strlen(tokens[3])+1)))
1189
-		strcpy(new->tname, tokens[3]);
1190
-#else
1191
-	    new->tname = cli_strdup(tokens[3]);
1192
-#endif
1187
+	    new->tname = cli_mp_strdup((*engine)->mempool, tokens[3]);
1193 1188
 	    if(!new->tname) {
1194 1189
 		mp_free((*engine)->mempool, new->magic);
1195 1190
 		mp_free((*engine)->mempool, new);
... ...
@@ -1222,8 +1150,10 @@ static int cli_loadftm(FILE *fs, struct cl_engine **engine, unsigned int options
1222 1222
     return CL_SUCCESS;
1223 1223
 }
1224 1224
 
1225
+#define IGN_TOKENS 3
1225 1226
 static int cli_loadign(FILE *fs, struct cl_engine **engine, unsigned int options, struct cli_dbio *dbio)
1226 1227
 {
1228
+	const char *tokens[IGN_TOKENS];
1227 1229
 	char buffer[FILEBUFF], *pt;
1228 1230
 	unsigned int line = 0;
1229 1231
 	struct cli_ignsig *new;
... ...
@@ -1242,55 +1172,28 @@ static int cli_loadign(FILE *fs, struct cl_engine **engine, unsigned int options
1242 1242
     while(cli_dbgets(buffer, FILEBUFF, fs, dbio)) {
1243 1243
 	line++;
1244 1244
 	cli_chomp(buffer);
1245
+	cli_strtokenize(buffer, ':', IGN_TOKENS, tokens);
1246
+
1245 1247
 	new = (struct cli_ignsig *) mp_calloc((*engine)->mempool, 1, sizeof(struct cli_ignsig));
1246 1248
 	if(!new) {
1247 1249
 	    ret = CL_EMEM;
1248 1250
 	    break;
1249 1251
 	}
1250 1252
 
1251
-#ifdef USE_MPOOL
1252
-{
1253
-    unsigned char *mpooldbname = cli_strtok(buffer, 0, ":");
1254
-    if(mpooldbname) {
1255
-        if((new->dbname = mp_malloc((*engine)->mempool, strlen(mpooldbname) + 1)))
1256
-	    strcpy(new->dbname, mpooldbname);
1257
-	free(mpooldbname);
1258
-    } else new->dbname = NULL;
1259
-}
1260
-#else
1261
-	new->dbname = cli_strtok(buffer, 0, ":");
1262
-#endif
1253
+	new->dbname = cli_mp_strdup((*engine)->mempool, tokens[0]);
1254
+
1263 1255
 	if(!new->dbname) {
1264 1256
 	    mp_free((*engine)->mempool, new);
1265 1257
 	    ret = CL_EMALFDB;
1266 1258
 	    break;
1267 1259
 	}
1268 1260
 
1269
-	if(!(pt = cli_strtok(buffer, 1, ":"))) {
1270
-	    mp_free((*engine)->mempool, new->dbname);
1271
-	    mp_free((*engine)->mempool, new);
1272
-	    ret = CL_EMALFDB;
1273
-	    break;
1274
-	} else {
1275
-	    new->line = atoi(pt);
1276
-	    free(pt);
1277
-	}
1261
+	new->line = atoi(tokens[1]);
1278 1262
 
1279 1263
 	if((ret = hashset_addkey(&ignored->hs, new->line)))
1280 1264
 	    break;
1281 1265
 
1282
-#ifdef USE_MPOOL
1283
-{
1284
-    unsigned char *mpoolsigname = cli_strtok(buffer, 2, ":");
1285
-    if(mpoolsigname) {
1286
-        if((new->signame = mp_malloc((*engine)->mempool, strlen(mpoolsigname) + 1)))
1287
-	    strcpy(new->signame, mpoolsigname);
1288
-	free(mpoolsigname);
1289
-    } else new->signame = NULL;
1290
-}
1291
-#else
1292
-	new->signame = cli_strtok(buffer, 2, ":");
1293
-#endif
1266
+	new->signame = cli_mp_strdup((*engine)->mempool, tokens[2]);
1294 1267
 	if(!new->signame) {
1295 1268
 	    mp_free((*engine)->mempool, new->dbname);
1296 1269
 	    mp_free((*engine)->mempool, new);
... ...
@@ -1421,29 +1324,12 @@ static int cli_loadmd5(FILE *fs, struct cl_engine **engine, unsigned int *signo,
1421 1421
 	    break;
1422 1422
 	}
1423 1423
 
1424
-#ifdef USE_MPOOL
1425
-	if(strlen(pt) == 32) {
1426
-	    unsigned char *mpoolhex = (unsigned char *) cli_hex2str(pt);
1427
-	    if(mpoolhex) {
1428
-	        if((new->pattern = mp_malloc((*engine)->mempool, 17)))
1429
-		    memcpy(new->pattern, mpoolhex, 17);
1430
-		free(mpoolhex);
1431
-	    } else new->pattern = NULL;
1432
-	} else new->pattern = NULL;
1433
-	if(new->pattern == NULL) {
1424
+	if(strlen(pt) != 32 || !(new->pattern = (unsigned char *) cli_mp_hex2str((*engine)->mempool, pt))) {
1434 1425
 	    cli_errmsg("cli_loadmd5: Malformed MD5 string at line %u\n", line);
1435 1426
 	    mp_free((*engine)->mempool, new);
1436 1427
 	    ret = CL_EMALFDB;
1437 1428
 	    break;
1438 1429
 	}
1439
-#else
1440
-	if(strlen(pt) != 32 || !(new->pattern = (unsigned char *) cli_hex2str(pt))) {
1441
-	    cli_errmsg("cli_loadmd5: Malformed MD5 string at line %u\n", line);
1442
-	    free(new);
1443
-	    ret = CL_EMALFDB;
1444
-	    break;
1445
-	}
1446
-#endif
1447 1430
 	new->length = 16;
1448 1431
 
1449 1432
 	if(!(pt = tokens[size_field])) {
... ...
@@ -1454,18 +1340,7 @@ static int cli_loadmd5(FILE *fs, struct cl_engine **engine, unsigned int *signo,
1454 1454
 	}
1455 1455
 	size = atoi(pt);
1456 1456
 
1457
-#ifdef USE_MPOOL
1458
-	{
1459
-	  char *mpoolvname = cli_virname((char *) tokens[2], options & CL_DB_OFFICIAL, 0);
1460
-	  if(mpoolvname) {
1461
-	    if((new->virname = mp_malloc((*engine)->mempool, strlen(mpoolvname) + 1)))
1462
-	      strcpy(new->virname, mpoolvname);
1463
-	    free(mpoolvname);
1464
-	  } else new->virname = NULL;
1465
-	}
1466
-#else
1467
-	new->virname = cli_virname((char *) tokens[2], options & CL_DB_OFFICIAL, 0);
1468
-#endif
1457
+	new->virname = cli_mp_virname((*engine)->mempool, (char *) tokens[2], options & CL_DB_OFFICIAL);
1469 1458
 	if(!new->virname) {
1470 1459
 	    mp_free((*engine)->mempool, new->pattern);
1471 1460
 	    mp_free((*engine)->mempool, new);
... ...
@@ -1519,8 +1394,10 @@ static int cli_loadmd5(FILE *fs, struct cl_engine **engine, unsigned int *signo,
1519 1519
     return CL_SUCCESS;
1520 1520
 }
1521 1521
 
1522
+#define MD_TOKENS 9
1522 1523
 static int cli_loadmd(FILE *fs, struct cl_engine **engine, unsigned int *signo, int type, unsigned int options, struct cli_dbio *dbio, const char *dbname)
1523 1524
 {
1525
+	const char *tokens[MD_TOKENS];
1524 1526
 	char buffer[FILEBUFF], *pt;
1525 1527
 	unsigned int line = 0, sigs = 0;
1526 1528
 	int ret = CL_SUCCESS, crc;
... ...
@@ -1533,6 +1410,7 @@ static int cli_loadmd(FILE *fs, struct cl_engine **engine, unsigned int *signo,
1533 1533
 	    continue;
1534 1534
 
1535 1535
 	cli_chomp(buffer);
1536
+	cli_strtokenize(buffer, ':', MD_TOKENS, tokens);
1536 1537
 
1537 1538
 	new = (struct cli_meta_node *) mp_calloc((*engine)->mempool, 1, sizeof(struct cli_meta_node));
1538 1539
 	if(!new) {
... ...
@@ -1540,20 +1418,9 @@ static int cli_loadmd(FILE *fs, struct cl_engine **engine, unsigned int *signo,
1540 1540
 	    break;
1541 1541
 	}
1542 1542
 
1543
-#ifdef USE_MPOOL
1544
-	{
1545
-	  char *mpoolvname = cli_virname(cli_strtok(buffer, 0, ":"), options & CL_DB_OFFICIAL, 1);
1546
-	  if(mpoolvname) {
1547
-	      if((new->virname = mp_malloc((*engine)->mempool, strlen(mpoolvname) + 1)))
1548
-		  strcpy(new->virname, mpoolvname);
1549
-	      free(mpoolvname);
1550
-	  } else new->virname = NULL;
1551
-	}
1552
-#else
1553
-	new->virname = cli_virname(cli_strtok(buffer, 0, ":"), options & CL_DB_OFFICIAL, 1);
1554
-#endif
1543
+	new->virname = cli_mp_virname((*engine)->mempool, (char *)tokens[0], options & CL_DB_OFFICIAL);
1555 1544
 	if(!new->virname) {
1556
-	  mp_free((*engine)->mempool, new);
1545
+	    mp_free((*engine)->mempool, new);
1557 1546
 	    ret = CL_EMEM;
1558 1547
 	    break;
1559 1548
 	}
... ...
@@ -1564,28 +1431,8 @@ static int cli_loadmd(FILE *fs, struct cl_engine **engine, unsigned int *signo,
1564 1564
 	    continue;
1565 1565
 	}
1566 1566
 
1567
-	if(!(pt = cli_strtok(buffer, 1, ":"))) {
1568
-	    mp_free((*engine)->mempool, new->virname);
1569
-	    mp_free((*engine)->mempool, new);
1570
-	    ret = CL_EMALFDB;
1571
-	    break;
1572
-	} else {
1573
-	    new->encrypted = atoi(pt);
1574
-	    free(pt);
1575
-	}
1576
-
1577
-#ifdef USE_MPOOL
1578
-	{
1579
-	  char *mpoolfname = cli_strtok(buffer, 2, ":");
1580
-	  if(mpoolfname) {
1581
-	      if((new->filename = mp_malloc((*engine)->mempool, strlen(mpoolfname) + 1)))
1582
-		  strcpy(new->filename, mpoolfname);
1583
-	      free(mpoolfname);
1584
-	  } else new->filename = NULL;
1585
-	}
1586
-#else
1587
-	new->filename = cli_strtok(buffer, 2, ":");
1588
-#endif
1567
+	new->encrypted = atoi(tokens[1]);
1568
+	new->filename = cli_mp_strdup((*engine)->mempool, tokens[2]);
1589 1569
 	if(!new->filename) {
1590 1570
 	    mp_free((*engine)->mempool, new->virname);
1591 1571
 	    mp_free((*engine)->mempool, new);
... ...
@@ -1598,95 +1445,41 @@ static int cli_loadmd(FILE *fs, struct cl_engine **engine, unsigned int *signo,
1598 1598
 	    }
1599 1599
 	}
1600 1600
 
1601
-	if(!(pt = cli_strtok(buffer, 3, ":"))) {
1602
-	    if(new->filename) mp_free((*engine)->mempool, new->filename);
1603
-	    mp_free((*engine)->mempool, new->virname);
1604
-	    mp_free((*engine)->mempool, new);
1605
-	    ret = CL_EMALFDB;
1606
-	    break;
1607
-	} else {
1608
-	    if(!strcmp(pt, "*"))
1609
-		new->size = -1;
1610
-	    else
1611
-		new->size = atoi(pt);
1612
-	    free(pt);
1613
-	}
1601
+	if(!strcmp(tokens[3], "*"))
1602
+	    new->size = -1;
1603
+	else
1604
+	    new->size = atoi(tokens[3]);
1614 1605
 
1615
-	if(!(pt = cli_strtok(buffer, 4, ":"))) {
1616
-	    if(new->filename) mp_free((*engine)->mempool, new->filename);
1617
-	    mp_free((*engine)->mempool, new->virname);
1618
-	    mp_free((*engine)->mempool, new);
1619
-	    ret = CL_EMALFDB;
1620
-	    break;
1621
-	} else {
1622
-	    if(!strcmp(pt, "*"))
1623
-		new->csize = -1;
1624
-	    else
1625
-		new->csize = atoi(pt);
1626
-	    free(pt);
1627
-	}
1606
+	if(!strcmp(tokens[4], "*"))
1607
+	    new->csize = -1;
1608
+	else
1609
+	    new->csize = atoi(tokens[4]);
1628 1610
 
1629
-	if(!(pt = cli_strtok(buffer, 5, ":"))) {
1630
-	    if(new->filename) mp_free((*engine)->mempool, new->filename);
1631
-	    mp_free((*engine)->mempool, new->virname);
1632
-	    mp_free((*engine)->mempool, new);
1633
-	    ret = CL_EMALFDB;
1634
-	    break;
1611
+	if(!strcmp(tokens[5], "*")) {
1612
+	    new->crc32 = 0;
1635 1613
 	} else {
1636
-	    if(!strcmp(pt, "*")) {
1637
-		new->crc32 = 0;
1638
-	    } else {
1639
-		crc = cli_hex2num(pt);
1640
-		if(crc == -1) {
1641
-		    ret = CL_EMALFDB;
1642
-		    break;
1643
-		}
1644
-		new->crc32 = (unsigned int) crc;
1614
+	    crc = cli_hex2num(tokens[5]);
1615
+	    if(crc == -1) {
1616
+	        ret = CL_EMALFDB;
1617
+		break;
1645 1618
 	    }
1646
-	    free(pt);
1619
+	    new->crc32 = (unsigned int) crc;
1647 1620
 	}
1648 1621
 
1649
-	if(!(pt = cli_strtok(buffer, 6, ":"))) {
1650
-	    if(new->filename) mp_free((*engine)->mempool, new->filename);
1651
-	    mp_free((*engine)->mempool, new->virname);
1652
-	    mp_free((*engine)->mempool, new);
1653
-	    ret = CL_EMALFDB;
1654
-	    break;
1655
-	} else {
1656
-	    if(!strcmp(pt, "*"))
1657
-		new->method = -1;
1658
-	    else
1659
-		new->method = atoi(pt);
1660
-	    free(pt);
1661
-	}
1622
+	if(!strcmp(tokens[6], "*"))
1623
+	    new->method = -1;
1624
+	else
1625
+	    new->method = atoi(tokens[6]);
1662 1626
 
1663
-	if(!(pt = cli_strtok(buffer, 7, ":"))) {
1664
-	    if(new->filename) mp_free((*engine)->mempool, new->filename);
1665
-	    mp_free((*engine)->mempool, new->virname);
1666
-	    mp_free((*engine)->mempool, new);
1667
-	    ret = CL_EMALFDB;
1668
-	    break;
1669
-	} else {
1670
-	    if(!strcmp(pt, "*"))
1671
-		new->fileno = 0;
1672
-	    else
1673
-		new->fileno = atoi(pt);
1674
-	    free(pt);
1675
-	}
1627
+	if(!strcmp(tokens[7], "*"))
1628
+	    new->fileno = 0;
1629
+	else
1630
+	    new->fileno = atoi(tokens[7]);
1676 1631
 
1677
-	if(!(pt = cli_strtok(buffer, 8, ":"))) {
1678
-	    if(new->filename) mp_free((*engine)->mempool, new->filename);
1679
-	    mp_free((*engine)->mempool, new->virname);
1680
-	    mp_free((*engine)->mempool, new);
1681
-	    ret = CL_EMALFDB;
1682
-	    break;
1683
-	} else {
1684
-	    if(!strcmp(pt, "*"))
1685
-		new->maxdepth = 0;
1686
-	    else
1687
-		new->maxdepth = atoi(pt);
1688
-	    free(pt);
1689
-	}
1632
+	if(!strcmp(tokens[8], "*"))
1633
+	    new->maxdepth = 0;
1634
+	else
1635
+	    new->maxdepth = atoi(tokens[8]);
1690 1636
 
1691 1637
 	if(type == 1) {
1692 1638
 	    new->next = (*engine)->zip_mlist;
... ...
@@ -53,7 +53,7 @@
53 53
 	cli_strbcasestr(ext, ".cld")		\
54 54
     )
55 55
 
56
-char *cli_virname(char *virname, unsigned int official, unsigned int allocated);
56
+char *cli_virname(char *virname, unsigned int official);
57 57
 
58 58
 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, const uint32_t *lsigid, unsigned int options);
59 59