minor code cleanup

git-svn: trunk@2031
remotes/push_mirror/metadata
Tomasz Kojm 20 years ago
parent dd7c22061b
commit e12c29d28b
  1. 4
      clamav-devel/ChangeLog
  2. 10
      clamav-devel/libclamav/cvd.c
  3. 15
      clamav-devel/libclamav/dsig.c
  4. 4
      clamav-devel/libclamav/elf.c
  5. 2
      clamav-devel/libclamav/filetypes.c
  6. 4
      clamav-devel/libclamav/is_tar.c
  7. 2
      clamav-devel/libclamav/matcher-ac.c
  8. 2
      clamav-devel/libclamav/matcher-bm.c
  9. 2
      clamav-devel/libclamav/matcher.c
  10. 2
      clamav-devel/libclamav/matcher.h
  11. 6
      clamav-devel/libclamav/mspack/system.c
  12. 4
      clamav-devel/libclamav/pe.c
  13. 15
      clamav-devel/libclamav/readdb.c
  14. 16
      clamav-devel/libclamav/scanners.c
  15. 4
      clamav-devel/libclamav/sis.c
  16. 2
      clamav-devel/libclamav/str.c
  17. 20
      clamav-devel/libclamav/unrar/unrar.c
  18. 2
      clamav-devel/libclamav/unrar/unrar.h
  19. 2
      clamav-devel/libclamav/unrar/unrarfilter.c
  20. 2
      clamav-devel/libclamav/unrar/unrarppm.c
  21. 4
      clamav-devel/libclamav/unrar/unrarvm.c
  22. 10
      clamav-devel/libclamav/unzip.c
  23. 2
      clamav-devel/libclamav/yc.c

@ -1,3 +1,7 @@
Sat Jun 17 22:57:37 CEST 2006 (tk)
----------------------------------
* libclamav: minor code cleanup
Sat Jun 17 21:17:20 CEST 2006 (tk)
----------------------------------
* libclamav/matcher-bm.c: minor optimization patch (~7% speed up) from

