Browse code

minor code cleanup

git-svn: trunk@1981

Tomasz Kojm authored on 2006/05/18 20:29:24
Showing 14 changed files
... ...
@@ -1,3 +1,7 @@
1
+Thu May 18 13:25:58 CEST 2006 (tk)
2
+----------------------------------
3
+  * libclamav: minor code cleanup
4
+
1 5
 Thu May 18 12:00:23 CEST 2006 (tk)
2 6
 ----------------------------------
3 7
   * libclamav/str.c: cli_hex2int: small tweak from NJH
... ...
@@ -116,7 +116,7 @@ static const struct cli_magic_s cli_magic[] = {
116 116
     /* Others */
117 117
 
118 118
     {0,  "\320\317\021\340\241\261\032\341", 8, "OLE2 container", CL_TYPE_MSOLE2},
119
-    {0,  "\%PDF-",			 5, "PDF document", CL_TYPE_PDF},
119
+    {0,  "%%PDF-",			 5, "PDF document", CL_TYPE_PDF},
120 120
     {0,  "\266\271\254\256\376\377\377\377", 8, "CryptFF", CL_TYPE_CRYPTFF},
121 121
 
122 122
     /* Ignored types */
... ...
@@ -126,7 +126,7 @@ static const struct cli_magic_s cli_magic[] = {
126 126
     {0,  "OggS",                         4, "Ogg Stream",         CL_TYPE_DATA},
127 127
     {0,  "ID3",				 3, "MP3",		  CL_TYPE_DATA},
128 128
     {0,  "\377\373\220",		 3, "MP3",		  CL_TYPE_DATA},
129
-    {0,  "\%!PS-Adobe-",		11, "PostScript",	  CL_TYPE_DATA},
129
+    {0,  "%%!PS-Adobe-",		11, "PostScript",	  CL_TYPE_DATA},
130 130
     {0,  "\060\046\262\165\216\146\317", 7, "WMA/WMV/ASF",	  CL_TYPE_DATA},
131 131
     {0,  ".RMF" ,			 4, "Real Media File",	  CL_TYPE_DATA},
132 132
 
... ...
@@ -4,7 +4,7 @@
4 4
  *  http://www-sr.informatik.uni-tuebingen.de/~buehler/AC/AC.html
5 5
  *  Thanks to Kurt Huwig for pointing me to this page.
6 6
  *
7
- *  Copyright (C) 2002 - 2005 Tomasz Kojm <tkojm@clamav.net>
7
+ *  Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net>
8 8
  *
9 9
  *  This program is free software; you can redistribute it and/or modify
10 10
  *  it under the terms of the GNU General Public License as published by
... ...
@@ -84,7 +84,7 @@ int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern)
84 84
     pattern->next = pos->list;
85 85
     pos->list = pattern;
86 86
 
87
-    return 0;
87
+    return CL_SUCCESS;
88 88
 }
89 89
 
90 90
 static int cli_enqueue(struct nodelist **bfs, struct cli_ac_node *n)
... ...
@@ -100,7 +100,7 @@ static int cli_enqueue(struct nodelist **bfs, struct cli_ac_node *n)
100 100
     new->next = *bfs;
101 101
     new->node = n;
102 102
     *bfs = new;
103
-    return 0;
103
+    return CL_SUCCESS;
104 104
 }
105 105
 
106 106
 static struct cli_ac_node *cli_dequeue(struct nodelist **bfs)
... ...
@@ -164,19 +164,18 @@ static int cli_maketrans(struct cli_matcher *root)
164 164
 	    }
165 165
 	}
166 166
     }
167
-    return 0;
167
+    return CL_SUCCESS;
168 168
 }
169 169
 
170 170
 int cli_ac_buildtrie(struct cli_matcher *root)
