From 8d3aca307a50c10da4c8b2cb98113b9edf870544 Mon Sep 17 00:00:00 2001 From: Tomasz Kojm Date: Thu, 18 May 2006 11:29:24 +0000 Subject: [PATCH] minor code cleanup git-svn: trunk@1981 --- clamav-devel/ChangeLog | 4 ++++ clamav-devel/libclamav/filetypes.c | 4 ++-- clamav-devel/libclamav/matcher-ac.c | 13 +++++------ clamav-devel/libclamav/matcher.c | 4 ++-- clamav-devel/libclamav/mspack/cabd.c | 4 +++- clamav-devel/libclamav/mspack/lzxd.c | 2 ++ clamav-devel/libclamav/mspack/mszipd.c | 2 ++ clamav-devel/libclamav/mspack/qtmd.c | 2 ++ clamav-devel/libclamav/others.c | 1 - clamav-devel/libclamav/pe.c | 18 +++++++-------- clamav-devel/libclamav/readdb.c | 31 ++++++++++++-------------- clamav-devel/libclamav/scanners.c | 20 +++++------------ clamav-devel/libclamav/sis.c | 5 +++-- clamav-devel/libclamav/yc.c | 2 +- 14 files changed, 56 insertions(+), 56 deletions(-) diff --git a/clamav-devel/ChangeLog b/clamav-devel/ChangeLog index 864fa3df0..e147e0cc8 100644 --- a/clamav-devel/ChangeLog +++ b/clamav-devel/ChangeLog @@ -1,3 +1,7 @@ +Thu May 18 13:25:58 CEST 2006 (tk) +---------------------------------- + * libclamav: minor code cleanup + Thu May 18 12:00:23 CEST 2006 (tk) ---------------------------------- * libclamav/str.c: cli_hex2int: small tweak from NJH diff --git a/clamav-devel/libclamav/filetypes.c b/clamav-devel/libclamav/filetypes.c index ae6192d26..795e8fee7 100644 --- a/clamav-devel/libclamav/filetypes.c +++ b/clamav-devel/libclamav/filetypes.c @@ -116,7 +116,7 @@ static const struct cli_magic_s cli_magic[] = { /* Others */ {0, "\320\317\021\340\241\261\032\341", 8, "OLE2 container", CL_TYPE_MSOLE2}, - {0, "\%PDF-", 5, "PDF document", CL_TYPE_PDF}, + {0, "%%PDF-", 5, "PDF document", CL_TYPE_PDF}, {0, "\266\271\254\256\376\377\377\377", 8, "CryptFF", CL_TYPE_CRYPTFF}, /* Ignored types */ @@ -126,7 +126,7 @@ static const struct cli_magic_s cli_magic[] = { {0, "OggS", 4, "Ogg Stream", CL_TYPE_DATA}, {0, "ID3", 3, "MP3", CL_TYPE_DATA}, {0, "\377\373\220", 3, "MP3", CL_TYPE_DATA}, - {0, "\%!PS-Adobe-", 11, "PostScript", CL_TYPE_DATA}, + {0, "%%!PS-Adobe-", 11, "PostScript", CL_TYPE_DATA}, {0, "\060\046\262\165\216\146\317", 7, "WMA/WMV/ASF", CL_TYPE_DATA}, {0, ".RMF" , 4, "Real Media File", CL_TYPE_DATA}, diff --git a/clamav-devel/libclamav/matcher-ac.c b/clamav-devel/libclamav/matcher-ac.c index 228f0cd38..bd89887c1 100644 --- a/clamav-devel/libclamav/matcher-ac.c +++ b/clamav-devel/libclamav/matcher-ac.c @@ -4,7 +4,7 @@ * http://www-sr.informatik.uni-tuebingen.de/~buehler/AC/AC.html * Thanks to Kurt Huwig for pointing me to this page. * - * Copyright (C) 2002 - 2005 Tomasz Kojm + * Copyright (C) 2002 - 2006 Tomasz Kojm * * This program is free software; you can redistribute it and/or modify * 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) pattern->next = pos->list; pos->list = pattern; - return 0; + return CL_SUCCESS; } 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) new->next = *bfs; new->node = n; *bfs = new; - return 0; + return CL_SUCCESS; } static struct cli_ac_node *cli_dequeue(struct nodelist **bfs) @@ -164,19 +164,18 @@ static int cli_maketrans(struct cli_matcher *root) } } } - return 0; + return CL_SUCCESS; } int cli_ac_buildtrie(struct cli_matcher *root) { - int ret; if(!root) return CL_EMALFDB; if(!root->ac_root) { - cli_dbgmsg("Pattern matcher not initialised\n"); - return 0; + cli_dbgmsg("AC pattern matcher not initialised\n"); + return CL_SUCCESS; } return cli_maketrans(root); diff --git a/clamav-devel/libclamav/matcher.c b/clamav-devel/libclamav/matcher.c index 2a02ca865..4029a30e9 100644 --- a/clamav-devel/libclamav/matcher.c +++ b/clamav-devel/libclamav/matcher.c @@ -325,9 +325,9 @@ int cli_validatesig(unsigned short target, unsigned short ftype, const char *off int cli_scandesc(int desc, cli_ctx *ctx, unsigned short otfrec, unsigned short ftype, struct cli_matched_type **ftoffset) { char *buffer, *buff, *endbl, *pt; - int ret = CL_CLEAN, *gpartcnt, *tpartcnt, type = CL_CLEAN, i, tid = 0, bytes; + int ret = CL_CLEAN, *gpartcnt = NULL, *tpartcnt = NULL, type = CL_CLEAN, i, tid = 0, bytes; unsigned int buffersize, length, maxpatlen, shift = 0; - unsigned long int *gpartoff, *tpartoff, offset = 0; + unsigned long int *gpartoff = NULL, *tpartoff = NULL, offset = 0; MD5_CTX md5ctx; unsigned char digest[16]; struct cli_md5_node *md5_node; diff --git a/clamav-devel/libclamav/mspack/cabd.c b/clamav-devel/libclamav/mspack/cabd.c index 15de7e9a5..fc013074b 100644 --- a/clamav-devel/libclamav/mspack/cabd.c +++ b/clamav-devel/libclamav/mspack/cabd.c @@ -37,6 +37,8 @@ #include #include +#include "others.h" + /* Notes on compliance with cabinet specification: * * 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) { struct mscab_decompressor_p *this = (struct mscab_decompressor_p *) file; unsigned char *buf = (unsigned char *) buffer; struct mspack_system *sys = this->system; - int avail, todo, outlen, ignore_cksum; + int avail, todo, outlen = 0, ignore_cksum; ignore_cksum = this->param[MSCABD_PARAM_FIXMSZIP] && ((this->d->comp_type & cffoldCOMPTYPE_MASK) == cffoldCOMPTYPE_MSZIP); diff --git a/clamav-devel/libclamav/mspack/lzxd.c b/clamav-devel/libclamav/mspack/lzxd.c index e457f8d51..40758e4f3 100644 --- a/clamav-devel/libclamav/mspack/lzxd.c +++ b/clamav-devel/libclamav/mspack/lzxd.c @@ -20,6 +20,8 @@ #include #include +#include "others.h" + /* Microsoft's LZX document and their implementation of the * com.ms.util.cab Java package do not concur. * diff --git a/clamav-devel/libclamav/mspack/mszipd.c b/clamav-devel/libclamav/mspack/mszipd.c index 153741fb9..d9592d737 100644 --- a/clamav-devel/libclamav/mspack/mszipd.c +++ b/clamav-devel/libclamav/mspack/mszipd.c @@ -20,6 +20,8 @@ #include #include +#include "others.h" + /* match lengths for literal codes 257.. 285 */ static const unsigned short lit_lengths[29] = { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, diff --git a/clamav-devel/libclamav/mspack/qtmd.c b/clamav-devel/libclamav/mspack/qtmd.c index 6ebb8b882..a9a0cea21 100644 --- a/clamav-devel/libclamav/mspack/qtmd.c +++ b/clamav-devel/libclamav/mspack/qtmd.c @@ -28,6 +28,8 @@ #include #include +#include "others.h" + /* Quantum decompressor bitstream reading macros * * STORE_BITS stores bitstream state in qtmd_stream structure diff --git a/clamav-devel/libclamav/others.c b/clamav-devel/libclamav/others.c index 894896f82..45826a3f4 100644 --- a/clamav-devel/libclamav/others.c +++ b/clamav-devel/libclamav/others.c @@ -396,7 +396,6 @@ static char *cli_gentempname(const char *dir) const char *mdir; unsigned char salt[16 + 32]; int i; - struct stat foo; if(!dir) { if((mdir = getenv("TMPDIR")) == NULL) diff --git a/clamav-devel/libclamav/pe.c b/clamav-devel/libclamav/pe.c index 7b55268c2..561223b34 100644 --- a/clamav-devel/libclamav/pe.c +++ b/clamav-devel/libclamav/pe.c @@ -490,7 +490,7 @@ int cli_scanpe(int desc, cli_ctx *ctx) return CL_CLEAN; } - strncpy(sname, section_hdr[i].Name, 8); + strncpy(sname, (char *) section_hdr[i].Name, 8); sname[8] = 0; cli_dbgmsg("Section %d\n", i); cli_dbgmsg("Section name: %s\n", sname); @@ -627,7 +627,7 @@ int cli_scanpe(int desc, cli_ctx *ctx) 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) { uint32_t remaining = EC32(section_hdr[0].SizeOfRawData); uint32_t chunk = sizeof(buff); - uint32_t val, shift, raddr, curroff, total = 0; + uint32_t val, shift, raddr, total = 0; const char *jpt; struct offset_list *offlist = NULL, *offnode; @@ -898,7 +898,7 @@ int cli_scanpe(int desc, cli_ctx *ctx) default: /* Everything gone wrong */ cli_dbgmsg("FSG: Unpacking failed\n"); close(ndesc); - unlink(tempfile); // It's empty anyway + unlink(tempfile); /* It's empty anyway */ free(tempfile); free(src); free(dest); @@ -1101,7 +1101,7 @@ int cli_scanpe(int desc, cli_ctx *ctx) default: /* Everything gone wrong */ cli_dbgmsg("FSG: Unpacking failed\n"); close(ndesc); - unlink(tempfile); // It's empty anyway + unlink(tempfile); /* It's empty anyway */ free(tempfile); free(src); free(dest); @@ -1306,7 +1306,7 @@ int cli_scanpe(int desc, cli_ctx *ctx) default: /* Everything gone wrong */ cli_dbgmsg("FSG: Unpacking failed\n"); close(ndesc); - unlink(tempfile); // It's empty anyway + unlink(tempfile); /* It's empty anyway */ free(tempfile); free(src); free(dest); @@ -1323,14 +1323,14 @@ int cli_scanpe(int desc, cli_ctx *ctx) /* UPX support */ - strncpy(sname, section_hdr[i].Name, 8); + strncpy(sname, (char *) section_hdr[i].Name, 8); sname[8] = 0; cli_dbgmsg("UPX: Section %d name: %s\n", i, sname); - strncpy(sname, section_hdr[i + 1].Name, 8); + strncpy(sname, (char *) section_hdr[i + 1].Name, 8); sname[8] = 0; cli_dbgmsg("UPX: Section %d name: %s\n", i + 1, sname); - if(strncmp(section_hdr[i].Name, "UPX0", 4) || strncmp(section_hdr[i + 1].Name, "UPX1", 4)) + if(strncmp((char *) section_hdr[i].Name, "UPX0", 4) || strncmp((char *) section_hdr[i + 1].Name, "UPX1", 4)) cli_dbgmsg("UPX: Possibly hacked UPX section headers\n"); /* we assume (i + 1) is UPX1 */ @@ -1769,7 +1769,7 @@ int cli_peheader(int desc, struct cli_exe_info *peinfo) { uint16_t e_magic; /* DOS signature ("MZ") */ uint32_t e_lfanew; /* address of new exe header */ - uint32_t min, max; + uint32_t min = 0, max = 0; struct pe_image_file_hdr file_hdr; struct pe_image_optional_hdr32 optional_hdr32; struct pe_image_optional_hdr64 optional_hdr64; diff --git a/clamav-devel/libclamav/readdb.c b/clamav-devel/libclamav/readdb.c index a54d1cc3f..fa17ff446 100644 --- a/clamav-devel/libclamav/readdb.c +++ b/clamav-devel/libclamav/readdb.c @@ -255,7 +255,7 @@ static int cli_ac_addsig(struct cli_matcher *root, const char *virname, const ch if(new->alt) free(hex); - return 0; + return CL_SUCCESS; } 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 } } - return 0; + return CL_SUCCESS; } static int cli_initengine(struct cl_engine **engine, unsigned int options) { - struct cli_matcher *root; - int i, ret; - if(!*engine) { cli_dbgmsg("Initializing the engine structure\n"); @@ -464,7 +461,7 @@ static int cli_initengine(struct cl_engine **engine, unsigned int options) } } - return 0; + return CL_SUCCESS; } 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) } } - return 0; + return CL_SUCCESS; } 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, if(signo) *signo += line; - return 0; + return CL_SUCCESS; } 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, cli_dbgmsg("*** Self protection mechanism activated.\n"); } - return 0; + return CL_SUCCESS; } 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, if(signo) *signo += line; - return 0; + return CL_SUCCESS; } 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, if(signo) *signo += (line - comments); - return 0; + return CL_SUCCESS; } #ifdef HAVE_HWACCEL @@ -1148,7 +1145,7 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine **engine, unsigne } closedir(dd); - return 0; + return CL_SUCCESS; } 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) } closedir(dd); - return 0; + return CL_SUCCESS; } int cl_statchkdir(const struct cl_stat *dbstat) @@ -1344,7 +1341,7 @@ int cl_statchkdir(const struct cl_stat *dbstat) } closedir(dd); - return 0; + return CL_SUCCESS; } int cl_statfree(struct cl_stat *dbstat) @@ -1375,12 +1372,12 @@ int cl_statfree(struct cl_stat *dbstat) return CL_ENULLARG; } - return 0; + return CL_SUCCESS; } void cl_free(struct cl_engine *engine) { - int i, ret; + int i; struct cli_md5_node *md5pt, *md5h; struct cli_meta_node *metapt, *metah; struct cli_matcher *root; @@ -1475,7 +1472,7 @@ int cl_build(struct cl_engine *engine) cli_ac_buildtrie(root); /* FIXME: check return values of cli_ac_buildtree */ - return 0; + return CL_SUCCESS; } struct cl_engine *cl_dup(struct cl_engine *engine) diff --git a/clamav-devel/libclamav/scanners.c b/clamav-devel/libclamav/scanners.c index b4d5a6b3b..751d28e99 100644 --- a/clamav-devel/libclamav/scanners.c +++ b/clamav-devel/libclamav/scanners.c @@ -55,14 +55,18 @@ extern short cli_leavetemps_flag; #include "ole2_extract.h" #include "vba_extract.h" #include "msexpand.h" +#include "mbox.h" #include "chmunpack.h" #include "pe.h" +#include "elf.h" #include "filetypes.h" #include "htmlnorm.h" #include "untar.h" #include "special.h" #include "binhex.h" +/* #include "uuencode.h" */ #include "tnef.h" +#include "pst.h" #include "sis.h" #include "pdf.h" @@ -95,22 +99,11 @@ extern short cli_leavetemps_flag; #define MAX_MAIL_RECURSION 15 -extern int cli_mbox(const char *dir, int desc, cli_ctx *ctx); /* FIXME */ static int cli_scanfile(const char *filename, cli_ctx *ctx); -/* -#ifdef CL_THREAD_SAFE -static void cli_unlock_mutex(void *mtx) -{ - cli_dbgmsg("Pthread cancelled. Unlocking mutex.\n"); - pthread_mutex_unlock(mtx); -} -#endif -*/ - static int cli_scanrar(int desc, cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_check) { - int fd, ret = CL_CLEAN; + int ret = CL_CLEAN; unsigned int files = 0; rar_metadata_t *metadata, *metadata_tmp; 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 ZZIP_DIRENT zdirent; ZZIP_FILE *zfp; FILE *tmp = NULL; - char *tmpname; - char *buff; + char *tmpname = NULL, *buff; int fd, bytes, ret = CL_CLEAN; unsigned long int size = 0; unsigned int files = 0, encrypted; diff --git a/clamav-devel/libclamav/sis.c b/clamav-devel/libclamav/sis.c index 57f5c3bb7..8ba8e4783 100644 --- a/clamav-devel/libclamav/sis.c +++ b/clamav-devel/libclamav/sis.c @@ -41,8 +41,9 @@ #undef HAVE_MMAP #endif -#include "cltypes.h" #include "clamav.h" +#include "scanners.h" +#include "cltypes.h" #include "sis.h" #define EC32(x) le32_to_host(x) /* Convert little endian to host */ @@ -343,7 +344,7 @@ int cli_scansis(int desc, cli_ctx *ctx) struct sis_file_hdr6 file_hdr6; uint8_t release = 0, compressed, ifile = 0; uint16_t opts, nlangs, *langrecs, nfiles; - uint32_t recp, frecord, n; + uint32_t frecord, n; size_t length; char *mfile = NULL, *langs, *dir; struct stat sb; diff --git a/clamav-devel/libclamav/yc.c b/clamav-devel/libclamav/yc.c index c1bec899f..59d827b1f 100644 --- a/clamav-devel/libclamav/yc.c +++ b/clamav-devel/libclamav/yc.c @@ -207,7 +207,7 @@ int yc_decrypt(char *fbuf, unsigned int filesize, struct pe_image_section_hdr *s name == 0x6164722E || /* .rda */ name == 0x6164692E || /* .ida */ name == 0x736C742E || /* .tls */ - name&0xffff == 0x4379 || /* yC */ + (name&0xffff == 0x4379) || /* yC */ EC32(sections[i].PointerToRawData) == 0 || EC32(sections[i].SizeOfRawData) == 0 ) continue; cli_dbgmsg("yC: decrypting sect%d\n",i);