@ -57,7 +57,11 @@ int cli_untgz(int fd, const char *destdir)
return -1;
}
fullname = (char *) calloc(sizeof(char), strlen(destdir) + 100 + 5);
fullname = (char *) cli_calloc(sizeof(char), strlen(destdir) + 100 + 5);
if(!fullname) {
cli_errmsg("cli_untgz: Can't allocate memory for fullname\n");
return -1;
}
while(1) {
@ -175,6 +179,10 @@ struct cl_cvd *cl_cvdparse(const char *head)
}
cvd = (struct cl_cvd *) cli_calloc(1, sizeof(struct cl_cvd));
if(!cvd) {
cli_errmsg("cl_cvdparse: Can't allocate memory for cvd\n");
return NULL;
}
if(!(cvd->time = cli_strtok(head, 1, ":"))) {
cli_errmsg("CVD -> Can't extract time from header.\n");

@ -75,17 +75,26 @@ static char *cli_decodesig(const char *sig, int plainlen, mpz_t e, mpz_t n)
mpz_init(c);
for(i = 0; i < siglen; i++) {
if((dec = cli_ndecode(sig[i])) < 0)
if((dec = cli_ndecode(sig[i])) < 0) {
mpz_clear(r);
mpz_clear(c);
return NULL;
}
mpz_set_ui(r, dec);
mpz_mul_2exp(r, r, 6 * i);
mpz_add(c, c, r);
}
mpz_init(p);
decoded = (char *) calloc(plainlen + 1, sizeof(char));
decoded = (char *) cli_calloc(plainlen + 1, sizeof(char));
if(!decoded) {
cli_errmsg("cli_decodesig: Can't allocate memory\n");
mpz_clear(r);
mpz_clear(c);
return NULL;
}
mpz_init(p);
mpz_powm(p, c, e, n); /* plain = cipher^e mod n */
mpz_clear(c);

@ -191,7 +191,7 @@ int cli_scanelf(int desc, cli_ctx *ctx)
shoff = EC32(file_hdr.e_shoff);
cli_dbgmsg("ELF: Section header table offset: %d\n", shoff);
if(lseek(desc, shoff, SEEK_SET) != shoff) {
if((uint32_t) lseek(desc, shoff, SEEK_SET) != shoff) {
/* Possibly broken end of file */
if(DETECT_BROKEN) {
if(ctx->virname)
@ -353,7 +353,7 @@ int cli_elfheader(int desc, struct cli_exe_info *elfinfo)
}
shoff = EC32(file_hdr.e_shoff);
if(lseek(desc, shoff, SEEK_SET) != shoff) {
if((uint32_t) lseek(desc, shoff, SEEK_SET) != shoff) {
/* Possibly broken end of file */
return -1;
}

@ -227,7 +227,7 @@ cli_file_t cli_filetype(const char *buf, size_t buflen)
return ascii ? CL_TYPE_UNKNOWN_TEXT : CL_TYPE_UNKNOWN_DATA;
}
int is_tar(unsigned char *buf, int nbytes);
int is_tar(unsigned char *buf, unsigned int nbytes);
cli_file_t cli_filetype2(int desc)
{

@ -5,7 +5,7 @@
* Public Domain version written 26 Aug 1985 John Gilmore (ihnp4!hoptoad!gnu).
*
* @(#)list.c 1.18 9/23/86 Public Domain - gnu
* $Id: is_tar.c,v 1.1 2005/03/22 21:26:25 kojm Exp $
* $Id: is_tar.c,v 1.2 2006/06/17 21:00:44 tkojm Exp $
*
* Comments changed and some code/comments reformatted
* for file command by Ian Darwin.
@ -32,7 +32,7 @@ static int from_oct(int digs, char *where);
* 1 for old UNIX tar file,
* 2 for Unix Std (POSIX) tar file.
*/
int is_tar(unsigned char *buf, int nbytes)
int is_tar(unsigned char *buf, unsigned int nbytes)
{
union record *header = (union record *)buf;
int i;

@ -294,7 +294,7 @@ int cli_ac_scanbuff(const char *buffer, unsigned int length, const char **virnam
else
t = ftype;
if((fd == -1 && !t) || !cli_validatesig(pt->target, t, pt->offset, offset + position, fd, pt->virname)) {
if((fd == -1 && !t) || !cli_validatesig(t, pt->offset, offset + position, fd, pt->virname)) {
pt = pt->next;
continue;
}

@ -190,7 +190,7 @@ int cli_bm_scanbuff(const char *buffer, unsigned int length, const char **virnam
if(p->target || p->offset) {
off = offset + i - BM_MIN_LENGTH + BM_BLOCK_SIZE;
if((fd == -1 && !ftype) || !cli_validatesig(p->target, ftype, p->offset, off, fd, p->virname)) {
if((fd == -1 && !ftype) || !cli_validatesig(ftype, p->offset, off, fd, p->virname)) {
p = p->next;
continue;
}

@ -395,7 +395,7 @@ static int cli_checkfp(int fd, const struct cl_engine *engine)
return 0;
}
int cli_validatesig(unsigned short target, unsigned short ftype, const char *offstr, unsigned long int fileoff, int desc, const char *virname)
int cli_validatesig(unsigned short ftype, const char *offstr, unsigned long int fileoff, int desc, const char *virname)
{
if(offstr && desc != -1) {

@ -30,6 +30,6 @@ int cli_scandesc(int desc, cli_ctx *ctx, unsigned short otfrec, unsigned short f
int cli_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cl_engine *engine, unsigned short ftype);
int cli_validatesig(unsigned short target, unsigned short ftype, const char *offstr, unsigned long int fileoff, int desc, const char *virname);
int cli_validatesig(unsigned short ftype, const char *offstr, unsigned long int fileoff, int desc, const char *virname);
#endif

@ -115,7 +115,7 @@ static struct mspack_file *msp_open(struct mspack_system *this,
default: return NULL;
}
if ((fh = malloc(sizeof(struct mspack_file_p)))) {
if ((fh = cli_malloc(sizeof(struct mspack_file_p)))) {
fh->name = filename;
fh->desc = 0;
if ((fh->fh = fopen(filename, fmode))) return (struct mspack_file *) fh;
@ -138,7 +138,7 @@ static struct mspack_file *msp_dopen(struct mspack_system *this,
default: return NULL;
}
if ((fh = malloc(sizeof(struct mspack_file_p)))) {
if ((fh = cli_malloc(sizeof(struct mspack_file_p)))) {
fh->name = "descriptor";
fh->desc = desc;
if ((fh->fh = fdopen(desc, fmode))) return (struct mspack_file *) fh;
@ -213,7 +213,7 @@ static void msp_msg(struct mspack_file *file, char *format, ...) {
static void *msp_alloc(struct mspack_system *this, size_t bytes) {
#ifdef DEBUG
/* make uninitialised data obvious */
char *buf = malloc(bytes + 8);
char *buf = cli_malloc(bytes + 8);
if (buf) memset(buf, 0xDC, bytes);
*((size_t *)buf) = bytes;
return &buf[8];

@ -1641,7 +1641,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
}
lseek(desc, 0, SEEK_SET);
if(read(desc, spinned, fsize) != fsize) {
if((size_t) read(desc, spinned, fsize) != fsize) {
cli_dbgmsg("PESpin: Can't read %d bytes\n", fsize);
free(spinned);
free(section_hdr);
@ -1707,7 +1707,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
}
lseek(desc, 0, SEEK_SET);
if(read(desc, spinned, fsize) != fsize) {
if((size_t) read(desc, spinned, fsize) != fsize) {
cli_dbgmsg("yC: Can't read %d bytes\n", fsize);
free(spinned);
free(section_hdr);

@ -124,9 +124,9 @@ static int cli_ac_addsig(struct cli_matcher *root, const char *virname, const ch
*start++ = 0;
new->alt++;
new->altn = (unsigned short int *) realloc(new->altn, new->alt * sizeof(unsigned short int));
new->altn = (unsigned short int *) cli_realloc(new->altn, new->alt * sizeof(unsigned short int));
new->altn[new->alt - 1] = 0;
new->altc = (char **) realloc(new->altc, new->alt * sizeof(char *));
new->altc = (char **) cli_realloc(new->altc, new->alt * sizeof(char *));
new->altc[new->alt - 1] = NULL;
for(i = 0; i < strlen(pt); i++)
@ -391,7 +391,7 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex
}
} else {
bm_new = (struct cli_bm_patt *) calloc(1, sizeof(struct cli_bm_patt));
bm_new = (struct cli_bm_patt *) cli_calloc(1, sizeof(struct cli_bm_patt));
if(!bm_new)
return CL_EMEM;
@ -802,7 +802,7 @@ static int cli_loadhdb(FILE *fd, struct cl_engine **engine, unsigned int *signo,
static int cli_loadmd(FILE *fd, struct cl_engine **engine, unsigned int *signo, int type, unsigned int options)
{
char buffer[FILEBUFF], *pt;
int line = 0, comments = 0, ret = 0;
int line = 0, comments = 0, ret = 0, crc32;
struct cli_meta_node *new;
@ -892,11 +892,12 @@ static int cli_loadmd(FILE *fd, struct cl_engine **engine, unsigned int *signo,
if(!strcmp(pt, "*")) {
new->crc32 = 0;
} else {
new->crc32 = cli_hex2num(pt);
if(new->crc32 == -1) {
crc32 = cli_hex2num(pt);
if(crc32 == -1) {
ret = CL_EMALFDB;
break;
}
new->crc32 = (unsigned int) crc32;
}
free(pt);
}
@ -1249,7 +1250,7 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat)
fname = cli_calloc(strlen(dirname) + strlen(dent->d_name) + 2, sizeof(char));
sprintf(fname, "%s/%s", dirname, dent->d_name);
#if defined(C_INTERIX) || defined(C_OS2)
dbstat->statdname[dbstat->no - 1] = (char *) calloc(strlen(dent->d_name) + 1, sizeof(char));
dbstat->statdname[dbstat->no - 1] = (char *) cli_calloc(strlen(dent->d_name) + 1, sizeof(char));
strcpy(dbstat->statdname[dbstat->no - 1], dent->d_name);
#endif
stat(fname, &dbstat->stattab[dbstat->no - 1]);

@ -330,16 +330,16 @@ static int cli_scanzip(int desc, cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_c
if(mdata->encrypted != encrypted)
continue;
if(mdata->crc32 && mdata->crc32 != (unsigned int) zdirent.d_crc32)
if(mdata->crc32 && mdata->crc32 != zdirent.d_crc32)
continue;
if(mdata->csize > 0 && mdata->csize != zdirent.d_csize)
if(mdata->csize > 0 && (uint32_t) mdata->csize != zdirent.d_csize)
continue;
if(mdata->size >= 0 && mdata->size != zdirent.st_size)
if(mdata->size >= 0 && (uint32_t) mdata->size != zdirent.st_size)
continue;
if(mdata->method >= 0 && mdata->method != (unsigned int) zdirent.d_compr)
if(mdata->method >= 0 && (uint16_t) mdata->method != zdirent.d_compr)
continue;
if(mdata->fileno && mdata->fileno != files)
@ -373,8 +373,8 @@ static int cli_scanzip(int desc, cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_c
continue;
}
if(zdirent.d_csize <= 0 || zdirent.st_size < 0) {
cli_dbgmsg("Zip: Malformed archive detected.\n");
if(!zdirent.d_csize) {
cli_dbgmsg("Zip: Malformed file (d_csize == 0 but st_size != 0)\n");
*ctx->virname = "Suspect.Zip";
ret = CL_VIRUS;
break;
@ -1313,8 +1313,8 @@ static int cli_scanjpeg(int desc, const char **virname)
static int cli_scancryptff(int desc, cli_ctx *ctx)
{
int ret = CL_CLEAN, i, ndesc;
unsigned int length;
int ret = CL_CLEAN, ndesc;
unsigned int length, i;
unsigned char *src = NULL, *dest = NULL;
char *tempfile;
struct stat sb;

@ -73,7 +73,7 @@ static char *langcodes[] = {
static char *sis_utf16_decode(const char *str, uint32_t length)
{
char *decoded;
int i, j;
uint32_t i, j;
if(!length || length % 2) {
@ -305,7 +305,7 @@ static int sis_extract_simple(int fd, char *mfile, uint32_t length, uint32_t off
return CL_EIO;
}
if(cli_writen(desc, buff, filelen) != filelen) {
if((uint32_t) cli_writen(desc, buff, filelen) != filelen) {
cli_errmsg("SIS: sis_extract_simple: Can't write %d bytes to %s\n", filelen, fname);
free(subdir);
free(fname);

@ -248,7 +248,7 @@ char *cli_strtok(const char *line, int fieldno, const char *delim)
if (i == j) {
return NULL;
}
buffer = malloc(j-i+1);
buffer = cli_malloc(j-i+1);
if(!buffer)
return NULL;
strncpy(buffer, line+i, j-i);

@ -241,7 +241,7 @@ static void *read_header(int fd, header_type hdr_type)
case MAIN_HEAD: {
main_header_t *main_hdr;
main_hdr = (main_header_t *) malloc(sizeof(main_header_t));
main_hdr = (main_header_t *) cli_malloc(sizeof(main_header_t));
if (!main_hdr) {
return NULL;
}
@ -257,7 +257,7 @@ static void *read_header(int fd, header_type hdr_type)
case FILE_HEAD: {
file_header_t *file_hdr;
file_hdr = (file_header_t *) malloc(sizeof(file_header_t));
file_hdr = (file_header_t *) cli_malloc(sizeof(file_header_t));
if (!file_hdr) {
return NULL;
}
@ -320,7 +320,7 @@ static file_header_t *read_block(int fd, header_type hdr_type)
cli_dbgmsg("Pack Size: %u\n", file_header->pack_size);
cli_dbgmsg("UnPack Version: 0x%.2x\n", file_header->unpack_ver);
cli_dbgmsg("Pack Method: 0x%.2x\n", file_header->method);
file_header->filename = (unsigned char *) malloc(file_header->name_size+1);
file_header->filename = (unsigned char *) cli_malloc(file_header->name_size+1);
if (!file_header->filename) {
free(file_header);
return NULL;
@ -884,7 +884,7 @@ static int add_vm_code(unpack_data_t *unpack_data, unsigned int first_byte,
cli_dbgmsg("ERROR: vm_codesize=0x%x\n", vm_codesize);
return FALSE;
}
vm_code = (unsigned char *) malloc(vm_codesize);
vm_code = (unsigned char *) cli_malloc(vm_codesize);
for (i=0 ; i < vm_codesize ; i++) {
vm_code[i] = rarvm_getbits(&rarvm_input) >> 8;
rarvm_addbits(&rarvm_input, 8);
@ -898,13 +898,13 @@ static int add_vm_code(unpack_data_t *unpack_data, unsigned int first_byte,
static_size = filter->prg.static_size;
if (static_size > 0 && static_size < VM_GLOBALMEMSIZE) {
stack_filter->prg.static_data = malloc(static_size);
stack_filter->prg.static_data = cli_malloc(static_size);
memcpy(stack_filter->prg.static_data, filter->prg.static_data, static_size);
}
if (stack_filter->prg.global_size < VM_FIXEDGLOBALSIZE) {
free(stack_filter->prg.global_data);
stack_filter->prg.global_data = malloc(VM_FIXEDGLOBALSIZE);
stack_filter->prg.global_data = cli_malloc(VM_FIXEDGLOBALSIZE);
memset(stack_filter->prg.global_data, 0, VM_FIXEDGLOBALSIZE);
stack_filter->prg.global_size = VM_FIXEDGLOBALSIZE;
}
@ -958,7 +958,7 @@ static int read_vm_code(unpack_data_t *unpack_data, int fd)
length = getbits(unpack_data);
addbits(unpack_data, 16);
}
vmcode = (unsigned char *) malloc(length + 2);
vmcode = (unsigned char *) cli_malloc(length + 2);
rar_dbgmsg("VM code length: %d\n", length);
if (!vmcode) {
return FALSE;
@ -1004,7 +1004,7 @@ static int read_vm_code_PPM(unpack_data_t *unpack_data, int fd)
}
length = b1*256 + b2;
}
vmcode = (unsigned char *) malloc(length + 2);
vmcode = (unsigned char *) cli_malloc(length + 2);
rar_dbgmsg("VM PPM code length: %d\n", length);
if (!vmcode) {
return FALSE;
@ -1317,7 +1317,7 @@ rar_metadata_t *cli_unrar(int fd, const char *dirname, const struct cl_limits *l
if (!is_rar_archive(fd)) {
return FALSE;
}
unpack_data = malloc(sizeof(unpack_data_t));
unpack_data = cli_malloc(sizeof(unpack_data_t));
unpack_data->rarvm_data.mem = NULL;
unpack_data->old_filter_lengths = NULL;
unpack_data->PrgStack.array = unpack_data->Filters.array = NULL;
@ -1373,7 +1373,7 @@ rar_metadata_t *cli_unrar(int fd, const char *dirname, const struct cl_limits *l
if (!file_header) {
break;
}
new_metadata = malloc(sizeof(rar_metadata_t));
new_metadata = cli_malloc(sizeof(rar_metadata_t));
if (!new_metadata) {
break;
}

@ -49,7 +49,7 @@ typedef struct rar_metadata_tag
uint32_t pack_size;
uint32_t unpack_size;
uint32_t crc;
int encrypted;
unsigned int encrypted;
uint8_t method;
unsigned char *filename;
struct rar_metadata_tag *next;

@ -66,7 +66,7 @@ struct UnpackFilter *rar_filter_new(void)
{
struct UnpackFilter *filter;
filter = (struct UnpackFilter *) malloc(sizeof(struct UnpackFilter));
filter = (struct UnpackFilter *) cli_malloc(sizeof(struct UnpackFilter));
if (!filter) {
return NULL;
}

@ -111,7 +111,7 @@ static int sub_allocator_start_sub_allocator(sub_allocator_t *sub_alloc, int sa_
}
sub_allocator_stop_sub_allocator(sub_alloc);
alloc_size = t/FIXED_UNIT_SIZE*UNIT_SIZE+UNIT_SIZE;
if ((sub_alloc->heap_start = (uint8_t *) malloc(alloc_size)) == NULL) {
if ((sub_alloc->heap_start = (uint8_t *) cli_malloc(alloc_size)) == NULL) {
cli_dbgmsg("sub_alloc start failed\n");
return FALSE;
}

@ -195,7 +195,7 @@ uint32_t rar_crc(uint32_t start_crc, void *addr, uint32_t size)
int rarvm_init(rarvm_data_t *rarvm_data)
{
rarvm_data->mem = (uint8_t *) malloc(RARVM_MEMSIZE+4);
rarvm_data->mem = (uint8_t *) cli_malloc(RARVM_MEMSIZE+4);
init_crc();
if (!rarvm_data->mem) {
return FALSE;
@ -1066,7 +1066,7 @@ void rarvm_prepare(rarvm_data_t *rarvm_data, rarvm_input_t *rarvm_input, unsigne
if (data_flag & 0x8000) {
int data_size = rarvm_read_data(rarvm_input)+1;
rar_dbgmsg("data_size=%d\n", data_size);
prg->static_data = malloc(data_size);
prg->static_data = cli_malloc(data_size);
for (i=0 ; rarvm_input->in_addr < code_size && i < data_size ; i++) {
prg->static_size++;
prg->static_data = realloc(prg->static_data, prg->static_size);

@ -126,13 +126,13 @@ int __zip_find_disk_trailer(int fd, off_t filesize, struct zip_disk_trailer *tra
__fixup_rootseek(offset + tail - buf, trailer);
u_rootseek = EC32(trailer->z_rootseek);
if(u_rootseek > filesize) {
if(u_rootseek > (uint32_t) filesize) {
cli_dbgmsg("Unzip: __zip_find_disk_trailer: u_rootseek > filesize, continue search\n");
continue;
}
for(i = 0; i < 2; i++) {
if(u_rootseek + shift + sizeof(dirent) < filesize) {
if(u_rootseek + shift + sizeof(dirent) < (uint32_t) filesize) {
if(lseek(fd, u_rootseek + shift, SEEK_SET) < 0) {
cli_errmsg("Unzip: __zip_find_disk_trailer: Can't lseek descriptor %d\n", fd);
free(buf);
@ -169,7 +169,7 @@ int __zip_parse_root_directory(int fd, struct zip_disk_trailer *trailer, zip_dir
struct zip_root_dirent dirent, *d;
zip_dir_hdr *hdr, *hdr0;
uint16_t *p_reclen = NULL, entries;
off_t offset;
uint32_t offset;
struct stat sb;
uint16_t u_entries = EC16(trailer->z_entries);
uint32_t u_rootsize = EC32(trailer->z_rootsize);
@ -183,7 +183,7 @@ int __zip_parse_root_directory(int fd, struct zip_disk_trailer *trailer, zip_dir
return CL_EIO;
}
if(u_rootsize > sb.st_size) {
if(u_rootsize > (uint32_t) sb.st_size) {
cli_errmsg("Unzip: __zip_parse_root_directory: Incorrect root size\n");
return CL_EFORMAT;
}
@ -452,7 +452,7 @@ zip_file *zip_file_open(zip_dir *dir, const char *name, int d_off)
while(1) {
hdr_name = hdr->d_name;
if(!strcmp(hdr_name, name) && (d_off == -1 || d_off == hdr->d_off)) {
if(!strcmp(hdr_name, name) && (d_off == -1 || (uint32_t) d_off == hdr->d_off)) {
switch (hdr->d_compr) {
case ZIP_METHOD_STORED:
case ZIP_METHOD_DEFLATED:

@ -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);

Loading…
Cancel
Save