171 171
 {
172
-	int ret;
173 172
 
174 173
     if(!root)
175 174
 	return CL_EMALFDB;
176 175
 
177 176
     if(!root->ac_root) {
178
-	cli_dbgmsg("Pattern matcher not initialised\n");
179
-	return 0;
177
+	cli_dbgmsg("AC pattern matcher not initialised\n");
178
+	return CL_SUCCESS;
180 179
     }
181 180
 
182 181
     return cli_maketrans(root);
... ...
@@ -325,9 +325,9 @@ int cli_validatesig(unsigned short target, unsigned short ftype, const char *off
325 325
 int cli_scandesc(int desc, cli_ctx *ctx, unsigned short otfrec, unsigned short ftype, struct cli_matched_type **ftoffset)
326 326
 {
327 327
  	char *buffer, *buff, *endbl, *pt;
328
-	int ret = CL_CLEAN, *gpartcnt, *tpartcnt, type = CL_CLEAN, i, tid = 0, bytes;
328
+	int ret = CL_CLEAN, *gpartcnt = NULL, *tpartcnt = NULL, type = CL_CLEAN, i, tid = 0, bytes;
329 329
 	unsigned int buffersize, length, maxpatlen, shift = 0;
330
-	unsigned long int *gpartoff, *tpartoff, offset = 0;
330
+	unsigned long int *gpartoff = NULL, *tpartoff = NULL, offset = 0;
331 331
 	MD5_CTX md5ctx;
332 332
 	unsigned char digest[16];
333 333
 	struct cli_md5_node *md5_node;
... ...
@@ -37,6 +37,8 @@
37 37
 #include <system.h>
38 38
 #include <cab.h>
39 39
 
40
+#include "others.h"
41
+
40 42
 /* Notes on compliance with cabinet specification:
41 43
  *
42 44
  * One of the main changes between cabextract 0.6 and libmspack's cab
... ...
@@ -1242,7 +1244,7 @@ static int cabd_sys_read(struct mspack_file *file, void *buffer, int bytes) {
1242 1242
   struct mscab_decompressor_p *this = (struct mscab_decompressor_p *) file;
1243 1243
   unsigned char *buf = (unsigned char *) buffer;
1244 1244
   struct mspack_system *sys = this->system;
1245
-  int avail, todo, outlen, ignore_cksum;
1245
+  int avail, todo, outlen = 0, ignore_cksum;
1246 1246
 
1247 1247
   ignore_cksum = this->param[MSCABD_PARAM_FIXMSZIP] &&
1248 1248
     ((this->d->comp_type & cffoldCOMPTYPE_MASK) == cffoldCOMPTYPE_MSZIP);
... ...
@@ -20,6 +20,8 @@
20 20
 #include <system.h>
21 21
 #include <lzx.h>
22 22
 
23
+#include "others.h"
24
+
23 25
 /* Microsoft's LZX document and their implementation of the
24 26
  * com.ms.util.cab Java package do not concur.
25 27
  *
... ...
@@ -20,6 +20,8 @@
20 20
 #include <system.h>
21 21
 #include <mszip.h>
22 22
 
23
+#include "others.h"
24
+
23 25
 /* match lengths for literal codes 257.. 285 */
24 26
 static const unsigned short lit_lengths[29] = {
25 27
   3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27,
... ...
@@ -28,6 +28,8 @@
28 28
 #include <system.h>
29 29
 #include <qtm.h>
30 30
 
31
+#include "others.h"
32
+
31 33
 /* Quantum decompressor bitstream reading macros
32 34
  *
33 35
  * STORE_BITS        stores bitstream state in qtmd_stream structure
... ...
@@ -396,7 +396,6 @@ static char *cli_gentempname(const char *dir)
396 396
         const char *mdir;
397 397
 	unsigned char salt[16 + 32];
398 398
 	int i;
399
-	struct stat foo;
400 399
 
401 400
     if(!dir) {
402 401
 	if((mdir = getenv("TMPDIR")) == NULL)
... ...
@@ -490,7 +490,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
490 490
 	    return CL_CLEAN;
491 491
 	}
492 492
 
493
-	strncpy(sname, section_hdr[i].Name, 8);
493
+	strncpy(sname, (char *) section_hdr[i].Name, 8);
494 494
 	sname[8] = 0;
495 495
 	cli_dbgmsg("Section %d\n", i);
496 496
 	cli_dbgmsg("Section name: %s\n", sname);
... ...
@@ -627,7 +627,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
627 627
    if(polipos && !dll && !pe_plus && nsections > 2 && nsections < 13 && e_lfanew <= 0x800 && (EC16(optional_hdr32.Subsystem) == 2 || EC16(optional_hdr32.Subsystem) == 3) && EC16(file_hdr.Machine) == 0x14c && optional_hdr32.SizeOfStackReserve >= 0x80000) {
628 628
 		uint32_t remaining = EC32(section_hdr[0].SizeOfRawData);
629 629
 		uint32_t chunk = sizeof(buff);
630
-		uint32_t val, shift, raddr, curroff, total = 0;
630
+		uint32_t val, shift, raddr, total = 0;
631 631
 		const char *jpt;
632 632
 		struct offset_list *offlist = NULL, *offnode;
633 633
 
... ...
@@ -898,7 +898,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
898 898
 		    default: /* Everything gone wrong */
899 899
 			cli_dbgmsg("FSG: Unpacking failed\n");
900 900
 			close(ndesc);
901
-			unlink(tempfile); // It's empty anyway
901
+			unlink(tempfile); /* It's empty anyway */
902 902
 			free(tempfile);
903 903
 			free(src);
904 904
 			free(dest);
... ...
@@ -1101,7 +1101,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1101 1101
 		    default: /* Everything gone wrong */
1102 1102
 			cli_dbgmsg("FSG: Unpacking failed\n");
1103 1103
 			close(ndesc);
1104
-			unlink(tempfile); // It's empty anyway
1104
+			unlink(tempfile); /* It's empty anyway */
1105 1105
 			free(tempfile);
1106 1106
 			free(src);
1107 1107
 			free(dest);
... ...
@@ -1306,7 +1306,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1306 1306
 		    default: /* Everything gone wrong */
1307 1307
 			cli_dbgmsg("FSG: Unpacking failed\n");
1308 1308
 			close(ndesc);
1309
-			unlink(tempfile); // It's empty anyway
1309
+			unlink(tempfile); /* It's empty anyway */
1310 1310
 			free(tempfile);
1311 1311
 			free(src);
1312 1312
 			free(dest);
... ...
@@ -1323,14 +1323,14 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1323 1323
 
1324 1324
 	    /* UPX support */
1325 1325
 
1326
-	    strncpy(sname, section_hdr[i].Name, 8);
1326
+	    strncpy(sname, (char *) section_hdr[i].Name, 8);
1327 1327
 	    sname[8] = 0;
1328 1328
 	    cli_dbgmsg("UPX: Section %d name: %s\n", i, sname);
1329
-	    strncpy(sname, section_hdr[i + 1].Name, 8);
1329
+	    strncpy(sname, (char *) section_hdr[i + 1].Name, 8);
1330 1330
 	    sname[8] = 0;
1331 1331
 	    cli_dbgmsg("UPX: Section %d name: %s\n", i + 1, sname);
1332 1332
 
1333
-	    if(strncmp(section_hdr[i].Name, "UPX0", 4) || strncmp(section_hdr[i + 1].Name, "UPX1", 4))
1333
+	    if(strncmp((char *) section_hdr[i].Name, "UPX0", 4) || strncmp((char *) section_hdr[i + 1].Name, "UPX1", 4))
1334 1334
 		cli_dbgmsg("UPX: Possibly hacked UPX section headers\n");
1335 1335
 
1336 1336
 	    /* we assume (i + 1) is UPX1 */
... ...
@@ -1769,7 +1769,7 @@ int cli_peheader(int desc, struct cli_exe_info *peinfo)
1769 1769
 {
1770 1770
 	uint16_t e_magic; /* DOS signature ("MZ") */
1771 1771
 	uint32_t e_lfanew; /* address of new exe header */
1772
-	uint32_t min, max;
1772
+	uint32_t min = 0, max = 0;
1773 1773
 	struct pe_image_file_hdr file_hdr;
1774 1774
 	struct pe_image_optional_hdr32 optional_hdr32;
1775 1775
 	struct pe_image_optional_hdr64 optional_hdr64;
... ...
@@ -255,7 +255,7 @@ static int cli_ac_addsig(struct cli_matcher *root, const char *virname, const ch
255 255
     if(new->alt)
256 256
 	free(hex);
257 257
 
258
-    return 0;
258
+    return CL_SUCCESS;
259 259
 }
260 260
 
261 261
 int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hexsig, unsigned short type, char *offset, unsigned short target)
... ...
@@ -436,14 +436,11 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex
436 436
 	}
437 437
     }
438 438
 
439
-    return 0;
439
+    return CL_SUCCESS;
440 440
 }
441 441
 
442 442
 static int cli_initengine(struct cl_engine **engine, unsigned int options)
443 443
 {
444
-	struct cli_matcher *root;
445
-	int i, ret;
446
-
447 444
 
448 445
     if(!*engine) {
449 446
 	cli_dbgmsg("Initializing the engine structure\n");
... ...
@@ -464,7 +461,7 @@ static int cli_initengine(struct cl_engine **engine, unsigned int options)
464 464
 	}
465 465
     }
466 466
 
467
-    return 0;
467
+    return CL_SUCCESS;
468 468
 }
469 469
 
470 470
 static int cli_initroots(struct cl_engine *engine, unsigned int options)
... ...
@@ -505,7 +502,7 @@ static int cli_initroots(struct cl_engine *engine, unsigned int options)
505 505
 	}
506 506
     }
507 507
 
508
-    return 0;
508
+    return CL_SUCCESS;
509 509
 }
510 510
 
511 511
 static int cli_loaddb(FILE *fd, struct cl_engine **engine, unsigned int *signo, unsigned int options)
... ...
@@ -565,7 +562,7 @@ static int cli_loaddb(FILE *fd, struct cl_engine **engine, unsigned int *signo,
565 565
     if(signo)
566 566
 	*signo += line;
567 567
 
568
-    return 0;
568
+    return CL_SUCCESS;
569 569
 }
570 570
 
571 571
 static int cli_loadndb(FILE *fd, struct cl_engine **engine, unsigned int *signo, unsigned short sdb, unsigned int options)
... ...
@@ -711,7 +708,7 @@ static int cli_loadndb(FILE *fd, struct cl_engine **engine, unsigned int *signo,
711 711
 	cli_dbgmsg("*** Self protection mechanism activated.\n");
712 712
     }
713 713
 
714
-    return 0;
714
+    return CL_SUCCESS;
715 715
 }
716 716
 
717 717
 static int cli_loadhdb(FILE *fd, struct cl_engine **engine, unsigned int *signo, unsigned short fp, unsigned int options)
... ...
@@ -799,7 +796,7 @@ static int cli_loadhdb(FILE *fd, struct cl_engine **engine, unsigned int *signo,
799 799
     if(signo)
800 800
 	*signo += line;
801 801
 
802
-    return 0;
802
+    return CL_SUCCESS;
803 803
 }
804 804
 
805 805
 static int cli_loadmd(FILE *fd, struct cl_engine **engine, unsigned int *signo, int type, unsigned int options)
... ...
@@ -970,7 +967,7 @@ static int cli_loadmd(FILE *fd, struct cl_engine **engine, unsigned int *signo,
970 970
     if(signo)
971 971
 	*signo += (line - comments);
972 972
 
973
-    return 0;
973
+    return CL_SUCCESS;
974 974
 }
975 975
 
976 976
 #ifdef HAVE_HWACCEL
... ...
@@ -1148,7 +1145,7 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine **engine, unsigne
1148 1148
     }
1149 1149
 
1150 1150
     closedir(dd);
1151
-    return 0;
1151
+    return CL_SUCCESS;
1152 1152
 }
1153 1153
 
1154 1154
 int cl_loaddbdir(const char *dirname, struct cl_engine **engine, unsigned int *signo) {
... ...
@@ -1262,7 +1259,7 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat)
1262 1262
     }
1263 1263
 
1264 1264
     closedir(dd);
1265
-    return 0;
1265
+    return CL_SUCCESS;
1266 1266
 }
1267 1267
 
1268 1268
 int cl_statchkdir(const struct cl_stat *dbstat)
... ...
@@ -1344,7 +1341,7 @@ int cl_statchkdir(const struct cl_stat *dbstat)
1344 1344
     }
1345 1345
 
1346 1346
     closedir(dd);
1347
-    return 0;
1347
+    return CL_SUCCESS;
1348 1348
 }
1349 1349
 
1350 1350
 int cl_statfree(struct cl_stat *dbstat)
... ...
@@ -1375,12 +1372,12 @@ int cl_statfree(struct cl_stat *dbstat)
1375 1375
 	return CL_ENULLARG;
1376 1376
     }
1377 1377
 
1378
-    return 0;
1378
+    return CL_SUCCESS;
1379 1379
 }
1380 1380
 
1381 1381
 void cl_free(struct cl_engine *engine)
1382 1382
 {
1383
-	int i, ret;
1383
+	int i;
1384 1384
 	struct cli_md5_node *md5pt, *md5h;
1385 1385
 	struct cli_meta_node *metapt, *metah;
1386 1386
 	struct cli_matcher *root;
... ...
@@ -1475,7 +1472,7 @@ int cl_build(struct cl_engine *engine)
1475 1475
 	    cli_ac_buildtrie(root);
1476 1476
     /* FIXME: check return values of cli_ac_buildtree */
1477 1477
 
1478
-    return 0;
1478
+    return CL_SUCCESS;
1479 1479
 }
1480 1480
 
1481 1481
 struct cl_engine *cl_dup(struct cl_engine *engine)
... ...
@@ -55,14 +55,18 @@ extern short cli_leavetemps_flag;
55 55
 #include "ole2_extract.h"
56 56
 #include "vba_extract.h"
57 57
 #include "msexpand.h"
58
+#include "mbox.h"
58 59
 #include "chmunpack.h"
59 60
 #include "pe.h"
61
+#include "elf.h"
60 62
 #include "filetypes.h"
61 63
 #include "htmlnorm.h"
62 64
 #include "untar.h"
63 65
 #include "special.h"
64 66
 #include "binhex.h"
67
+/* #include "uuencode.h" */
65 68
 #include "tnef.h"
69
+#include "pst.h"
66 70
 #include "sis.h"
67 71
 #include "pdf.h"
68 72
 
... ...
@@ -95,22 +99,11 @@ extern short cli_leavetemps_flag;
95 95
 
96 96
 #define MAX_MAIL_RECURSION  15
97 97
 
98
-extern int cli_mbox(const char *dir, int desc, cli_ctx *ctx); /* FIXME */
99 98
 static int cli_scanfile(const char *filename, cli_ctx *ctx);
100 99
 
101
-/*
102
-#ifdef CL_THREAD_SAFE
103
-static void cli_unlock_mutex(void *mtx)
104
-{
105
-    cli_dbgmsg("Pthread cancelled. Unlocking mutex.\n");
106
-    pthread_mutex_unlock(mtx);
107
-}
108
-#endif
109
-*/
110
-
111 100
 static int cli_scanrar(int desc, cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_check)
112 101
 {
113
-	int fd, ret = CL_CLEAN;
102
+	int ret = CL_CLEAN;
114 103
 	unsigned int files = 0;
115 104
 	rar_metadata_t *metadata, *metadata_tmp;
116 105
 	struct cli_meta_node *mdata;
... ...
@@ -270,8 +263,7 @@ static int cli_scanzip(int desc, cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_c
270 270
 	ZZIP_DIRENT zdirent;
271 271
 	ZZIP_FILE *zfp;
272 272
 	FILE *tmp = NULL;
273
-	char *tmpname;
274
-	char *buff;
273
+	char *tmpname = NULL, *buff;
275 274
 	int fd, bytes, ret = CL_CLEAN;
276 275
 	unsigned long int size = 0;
277 276
 	unsigned int files = 0, encrypted;
... ...
@@ -41,8 +41,9 @@
41 41
 #undef HAVE_MMAP
42 42
 #endif
43 43
 
44
-#include "cltypes.h"
45 44
 #include "clamav.h"
45
+#include "scanners.h"
46
+#include "cltypes.h"
46 47
 #include "sis.h"
47 48
 
48 49
 #define EC32(x) le32_to_host(x) /* Convert little endian to host */
... ...
@@ -343,7 +344,7 @@ int cli_scansis(int desc, cli_ctx *ctx)
343 343
 	struct sis_file_hdr6 file_hdr6;
344 344
 	uint8_t release = 0, compressed, ifile = 0;
345 345
 	uint16_t opts, nlangs, *langrecs, nfiles;
346
-	uint32_t recp, frecord, n;
346
+	uint32_t frecord, n;
347 347
 	size_t length;
348 348
 	char *mfile = NULL, *langs, *dir;
349 349
 	struct stat sb;
... ...
@@ -207,7 +207,7 @@ int yc_decrypt(char *fbuf, unsigned int filesize, struct pe_image_section_hdr *s
207 207
 	   name == 0x6164722E || /* .rda */
208 208
 	   name == 0x6164692E || /* .ida */
209 209
 	   name == 0x736C742E || /* .tls */
210
-	   name&0xffff == 0x4379 || /* yC */
210
+	   (name&0xffff == 0x4379) || /* yC */
211 211
 	   EC32(sections[i].PointerToRawData) == 0 ||
212 212
 	   EC32(sections[i].SizeOfRawData) == 0 ) continue;
213 213
       cli_dbgmsg("yC: decrypting sect%d\n",i);