From f304dc688ac6fbb4e6670c25f2567b9faa82dd18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B6r=C3=B6k=20Edvin?= Date: Thu, 5 Jan 2012 14:16:09 +0200 Subject: [PATCH] fmapify: fix const-ness warnings --- libclamav/autoit.c | 6 ++-- libclamav/binhex.c | 3 +- libclamav/bytecode_api.c | 10 +++--- libclamav/bytecode_api_decl.c | 4 +-- libclamav/bytecode_api_impl.h | 4 +-- libclamav/cab.c | 13 ++++---- libclamav/cache.c | 2 +- libclamav/chmunpack.c | 8 ++--- libclamav/chmunpack.h | 6 ++-- libclamav/filetypes.c | 5 +-- libclamav/fmap.h | 8 ++--- libclamav/fsg.c | 7 ++-- libclamav/fsg.h | 4 +-- libclamav/is_tar.c | 2 +- libclamav/is_tar.h | 2 +- libclamav/ishield.c | 13 +++++--- libclamav/iso9660.c | 10 +++--- libclamav/matcher.c | 6 ++-- libclamav/mbox.c | 5 +-- libclamav/mew.c | 38 ++++++++++++---------- libclamav/mew.h | 4 +-- libclamav/msexpand.c | 2 +- libclamav/nsis/nulsft.c | 8 ++--- libclamav/ole2_extract.c | 4 +-- libclamav/packlibs.c | 12 ++++--- libclamav/packlibs.h | 4 +-- libclamav/pe.c | 60 +++++++++++++++++++---------------- libclamav/pe_icons.c | 11 ++++--- libclamav/scanners.c | 11 ++++--- libclamav/unsp.c | 6 ++-- libclamav/unsp.h | 8 ++--- libclamav/unzip.c | 19 +++++------ libclamav/upx.c | 12 +++---- libclamav/upx.h | 8 ++--- 34 files changed, 174 insertions(+), 151 deletions(-) diff --git a/libclamav/autoit.c b/libclamav/autoit.c index 54fdde36b..8dd0328ab 100644 --- a/libclamav/autoit.c +++ b/libclamav/autoit.c @@ -176,7 +176,7 @@ static uint32_t getbits(struct UNP *UNP, uint32_t size) { *********************/ -static int ea05(cli_ctx *ctx, uint8_t *base, char *tmpd) { +static int ea05(cli_ctx *ctx, const uint8_t *base, char *tmpd) { uint8_t b[300], comp; uint32_t s, m4sum=0; int i, ret; @@ -480,7 +480,7 @@ static void LAME_decrypt (uint8_t *cypher, uint32_t size, uint16_t seed) { autoit3 EA06 handler *********************/ -static int ea06(cli_ctx *ctx, uint8_t *base, char *tmpd) { +static int ea06(cli_ctx *ctx, const uint8_t *base, char *tmpd) { uint8_t b[600], comp, script, *buf; uint32_t s; int i, ret; @@ -916,7 +916,7 @@ static int ea06(cli_ctx *ctx, uint8_t *base, char *tmpd) { *********************/ int cli_scanautoit(cli_ctx *ctx, off_t offset) { - uint8_t *version; + const uint8_t *version; int r; char *tmpd; fmap_t *map = *ctx->fmap; diff --git a/libclamav/binhex.c b/libclamav/binhex.c index dfa74b249..1d7e3915f 100644 --- a/libclamav/binhex.c +++ b/libclamav/binhex.c @@ -48,7 +48,8 @@ static const uint8_t hqxtbl[] = { int cli_binhex(cli_ctx *ctx) { fmap_t *map = *ctx->fmap; - uint8_t *encoded, decoded[BUFSIZ], spare_bits, last_byte=0, this_byte, offset=0; + const uint8_t *encoded; + uint8_t decoded[BUFSIZ], spare_bits, last_byte=0, this_byte, offset=0; size_t enc_done=0, enc_todo=map->len; unsigned int dec_done=0, chunksz = 0, chunkoff=0; uint32_t datalen, reslen; diff --git a/libclamav/bytecode_api.c b/libclamav/bytecode_api.c index 927a765d3..67f8ad537 100644 --- a/libclamav/bytecode_api.c +++ b/libclamav/bytecode_api.c @@ -534,7 +534,7 @@ int32_t cli_bcapi_extract_new(struct cli_bc_ctx *ctx, int32_t id) int32_t cli_bcapi_read_number(struct cli_bc_ctx *ctx, uint32_t radix) { unsigned i; - char *p; + const char *p; int32_t result; if ((radix != 10 && radix != 16) || !ctx->fmap) @@ -705,7 +705,7 @@ uint32_t cli_bcapi_buffer_pipe_read_avail(struct cli_bc_ctx *ctx , int32_t id) return ctx->file_size - b->read_cursor; } -uint8_t* cli_bcapi_buffer_pipe_read_get(struct cli_bc_ctx *ctx , int32_t id, uint32_t size) +const uint8_t* cli_bcapi_buffer_pipe_read_get(struct cli_bc_ctx *ctx , int32_t id, uint32_t size) { struct bc_buffer *b = get_buffer(ctx, id); if (!b || size > cli_bcapi_buffer_pipe_read_avail(ctx, id) || !size) @@ -843,7 +843,7 @@ int32_t cli_bcapi_inflate_process(struct cli_bc_ctx *ctx , int32_t id) b->stream.avail_in = avail_in_orig = cli_bcapi_buffer_pipe_read_avail(ctx, b->from); - b->stream.next_in = cli_bcapi_buffer_pipe_read_get(ctx, b->from, + b->stream.next_in = (void*)cli_bcapi_buffer_pipe_read_get(ctx, b->from, b->stream.avail_in); b->stream.avail_out = avail_out_orig = @@ -959,7 +959,7 @@ static struct bc_jsnorm *get_jsnorm(struct cli_bc_ctx *ctx, int32_t id) int32_t cli_bcapi_jsnorm_process(struct cli_bc_ctx *ctx, int32_t id) { unsigned avail; - unsigned char *in; + const unsigned char *in; cli_ctx *cctx = ctx->ctx; struct bc_jsnorm *b = get_jsnorm(ctx, id); if (!b || b->from == -1 || !b->state) @@ -1448,7 +1448,7 @@ uint32_t cli_bcapi_pdf_getobjsize(struct cli_bc_ctx *ctx , int32_t objidx) return ctx->pdf_objs[objidx+1].start - ctx->pdf_objs[objidx].start - 4; } -uint8_t* cli_bcapi_pdf_getobj(struct cli_bc_ctx *ctx , int32_t objidx, uint32_t amount) +const uint8_t* cli_bcapi_pdf_getobj(struct cli_bc_ctx *ctx , int32_t objidx, uint32_t amount) { uint32_t size = cli_bcapi_pdf_getobjsize(ctx, objidx); if (amount > size) diff --git a/libclamav/bytecode_api_decl.c b/libclamav/bytecode_api_decl.c index c25bdeb04..6e26130b7 100644 --- a/libclamav/bytecode_api_decl.c +++ b/libclamav/bytecode_api_decl.c @@ -65,7 +65,7 @@ int32_t cli_bcapi_hashset_empty(struct cli_bc_ctx *ctx , int32_t); int32_t cli_bcapi_buffer_pipe_new(struct cli_bc_ctx *ctx , uint32_t); int32_t cli_bcapi_buffer_pipe_new_fromfile(struct cli_bc_ctx *ctx , uint32_t); uint32_t cli_bcapi_buffer_pipe_read_avail(struct cli_bc_ctx *ctx , int32_t); -uint8_t* cli_bcapi_buffer_pipe_read_get(struct cli_bc_ctx *ctx , int32_t, uint32_t); +const uint8_t* cli_bcapi_buffer_pipe_read_get(struct cli_bc_ctx *ctx , int32_t, uint32_t); int32_t cli_bcapi_buffer_pipe_read_stopped(struct cli_bc_ctx *ctx , int32_t, uint32_t); uint32_t cli_bcapi_buffer_pipe_write_avail(struct cli_bc_ctx *ctx , int32_t); uint8_t* cli_bcapi_buffer_pipe_write_get(struct cli_bc_ctx *ctx , int32_t, uint32_t); @@ -114,7 +114,7 @@ int32_t cli_bcapi_pdf_get_flags(struct cli_bc_ctx *ctx ); int32_t cli_bcapi_pdf_set_flags(struct cli_bc_ctx *ctx , int32_t); int32_t cli_bcapi_pdf_lookupobj(struct cli_bc_ctx *ctx , uint32_t); uint32_t cli_bcapi_pdf_getobjsize(struct cli_bc_ctx *ctx , int32_t); -uint8_t* cli_bcapi_pdf_getobj(struct cli_bc_ctx *ctx , int32_t, uint32_t); +const uint8_t* cli_bcapi_pdf_getobj(struct cli_bc_ctx *ctx , int32_t, uint32_t); int32_t cli_bcapi_pdf_getobjid(struct cli_bc_ctx *ctx , int32_t); int32_t cli_bcapi_pdf_getobjflags(struct cli_bc_ctx *ctx , int32_t); int32_t cli_bcapi_pdf_setobjflags(struct cli_bc_ctx *ctx , int32_t, int32_t); diff --git a/libclamav/bytecode_api_impl.h b/libclamav/bytecode_api_impl.h index 4c85abdcf..0b2cc8db1 100644 --- a/libclamav/bytecode_api_impl.h +++ b/libclamav/bytecode_api_impl.h @@ -63,7 +63,7 @@ int32_t cli_bcapi_hashset_empty(struct cli_bc_ctx *ctx , int32_t); int32_t cli_bcapi_buffer_pipe_new(struct cli_bc_ctx *ctx , uint32_t); int32_t cli_bcapi_buffer_pipe_new_fromfile(struct cli_bc_ctx *ctx , uint32_t); uint32_t cli_bcapi_buffer_pipe_read_avail(struct cli_bc_ctx *ctx , int32_t); -uint8_t* cli_bcapi_buffer_pipe_read_get(struct cli_bc_ctx *ctx , int32_t, uint32_t); +const uint8_t* cli_bcapi_buffer_pipe_read_get(struct cli_bc_ctx *ctx , int32_t, uint32_t); int32_t cli_bcapi_buffer_pipe_read_stopped(struct cli_bc_ctx *ctx , int32_t, uint32_t); uint32_t cli_bcapi_buffer_pipe_write_avail(struct cli_bc_ctx *ctx , int32_t); uint8_t* cli_bcapi_buffer_pipe_write_get(struct cli_bc_ctx *ctx , int32_t, uint32_t); @@ -112,7 +112,7 @@ int32_t cli_bcapi_pdf_get_flags(struct cli_bc_ctx *ctx ); int32_t cli_bcapi_pdf_set_flags(struct cli_bc_ctx *ctx , int32_t); int32_t cli_bcapi_pdf_lookupobj(struct cli_bc_ctx *ctx , uint32_t); uint32_t cli_bcapi_pdf_getobjsize(struct cli_bc_ctx *ctx , int32_t); -uint8_t* cli_bcapi_pdf_getobj(struct cli_bc_ctx *ctx , int32_t, uint32_t); +const uint8_t* cli_bcapi_pdf_getobj(struct cli_bc_ctx *ctx , int32_t, uint32_t); int32_t cli_bcapi_pdf_getobjid(struct cli_bc_ctx *ctx , int32_t); int32_t cli_bcapi_pdf_getobjflags(struct cli_bc_ctx *ctx , int32_t); int32_t cli_bcapi_pdf_setobjflags(struct cli_bc_ctx *ctx , int32_t, int32_t); diff --git a/libclamav/cab.c b/libclamav/cab.c index b392e5ee6..a9f0b2ad3 100644 --- a/libclamav/cab.c +++ b/libclamav/cab.c @@ -95,7 +95,8 @@ struct cab_block_hdr static char *cab_readstr(fmap_t *map, off_t *offset, int *ret) { int i; - char *str, *retstr; + const char *str; + char *retstr; if(!(str = fmap_need_offstr(map, *offset, 256))) { *ret = CL_EFORMAT; @@ -181,8 +182,8 @@ int cab_open(fmap_t *map, off_t offset, struct cab_archive *cab) unsigned int i, folders = 0; struct cab_file *file, *lfile = NULL; struct cab_folder *folder, *lfolder = NULL; - struct cab_hdr *hdr; - struct cab_hdr_opt *hdr_opt; + const struct cab_hdr *hdr; + const struct cab_hdr_opt *hdr_opt; uint16_t fidx; uint32_t coffFiles; char *pt; @@ -305,7 +306,7 @@ int cab_open(fmap_t *map, off_t offset, struct cab_archive *cab) /* folders */ for(i = 0; i < cab->nfolders; i++) { - struct cab_folder_hdr *folder_hdr; + const struct cab_folder_hdr *folder_hdr; if(!(folder_hdr = fmap_need_off_once(map, cur_offset, sizeof(*folder_hdr)))) { cli_dbgmsg("cab_open: Can't read header for folder %u\n", i); @@ -360,7 +361,7 @@ int cab_open(fmap_t *map, off_t offset, struct cab_archive *cab) cur_offset = coffFiles; } for(i = 0; i < cab->nfiles; i++) { - struct cab_file_hdr *file_hdr; + const struct cab_file_hdr *file_hdr; if(!(file_hdr = fmap_need_off_once(map, cur_offset, sizeof(*file_hdr)))) { cli_dbgmsg("cab_open: Can't read file %u header\n", i); @@ -449,7 +450,7 @@ int cab_open(fmap_t *map, off_t offset, struct cab_archive *cab) static int cab_read_block(struct cab_file *file) { - struct cab_block_hdr *block_hdr; + const struct cab_block_hdr *block_hdr; struct cab_state *state = file->cab->state; if(!(block_hdr = fmap_need_off_once(file->cab->map, file->cab->cur_offset, sizeof(*block_hdr)))) { diff --git a/libclamav/cache.c b/libclamav/cache.c index 3e947fca5..60e242d82 100644 --- a/libclamav/cache.c +++ b/libclamav/cache.c @@ -703,7 +703,7 @@ int cache_check(unsigned char *hash, cli_ctx *ctx) { cli_md5_init(&md5); while(todo) { - void *buf; + const void *buf; size_t readme = todo < FILEBUFF ? todo : FILEBUFF; if(!(buf = fmap_need_off_once(map, at, readme))) return CL_VIRUS; diff --git a/libclamav/chmunpack.c b/libclamav/chmunpack.c index 511276b8b..6b071d2e8 100644 --- a/libclamav/chmunpack.c +++ b/libclamav/chmunpack.c @@ -105,7 +105,7 @@ typedef struct lzx_content_tag { /* Read in a block of data from either the mmap area or the given fd */ static int chm_read_data(fmap_t *map, char *dest, off_t offset, off_t len) { - void *src = fmap_need_off_once(map, offset, len); + const void *src = fmap_need_off_once(map, offset, len); if(!src) return FALSE; memcpy(dest, src, len); return TRUE; @@ -233,10 +233,10 @@ static int itsp_read_header(chm_metadata_t *metadata, off_t offset) return TRUE; } -static uint64_t read_enc_int(char **start, char *end) +static uint64_t read_enc_int(const char **start, const char *end) { uint64_t retval=0; - char *current; + const char *current; current = *start; @@ -258,7 +258,7 @@ static uint64_t read_enc_int(char **start, char *end) /* Read control entries */ static int read_control_entries(chm_metadata_t *metadata) { - char *name; + const char *name; uint64_t name_len, section, offset, length; while (metadata->chunk_entries--) { diff --git a/libclamav/chmunpack.h b/libclamav/chmunpack.h index f0bffd592..7864386b9 100644 --- a/libclamav/chmunpack.h +++ b/libclamav/chmunpack.h @@ -108,9 +108,9 @@ typedef struct chm_metadata_tag { int ofd; uint32_t num_chunks; off_t chunk_offset; - char *chunk_data; - char *chunk_current; - char *chunk_end; + const char *chunk_data; + const char *chunk_current; + const char *chunk_end; fmap_t *map; uint16_t chunk_entries; } chm_metadata_t; diff --git a/libclamav/filetypes.c b/libclamav/filetypes.c index 019d1dd86..ebe157d29 100644 --- a/libclamav/filetypes.c +++ b/libclamav/filetypes.c @@ -155,11 +155,12 @@ cli_file_t cli_filetype(const unsigned char *buf, size_t buflen, const struct cl return cli_texttype(buf, buflen); } -int is_tar(unsigned char *buf, unsigned int nbytes); +int is_tar(const unsigned char *buf, unsigned int nbytes); cli_file_t cli_filetype2(fmap_t *map, const struct cl_engine *engine) { - unsigned char *buff, *decoded; + const unsigned char *buff; + unsigned char *decoded; int bread = MIN(map->len, MAGIC_BUFFER_SIZE), sret; cli_file_t ret = CL_TYPE_BINARY_DATA; struct cli_matcher *root; diff --git a/libclamav/fmap.h b/libclamav/fmap.h index ef72655be..373e3bfcc 100644 --- a/libclamav/fmap.h +++ b/libclamav/fmap.h @@ -103,12 +103,12 @@ static inline size_t fmap_ptr2off(const fmap_t *m, const void *ptr) :(const char*)ptr - (const char*)m - m->hdrsz; } -static inline const void *fmap_need_ptr(fmap_t *m, void *ptr, size_t len) +static inline const void *fmap_need_ptr(fmap_t *m, const void *ptr, size_t len) { return m->need(m, fmap_ptr2off(m, ptr), len, 1); } -static inline const void *fmap_need_ptr_once(fmap_t *m, void *ptr, size_t len) +static inline const void *fmap_need_ptr_once(fmap_t *m, const void *ptr, size_t len) { return m->need(m, fmap_ptr2off(m, ptr), len, 0); } @@ -118,7 +118,7 @@ static inline void fmap_unneed_off(fmap_t *m, size_t at, size_t len) m->unneed_off(m, at, len); } -static inline void fmap_unneed_ptr(fmap_t *m, void *ptr, size_t len) +static inline void fmap_unneed_ptr(fmap_t *m, const void *ptr, size_t len) { fmap_unneed_off(m, fmap_ptr2off(m, ptr), len); } @@ -140,7 +140,7 @@ static inline int fmap_readn(fmap_t *m, void *dst, size_t at, size_t len) return len; } -static inline const void *fmap_need_str(fmap_t *m, void *ptr, size_t len_hint) +static inline const void *fmap_need_str(fmap_t *m, const void *ptr, size_t len_hint) { return m->need_offstr(m, fmap_ptr2off(m, ptr), len_hint); } diff --git a/libclamav/fsg.c b/libclamav/fsg.c index 87735a9a9..eba0e46ae 100644 --- a/libclamav/fsg.c +++ b/libclamav/fsg.c @@ -46,7 +46,7 @@ #include "packlibs.h" #include "fsg.h" -int unfsg_200(char *source, char *dest, int ssize, int dsize, uint32_t rva, uint32_t base, uint32_t ep, int file) { +int unfsg_200(const char *source, char *dest, int ssize, int dsize, uint32_t rva, uint32_t base, uint32_t ep, int file) { struct cli_exe_section section; /* Yup, just one ;) */ if ( cli_unfsg(source, dest, ssize, dsize, NULL, NULL) ) return -1; @@ -64,8 +64,9 @@ int unfsg_200(char *source, char *dest, int ssize, int dsize, uint32_t rva, uint } -int unfsg_133(char *source, char *dest, int ssize, int dsize, struct cli_exe_section *sections, int sectcount, uint32_t base, uint32_t ep, int file) { - char *tsrc=source, *tdst=dest; +int unfsg_133(const char *source, char *dest, int ssize, int dsize, struct cli_exe_section *sections, int sectcount, uint32_t base, uint32_t ep, int file) { + const char *tsrc=source; + char *tdst=dest; int i, upd=1, offs=0, lastsz=dsize; for (i = 0 ; i <= sectcount ; i++) { diff --git a/libclamav/fsg.h b/libclamav/fsg.h index b64d40d42..fd9fd2682 100644 --- a/libclamav/fsg.h +++ b/libclamav/fsg.h @@ -24,8 +24,8 @@ #include "cltypes.h" #include "execs.h" -int unfsg_200(char *, char *, int, int, uint32_t, uint32_t, uint32_t, int); -int unfsg_133(char *, char *, int , int, struct cli_exe_section *, int, uint32_t, uint32_t, int); +int unfsg_200(const char *, char *, int, int, uint32_t, uint32_t, uint32_t, int); +int unfsg_133(const char *, char *, int , int, struct cli_exe_section *, int, uint32_t, uint32_t, int); #endif diff --git a/libclamav/is_tar.c b/libclamav/is_tar.c index d696a7053..56d52fef4 100644 --- a/libclamav/is_tar.c +++ b/libclamav/is_tar.c @@ -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, unsigned int nbytes) +int is_tar(const unsigned char *buf, unsigned int nbytes) { union record *header = (union record *)buf; int i; diff --git a/libclamav/is_tar.h b/libclamav/is_tar.h index 236362607..2a8f99f07 100644 --- a/libclamav/is_tar.h +++ b/libclamav/is_tar.h @@ -44,4 +44,4 @@ union record { /* The magic field is filled with this if uname and gname are valid. */ #define TMAGIC "ustar " /* 7 chars and a null */ -int is_tar(unsigned char *buf, unsigned int nbytes); +int is_tar(const unsigned char *buf, unsigned int nbytes); diff --git a/libclamav/ishield.c b/libclamav/ishield.c index ca4060f76..bf463fa27 100644 --- a/libclamav/ishield.c +++ b/libclamav/ishield.c @@ -193,7 +193,7 @@ static const uint8_t skey[] = { 0xec, 0xca, 0x79, 0xf8 }; /* ~0x13, ~0x35, ~0x86 /* Extracts the content of MSI based IS */ int cli_scanishield_msi(cli_ctx *ctx, off_t off) { - uint8_t *buf; + const uint8_t *buf; unsigned int fcount, scanned = 0; int ret; fmap_t *map = *ctx->fmap; @@ -337,7 +337,8 @@ static int is_extract_cab(cli_ctx *ctx, uint64_t off, uint64_t size, uint64_t cs /* Extract the content of older (non-MSI) IS */ int cli_scanishield(cli_ctx *ctx, off_t off, size_t sz) { - char *fname, *path, *version, *strsz, *eostr, *data; + const char *fname, *path, *version, *strsz, *data; + char *eostr; int ret = CL_CLEAN; long fsize; off_t coff = off; @@ -436,7 +437,8 @@ int cli_scanishield(cli_ctx *ctx, off_t off, size_t sz) { /* Utility func to scan a fd @ a given offset and size */ static int is_dump_and_scan(cli_ctx *ctx, off_t off, size_t fsize) { - char *fname, *buf; + char *fname; + const char *buf; int ofd, ret = CL_CLEAN; fmap_t *map = *ctx->fmap; @@ -486,7 +488,7 @@ static int is_parse_hdr(cli_ctx *ctx, struct IS_CABSTUFF *c) { char hash[33], *hdr; fmap_t *map = *ctx->fmap; - struct IS_HDR *h1; + const struct IS_HDR *h1; struct IS_OBJECTS *objs; /* struct IS_INSTTYPEHDR *typehdr; -- UNUSED */ @@ -675,7 +677,8 @@ static void md5str(uint8_t *sum) { #define IS_CABBUFSZ 65536 static int is_extract_cab(cli_ctx *ctx, uint64_t off, uint64_t size, uint64_t csize) { - uint8_t *inbuf, *outbuf; + const uint8_t *inbuf; + uint8_t *outbuf; char *tempfile; int ofd, ret = CL_CLEAN; z_stream z; diff --git a/libclamav/iso9660.c b/libclamav/iso9660.c index 0a5bc0b44..650ffbe51 100644 --- a/libclamav/iso9660.c +++ b/libclamav/iso9660.c @@ -37,7 +37,7 @@ typedef struct { } iso9660_t; -static void *needblock(const iso9660_t *iso, unsigned int block, int temp) { +static const void *needblock(const iso9660_t *iso, unsigned int block, int temp) { cli_ctx *ctx = iso->ctx; size_t loff; unsigned int blocks_per_sect = (2048 / iso->blocksz); @@ -59,7 +59,7 @@ static int iso_scan_file(const iso9660_t *iso, unsigned int block, unsigned int cli_dbgmsg("iso_scan_file: dumping to %s\n", tmpf); while(len) { - void *buf = needblock(iso, block, 1); + const void *buf = needblock(iso, block, 1); unsigned int todo = MIN(len, iso->blocksz); if(cli_writen(fd, buf, todo) != todo) { close(fd); @@ -88,7 +88,7 @@ static int iso_scan_file(const iso9660_t *iso, unsigned int block, unsigned int return ret; } -static char *iso_string(iso9660_t *iso, void *src, unsigned int len) { +static char *iso_string(iso9660_t *iso, const void *src, unsigned int len) { if(iso->joliet) { char *utf8; if(len > sizeof(iso->buf)) @@ -120,7 +120,7 @@ static int iso_parse_dir(iso9660_t *iso, unsigned int block, unsigned int len) { } for(; len && ret == CL_CLEAN; block++, len -= MIN(len, iso->blocksz)) { - uint8_t *dir, *dir_orig; + const uint8_t *dir, *dir_orig; unsigned int dirsz; if(iso->dir_blocks.count > 1024) { @@ -205,7 +205,7 @@ static int iso_parse_dir(iso9660_t *iso, unsigned int block, unsigned int len) { } int cli_scaniso(cli_ctx *ctx, size_t offset) { - uint8_t *privol, *next; + const uint8_t *privol, *next; iso9660_t iso; int i; diff --git a/libclamav/matcher.c b/libclamav/matcher.c index 1578b09bc..75db33d72 100644 --- a/libclamav/matcher.c +++ b/libclamav/matcher.c @@ -396,7 +396,7 @@ int cli_checkfp(unsigned char *digest, size_t size, cli_ctx *ctx) SHA1Context sha1; SHA256_CTX sha256; fmap_t *map; - char *ptr; + const char *ptr; uint8_t shash1[SHA1_HASH_SIZE*2+1]; uint8_t shash256[SHA256_HASH_SIZE*2+1]; int have_sha1, have_sha256; @@ -610,7 +610,7 @@ int cli_lsig_eval(cli_ctx *ctx, struct cli_matcher *root, struct cli_ac_data *ac int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli_matched_type **ftoffset, unsigned int acmode, struct cli_ac_result **acres, unsigned char *refhash) { - unsigned char *buff; + const unsigned char *buff; int ret = CL_CLEAN, type = CL_CLEAN, bytes, compute_hash[CLI_HASH_AVAIL_TYPES]; unsigned int i = 0, bm_offmode = 0; uint32_t maxpatlen, offset = 0; @@ -760,7 +760,7 @@ int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli } if(hdb) { - void *data = buff + maxpatlen * (offset!=0); + const void *data = buff + maxpatlen * (offset!=0); uint32_t data_len = bytes - maxpatlen * (offset!=0); if(compute_hash[CLI_HASH_MD5]) diff --git a/libclamav/mbox.c b/libclamav/mbox.c index 0fb7d7d01..6ac670368 100644 --- a/libclamav/mbox.c +++ b/libclamav/mbox.c @@ -656,7 +656,7 @@ parseEmailFile(fmap_t *map, size_t *at, const table_t *rfc821, const char *first bodyIsEmpty = TRUE; } else { char *ptr; - char *lookahead; + const char *lookahead; if(fullline == NULL) { char cmd[RFC2821LENGTH + 1], out[RFC2821LENGTH + 1]; @@ -3212,7 +3212,8 @@ usefulHeader(int commandNumber, const char *cmd) static char * getline_from_mbox(char *buffer, size_t buffer_len, fmap_t *map, size_t *at) { - char *src, *cursrc, *curbuf; + const char *src, *cursrc; + char *curbuf; size_t i; size_t input_len = MIN(map->len - *at, buffer_len + 1); src = cursrc = fmap_need_off_once(map, *at, input_len); diff --git a/libclamav/mew.c b/libclamav/mew.c index b029a797e..60cf7e290 100644 --- a/libclamav/mew.c +++ b/libclamav/mew.c @@ -64,7 +64,7 @@ /* northfox does this shitty way, * this should be done with just a bswap */ -static char *lzma_bswap_4861dc(struct lzmastate *p, char *old_edx) +static const char *lzma_bswap_4861dc(struct lzmastate *p, const char *old_edx) { /* dumb_dump_start * @@ -99,7 +99,7 @@ static char *lzma_bswap_4861dc(struct lzmastate *p, char *old_edx) return p->p0; } -static uint32_t lzma_486248 (struct lzmastate *p, char **old_ecx, char *src, uint32_t size) +static uint32_t lzma_486248 (struct lzmastate *p,const char **old_ecx, char *src, uint32_t size) { uint32_t loc_esi, loc_edi, loc_eax, loc_ecx, ret; if (!CLI_ISCONTAINED(src, size, *old_ecx, 4) || !CLI_ISCONTAINED(src, size, p->p0, 1)) @@ -152,11 +152,11 @@ static uint32_t lzma_486248 (struct lzmastate *p, char **old_ecx, char *src, uin } -static uint32_t lzma_48635C(uint8_t znaczek, char **old_ecx, struct lzmastate *p, uint32_t *retval, char *src, uint32_t size) +static uint32_t lzma_48635C(uint8_t znaczek, const char **old_ecx, struct lzmastate *p, uint32_t *retval, char *src, uint32_t size) { uint32_t loc_esi = (znaczek&0xff) >> 7, /* msb */ loc_ebx, ret; - char *loc_edi; + const char *loc_edi; znaczek <<= 1; ret = loc_esi << 9; loc_edi = *old_ecx; @@ -196,10 +196,10 @@ static uint32_t lzma_48635C(uint8_t znaczek, char **old_ecx, struct lzmastate *p return 0; } -static uint32_t lzma_4862e0 (struct lzmastate *p, char **old_ecx, uint32_t *old_edx, uint32_t *retval, char *src, uint32_t size) +static uint32_t lzma_4862e0 (struct lzmastate *p, const char **old_ecx, uint32_t *old_edx, uint32_t *retval, char *src, uint32_t size) { uint32_t loc_ebx, loc_esi, stack_ecx, ret; - char *loc_edi; + const char *loc_edi; loc_ebx = *old_edx; ret = 1; @@ -229,10 +229,10 @@ static uint32_t lzma_4862e0 (struct lzmastate *p, char **old_ecx, uint32_t *old_ } /* old_edx - write only */ -static uint32_t lzma_4863da (uint32_t var0, struct lzmastate *p, char **old_ecx, uint32_t *old_edx, uint32_t *retval, char *src, uint32_t size) +static uint32_t lzma_4863da (uint32_t var0, struct lzmastate *p, const char **old_ecx, uint32_t *old_edx, uint32_t *retval, char *src, uint32_t size) { uint32_t ret; - char *loc_esi = *old_ecx; + const char *loc_esi = *old_ecx; if ((ret = lzma_486248 (p, old_ecx, src, size)) == 0xffffffff) return -1; @@ -274,7 +274,7 @@ static uint32_t lzma_4863da (uint32_t var0, struct lzmastate *p, char **old_ecx static uint32_t lzma_486204 (struct lzmastate *p, uint32_t old_edx, uint32_t *retval, char *src, uint32_t size) { uint32_t loc_esi, loc_edi, loc_ebx, loc_eax; - char *loc_edx; + const char *loc_edx; loc_esi = p->p1; loc_edi = p->p2; loc_eax = 0; @@ -311,11 +311,11 @@ static uint32_t lzma_486204 (struct lzmastate *p, uint32_t old_edx, uint32_t *re return 0; } -static uint32_t lzma_48631a (struct lzmastate *p, char **old_ecx, uint32_t *old_edx, uint32_t *retval, char *src, uint32_t size) +static uint32_t lzma_48631a (struct lzmastate *p, const char **old_ecx, uint32_t *old_edx, uint32_t *retval, char *src, uint32_t size) { uint32_t copy1, copy2; uint32_t loc_esi, loc_edi, ret; - char *loc_ebx; + const char *loc_ebx; copy1 = *old_edx; loc_edi = 0; @@ -347,7 +347,7 @@ static uint32_t lzma_48631a (struct lzmastate *p, char **old_ecx, uint32_t *old_ } -int mew_lzma(char *orgsource, char *buf, uint32_t size_sum, uint32_t vma, uint32_t special) +int mew_lzma(char *orgsource, const char *buf, uint32_t size_sum, uint32_t vma, uint32_t special) { uint32_t var08, var0C, var10, var14, var20, var24, var28, var34; struct lzmastate var40; @@ -355,8 +355,12 @@ int mew_lzma(char *orgsource, char *buf, uint32_t size_sum, uint32_t vma, uint32 int i, mainloop; char var1, var30; - char *source = buf, *dest, *new_ebx, *new_ecx, *var0C_ecxcopy, *var2C; - char *pushed_esi = NULL, *pushed_ebx = NULL; + const char *source = buf; + char *dest, *new_ebx; + const char *new_ecx, *var0C_ecxcopy; + const char *var2C; + char *pushed_esi = NULL; + const char *pushed_ebx = NULL; uint32_t pushed_edx=0; uint32_t loc_esi, loc_edi; @@ -774,8 +778,10 @@ int unmew11(char *src, int off, int ssize, int dsize, uint32_t base, uint32_t va { uint32_t entry_point, newedi, loc_ds=dsize, loc_ss=ssize; char *source = src + dsize + off; - char *lesi = source + 12, *ledi; - char *f1, *f2; + const char *lesi = source + 12; + char *ledi; + const char *f1; + char *f2; int i; struct cli_exe_section *section = NULL; uint32_t vma = base + vadd, size_sum = ssize + dsize; diff --git a/libclamav/mew.h b/libclamav/mew.h index 7f86b38a8..51ae3d77e 100644 --- a/libclamav/mew.h +++ b/libclamav/mew.h @@ -28,11 +28,11 @@ #include "cltypes.h" struct lzmastate { - char *p0; + const char *p0; uint32_t p1, p2; }; -int mew_lzma(char *, char *, uint32_t, uint32_t, uint32_t); +int mew_lzma(char *, const char *, uint32_t, uint32_t, uint32_t); uint32_t lzma_upack_esi_00(struct lzmastate *, char *, char *, uint32_t); uint32_t lzma_upack_esi_50(struct lzmastate *, uint32_t, uint32_t, char **, char *, uint32_t *, char *, uint32_t); diff --git a/libclamav/msexpand.c b/libclamav/msexpand.c index ccb204999..3b7ef8f3c 100644 --- a/libclamav/msexpand.c +++ b/libclamav/msexpand.c @@ -94,7 +94,7 @@ struct msexp_hdr { int cli_msexpand(cli_ctx *ctx, int ofd) { - struct msexp_hdr *hdr; + const struct msexp_hdr *hdr; uint8_t i, mask, bits; unsigned char buff[B_SIZE], wbuff[RW_SIZE]; const unsigned char *rbuff; diff --git a/libclamav/nsis/nulsft.c b/libclamav/nsis/nulsft.c index b416f5381..2be03f679 100644 --- a/libclamav/nsis/nulsft.c +++ b/libclamav/nsis/nulsft.c @@ -70,7 +70,7 @@ struct nsis_st { struct CLI_LZMA lz; /* z_stream z; */ nsis_z_stream z; - unsigned char *freeme; + const unsigned char *freeme; fmap_t *map; char ofn[1024]; }; @@ -183,7 +183,7 @@ static int nsis_decomp(struct nsis_st *n) { } static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) { - unsigned char *ibuf; + const unsigned char *ibuf; uint32_t size, loops; int ret, gotsome=0; unsigned char obuf[BUFSIZ]; @@ -258,7 +258,7 @@ static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) { } n->nsis.avail_in = size; - n->nsis.next_in = ibuf; + n->nsis.next_in = (void*)ibuf; n->nsis.next_out = obuf; n->nsis.avail_out = BUFSIZ; loops=0; @@ -325,7 +325,7 @@ static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) { close(n->ofd); return CL_EREAD; } - n->nsis.next_in = n->freeme; + n->nsis.next_in = (void*)n->freeme; n->nsis.avail_in = n->asz; } diff --git a/libclamav/ole2_extract.c b/libclamav/ole2_extract.c index c60ac921d..b10c324f0 100644 --- a/libclamav/ole2_extract.c +++ b/libclamav/ole2_extract.c @@ -276,7 +276,7 @@ static void print_ole2_header(ole2_header_t *hdr) static int ole2_read_block(ole2_header_t *hdr, void *buff, unsigned int size, int32_t blockno) { off_t offset, offend; - void *pblock; + const void *pblock; if (blockno < 0) { return FALSE; @@ -872,7 +872,7 @@ int cli_ole2_extract(const char *dirname, cli_ctx *ctx, struct uniq **vba) int hdr_size, ret=CL_CLEAN; unsigned int file_count=0; unsigned long scansize, scansize2; - void *phdr; + const void *phdr; cli_dbgmsg("in cli_ole2_extract()\n"); diff --git a/libclamav/packlibs.c b/libclamav/packlibs.c index adfcbbb3f..f5aaa30e5 100644 --- a/libclamav/packlibs.c +++ b/libclamav/packlibs.c @@ -27,7 +27,7 @@ #include "pe.h" #include "packlibs.h" -static int doubledl(char **scur, uint8_t *mydlptr, char *buffer, uint32_t buffersize) +static int doubledl(const char **scur, uint8_t *mydlptr, const char *buffer, uint32_t buffersize) { unsigned char mydl = *mydlptr; unsigned char olddl = mydl; @@ -45,10 +45,11 @@ static int doubledl(char **scur, uint8_t *mydlptr, char *buffer, uint32_t buffer } -int cli_unfsg(char *source, char *dest, int ssize, int dsize, char **endsrc, char **enddst) { +int cli_unfsg(const char *source, char *dest, int ssize, int dsize, const char **endsrc, char **enddst) { uint8_t mydl=0x80; uint32_t backbytes, backsize, oldback = 0; - char *csrc = source, *cdst = dest; + const char *csrc = source; + char *cdst = dest; int oob, lostbit = 1; if (ssize<=0 || dsize<=0) return -1; @@ -170,10 +171,11 @@ int cli_unfsg(char *source, char *dest, int ssize, int dsize, char **endsrc, cha return 0; } -int unmew(char *source, char *dest, int ssize, int dsize, char **endsrc, char **enddst) { +int unmew(const char *source, char *dest, int ssize, int dsize, const char **endsrc, char **enddst) { uint8_t mydl=0x80; uint32_t myeax_backbytes, myecx_backsize, oldback = 0; - char *csrc = source, *cdst = dest; + const char *csrc = source; + char *cdst = dest; int oob, lostbit = 1; *cdst++=*csrc++; diff --git a/libclamav/packlibs.h b/libclamav/packlibs.h index 9ed1b4846..5962e4663 100644 --- a/libclamav/packlibs.h +++ b/libclamav/packlibs.h @@ -28,8 +28,8 @@ #include "cltypes.h" #include "rebuildpe.h" -int cli_unfsg(char *, char *, int, int, char **, char **); +int cli_unfsg(const char *, char *, int, int, const char **, char **); -int unmew(char *, char *, int, int, char **, char **); +int unmew(const char *, char *, int, int, const char **, char **); #endif diff --git a/libclamav/pe.c b/libclamav/pe.c index 9cd9dec8b..2f5eea027 100644 --- a/libclamav/pe.c +++ b/libclamav/pe.c @@ -325,7 +325,7 @@ static int cli_ddump(int desc, int offset, int size, const char *file) { void findres(uint32_t by_type, uint32_t by_name, uint32_t res_rva, fmap_t *map, struct cli_exe_section *exe_sections, uint16_t nsections, uint32_t hdr_size, int (*cb)(void *, uint32_t, uint32_t, uint32_t, uint32_t), void *opaque) { unsigned int err = 0; uint32_t type, type_offs, name, name_offs, lang, lang_offs; - uint8_t *resdir, *type_entry, *name_entry, *lang_entry ; + const uint8_t *resdir, *type_entry, *name_entry, *lang_entry ; uint16_t type_cnt, name_cnt, lang_cnt; if (!(resdir = fmap_need_off_once(map, cli_rawaddr(res_rva, exe_sections, nsections, &err, map->len, hdr_size), 16)) || err) @@ -389,7 +389,7 @@ void findres(uint32_t by_type, uint32_t by_name, uint32_t res_rva, fmap_t *map, } static unsigned int cli_md5sect(fmap_t *map, struct cli_exe_section *s, unsigned char *digest) { - void *hashme; + const void *hashme; cli_md5_ctx md5; if (s->rsz > CLI_MAX_ALLOCATION) { @@ -411,8 +411,8 @@ static unsigned int cli_md5sect(fmap_t *map, struct cli_exe_section *s, unsigned static void cli_parseres_special(uint32_t base, uint32_t rva, fmap_t *map, struct cli_exe_section *exe_sections, uint16_t nsections, size_t fsize, uint32_t hdr_size, unsigned int level, uint32_t type, unsigned int *maxres, struct swizz_stats *stats) { unsigned int err = 0, i; - uint8_t *resdir; - uint8_t *entry, *oentry; + const uint8_t *resdir; + const uint8_t *entry, *oentry; uint16_t named, unnamed; uint32_t rawaddr = cli_rawaddr(rva, exe_sections, nsections, &err, fsize, hdr_size); uint32_t entries; @@ -481,7 +481,7 @@ static void cli_parseres_special(uint32_t base, uint32_t rva, fmap_t *map, struc rawaddr = cli_rawaddr(base + offs, exe_sections, nsections, &err, fsize, hdr_size); if (!err && (resdir = fmap_need_off_once(map, rawaddr, 16))) { uint32_t isz = cli_readint32(resdir+4); - uint8_t *str; + const uint8_t *str; rawaddr = cli_rawaddr(cli_readint32(resdir), exe_sections, nsections, &err, fsize, hdr_size); if (err || !isz || isz >= fsize || rawaddr+isz >= fsize) { cli_dbgmsg("cli_parseres_special: invalid resource table entry: %lu + %lu\n", @@ -519,8 +519,9 @@ int cli_scanpe(cli_ctx *ctx) ssize_t bytes, at; unsigned int i, found, upx_success = 0, min = 0, max = 0, err, overlays = 0; unsigned int ssize = 0, dsize = 0, dll = 0, pe_plus = 0, corrupted_cur; - int (*upxfn)(char *, uint32_t, char *, uint32_t *, uint32_t, uint32_t, uint32_t) = NULL; - char *src = NULL, *dest = NULL; + int (*upxfn)(const char *, uint32_t, char *, uint32_t *, uint32_t, uint32_t, uint32_t) = NULL; + const char *src = NULL; + char *dest = NULL; int ndesc, ret = CL_CLEAN, upack = 0, native=0; size_t fsize; uint32_t valign, falign, hdr_size, j; @@ -1247,19 +1248,19 @@ int cli_scanpe(cli_ctx *ctx) if(vsize >= 0x612c && rsize >= 0x612c && ((vsize & 0xff) == 0xec)) { int bw = rsize < 0x7000 ? rsize : 0x7000; - char *tbuff; + const char *tbuff; if((tbuff = fmap_need_off_once(map, exe_sections[nsections - 1].raw + rsize - bw, 4096))) { if(cli_memstr(tbuff, 4091, "\xe8\x2c\x61\x00\x00", 5)) { *ctx->virname = dam ? "Heuristics.W32.Magistr.A.dam" : "Heuristics.W32.Magistr.A"; free(exe_sections); return CL_VIRUS; - } + } } } else if(rsize >= 0x7000 && vsize >= 0x7000 && ((vsize & 0xff) == 0xed)) { int bw = rsize < 0x8000 ? rsize : 0x8000; - char *tbuff; + const char *tbuff; if((tbuff = fmap_need_off_once(map, exe_sections[nsections - 1].raw + rsize - bw, 4096))) { if(cli_memstr(tbuff, 4091, "\xe8\x04\x72\x00\x00", 5)) { @@ -1274,7 +1275,7 @@ int cli_scanpe(cli_ctx *ctx) /* W32.Polipos.A */ while(polipos && !dll && 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 jump, jold, *jumps = NULL; - uint8_t *code; + const uint8_t *code; unsigned int xsjs = 0; if(exe_sections[0].rsz > CLI_MAX_ALLOCATION) break; @@ -1367,10 +1368,11 @@ int cli_scanpe(cli_ctx *ctx) /* MEW support */ if (found && (DCONF & PE_CONF_MEW) && epsize>=16 && epbuff[0]=='\xe9') { uint32_t fileoffset; - char *tbuff; + const char *tbuff; fileoffset = (vep + cli_readint32(epbuff + 1) + 5); while (fileoffset == 0x154 || fileoffset == 0x158) { + char *src; uint32_t offdiff, uselzma; cli_dbgmsg ("MEW: found MEW characteristics %08X + %08X + 5 = %08X\n", @@ -1543,7 +1545,8 @@ int cli_scanpe(cli_ctx *ctx) } - while(found && (DCONF & PE_CONF_FSG) && epbuff[0] == '\x87' && epbuff[1] == '\x25') { + while(found && (DCONF & PE_CONF_FSG) && epbuff[0] == '\x87' && epbuff[1] == '\x25') { + const char *dst; /* FSG v2.0 support - thanks to aCaB ! */ @@ -1572,28 +1575,28 @@ int cli_scanpe(cli_ctx *ctx) return CL_ESEEK; } - dest = src + newedx - exe_sections[i + 1].rva; - if(newedx < exe_sections[i + 1].rva || !CLI_ISCONTAINED(src, ssize, dest, 4)) { + dst = src + newedx - exe_sections[i + 1].rva; + if(newedx < exe_sections[i + 1].rva || !CLI_ISCONTAINED(src, ssize, dst, 4)) { cli_dbgmsg("FSG: New ESP out of bounds\n"); break; } - newedx = cli_readint32(dest) - EC32(optional_hdr32.ImageBase); + newedx = cli_readint32(dst) - EC32(optional_hdr32.ImageBase); if(!CLI_ISCONTAINED(exe_sections[i + 1].rva, exe_sections[i + 1].rsz, newedx, 4)) { cli_dbgmsg("FSG: New ESP (%x) is wrong\n", newedx); break; } - dest = src + newedx - exe_sections[i + 1].rva; - if(!CLI_ISCONTAINED(src, ssize, dest, 32)) { + dst = src + newedx - exe_sections[i + 1].rva; + if(!CLI_ISCONTAINED(src, ssize, dst, 32)) { cli_dbgmsg("FSG: New stack out of bounds\n"); break; } - newedi = cli_readint32(dest) - EC32(optional_hdr32.ImageBase); - newesi = cli_readint32(dest + 4) - EC32(optional_hdr32.ImageBase); - newebx = cli_readint32(dest + 16) - EC32(optional_hdr32.ImageBase); - newedx = cli_readint32(dest + 20); + newedi = cli_readint32(dst) - EC32(optional_hdr32.ImageBase); + newesi = cli_readint32(dst + 4) - EC32(optional_hdr32.ImageBase); + newebx = cli_readint32(dst + 16) - EC32(optional_hdr32.ImageBase); + newedx = cli_readint32(dst + 20); if(newedi != exe_sections[i].rva) { cli_dbgmsg("FSG: Bad destination buffer (edi is %x should be %x)\n", newedi, exe_sections[i].rva); @@ -1615,7 +1618,6 @@ int cli_scanpe(cli_ctx *ctx) if((dest = (char *) cli_calloc(dsize, sizeof(char))) == NULL) { free(exe_sections); - free(src); return CL_EMEM; } @@ -1630,7 +1632,7 @@ int cli_scanpe(cli_ctx *ctx) /* FSG support - v. 1.33 (thx trog for the many samples) */ int sectcnt = 0; - char *support; + const char *support; uint32_t newesi, newedi, oldep, gp, t; struct cli_exe_section *sections; @@ -1733,7 +1735,7 @@ int cli_scanpe(cli_ctx *ctx) int sectcnt = 0; uint32_t gp, t = cli_rawaddr(cli_readint32(epbuff+1) - EC32(optional_hdr32.ImageBase), NULL, 0 , &err, fsize, hdr_size); - char *support; + const char *support; uint32_t newesi = cli_readint32(epbuff+11) - EC32(optional_hdr32.ImageBase); uint32_t newedi = cli_readint32(epbuff+6) - EC32(optional_hdr32.ImageBase); uint32_t oldep = vep - exe_sections[i + 1].rva; @@ -2124,6 +2126,7 @@ int cli_scanpe(cli_ctx *ctx) memcmp(epbuff+0x68, "\xe8\x00\x00\x00\x00\x58\x2d\x6d\x00\x00\x00\x50\x60\x33\xc9\x50\x58\x50\x50", 19) == 0) { uint32_t head = exe_sections[nsections - 1].raw; uint8_t *packer; + char *src; ssize = 0; for(i=0 ; ; i++) { @@ -2178,6 +2181,7 @@ int cli_scanpe(cli_ctx *ctx) /* ASPACK support */ while((DCONF & PE_CONF_ASPACK) && ep+58+0x70e < fsize && !memcmp(epbuff,"\x60\xe8\x03\x00\x00\x00\xe9\xeb",8)) { + char *src; if(epsize<0x3bf || memcmp(epbuff+0x3b9, "\x68\x00\x00\x00\x00\xc3",6)) break; ssize = 0; @@ -2214,7 +2218,7 @@ int cli_scanpe(cli_ctx *ctx) uint32_t eprva = vep; uint32_t start_of_stuff, rep = ep; unsigned int nowinldr; - char *nbuff; + const char *nbuff; src=epbuff; if (*epbuff=='\xe9') { /* bitched headers */ @@ -2471,7 +2475,7 @@ int cli_peheader(fmap_t *map, struct cli_exe_info *peinfo) while(dirs[2].Size) { struct vinfo_list vlist; - uint8_t *vptr, *baseptr; + const uint8_t *vptr, *baseptr; uint32_t rva, res_sz; memset(&vlist, 0, sizeof(vlist)); @@ -2555,7 +2559,7 @@ int cli_peheader(fmap_t *map, struct cli_exe_info *peinfo) while(sfi_sz > 6) { /* enum all stringtables - RESUMABLE */ uint32_t st_sz = cli_readint32(vptr) & 0xffff; - uint8_t *next_vptr = vptr + st_sz; + const uint8_t *next_vptr = vptr + st_sz; uint32_t next_sfi_sz = sfi_sz - st_sz; if(st_sz > sfi_sz || st_sz <= 24) { diff --git a/libclamav/pe_icons.c b/libclamav/pe_icons.c index fb822392c..8fb21c34f 100644 --- a/libclamav/pe_icons.c +++ b/libclamav/pe_icons.c @@ -88,7 +88,7 @@ int cli_scanicon(icon_groupset *set, uint32_t resdir_rva, cli_ctx *ctx, struct c findres(14, 0xffffffff, resdir_rva, map, exe_sections, nsections, hdr_size, groupicon_cb, &gicons); for(curicon=0; curiconlen, hdr_size), 16); + const uint8_t *grp = fmap_need_off_once(map, cli_rawaddr(gicons.rvas[curicon], exe_sections, nsections, &err, map->len, hdr_size), 16); if(grp && !err) { uint32_t gsz = cli_readint32(grp + 4); if(gsz>6) { @@ -1192,9 +1192,10 @@ static int parseicon(icon_groupset *set, uint32_t rva, cli_ctx *ctx, struct cli_ unsigned int important; } bmphdr; struct icomtr metrics; - unsigned char *rawimage; + const unsigned char *rawimage; const char *tempd; - uint32_t *palette = NULL, *imagedata; + const uint32_t *palette = NULL; + uint32_t *imagedata; unsigned int scanlinesz, andlinesz; unsigned int width, height, depth, x, y; unsigned int err, scalemode = 2, enginesize; @@ -1210,12 +1211,12 @@ static int parseicon(icon_groupset *set, uint32_t rva, cli_ctx *ctx, struct cli_ icoff = cli_rawaddr(rva, exe_sections, nsections, &err, map->len, hdr_size); /* read the bitmap header */ - if(err || !(imagedata = fmap_need_off_once(map, icoff, 4))) { + if(err || !(rawimage = fmap_need_off_once(map, icoff, 4))) { cli_dbgmsg("parseicon: offset to icon is out of file\n"); return CL_SUCCESS; } - rva = cli_readint32(imagedata); + rva = cli_readint32(rawimage); icoff = cli_rawaddr(rva, exe_sections, nsections, &err, map->len, hdr_size); if(err || fmap_readn(map, &bmphdr, icoff, sizeof(bmphdr)) != sizeof(bmphdr)) { cli_dbgmsg("parseicon: bmp header is out of file\n"); diff --git a/libclamav/scanners.c b/libclamav/scanners.c index 4f614d8ae..3fbc52769 100644 --- a/libclamav/scanners.c +++ b/libclamav/scanners.c @@ -488,7 +488,7 @@ static int cli_scangzip(cli_ctx *ctx) while (at < map->len) { unsigned int bytes = MIN(map->len - at, map->pgsz); - if(!(z.next_in = fmap_need_off_once(map, at, bytes))) { + if(!(z.next_in = (void*)fmap_need_off_once(map, at, bytes))) { cli_dbgmsg("GZip: Can't read %u bytes @ %lu.\n", bytes, (long unsigned)at); inflateEnd(&z); close(fd); @@ -1050,7 +1050,7 @@ static int cli_scanhtml(cli_ctx *ctx) static int cli_scanscript(cli_ctx *ctx) { - unsigned char *buff; + const unsigned char *buff; unsigned char* normalized; struct text_norm_state state; char *tmpname = NULL; @@ -1147,7 +1147,8 @@ static int cli_scanscript(cli_ctx *ctx) static int cli_scanhtml_utf16(cli_ctx *ctx) { - char *tempname, *decoded, *buff; + char *tempname, *decoded; + const char *buff; int ret = CL_CLEAN, fd, bytes; size_t at = 0; fmap_t *map = *ctx->fmap; @@ -1640,7 +1641,7 @@ static int cli_scanembpe(cli_ctx *ctx, off_t offset) { int fd, bytes, ret = CL_CLEAN; unsigned long int size = 0, todo; - char *buff; + const char *buff; char *tmpname; fmap_t *map = *ctx->fmap; unsigned int corrupted_input; @@ -2261,7 +2262,7 @@ static int magic_scandesc(cli_ctx *ctx, cli_file_t type) break; } do { - char *b; + const char *b; len = 0; b = fmap_need_off_once_len(*ctx->fmap, pos, BUFSIZ, &len); diff --git a/libclamav/unsp.c b/libclamav/unsp.c index 1e0a535b8..69bd0248c 100644 --- a/libclamav/unsp.c +++ b/libclamav/unsp.c @@ -120,12 +120,12 @@ nsp1:00435A5A push 8000h /* real_unpack(start_of_stuff, dest, malloc, free); */ -uint32_t unspack(char *start_of_stuff, char *dest, cli_ctx *ctx, uint32_t rva, uint32_t base, uint32_t ep, int file) { +uint32_t unspack(const char *start_of_stuff, char *dest, cli_ctx *ctx, uint32_t rva, uint32_t base, uint32_t ep, int file) { uint8_t c = *start_of_stuff; uint32_t i,firstbyte,tre,allocsz,tablesz,dsize,ssize; uint16_t *table; char *dst = dest; - char *src = start_of_stuff+0xd; + const char *src = start_of_stuff+0xd; struct cli_exe_section section; if (c>=0xe1) return 1; @@ -170,7 +170,7 @@ uint32_t unspack(char *start_of_stuff, char *dest, cli_ctx *ctx, uint32_t rva, u } -uint32_t very_real_unpack(uint16_t *table, uint32_t tablesz, uint32_t tre, uint32_t allocsz, uint32_t firstbyte, char *src, uint32_t ssize, char *dst, uint32_t dsize) { +uint32_t very_real_unpack(uint16_t *table, uint32_t tablesz, uint32_t tre, uint32_t allocsz, uint32_t firstbyte, const char *src, uint32_t ssize, char *dst, uint32_t dsize) { struct UNSP read_struct; uint32_t i = (0x300<<((allocsz+tre)&0xff)) + 0x736; diff --git a/libclamav/unsp.h b/libclamav/unsp.h index fc8e8385d..59b432958 100644 --- a/libclamav/unsp.h +++ b/libclamav/unsp.h @@ -25,8 +25,8 @@ #include "others.h" struct UNSP { - char *src_curr; - char *src_end; + const char *src_curr; + const char *src_end; uint32_t bitmap; uint32_t oldval; int error; @@ -35,8 +35,8 @@ struct UNSP { char *table; }; -uint32_t unspack(char *, char *, cli_ctx *, uint32_t, uint32_t, uint32_t, int); -uint32_t very_real_unpack(uint16_t *, uint32_t, uint32_t, uint32_t, uint32_t, char *, uint32_t, char *, uint32_t); +uint32_t unspack(const char *, char *, cli_ctx *, uint32_t, uint32_t, uint32_t, int); +uint32_t very_real_unpack(uint16_t *, uint32_t, uint32_t, uint32_t, uint32_t,const char *, uint32_t, char *, uint32_t); uint32_t get_byte(struct UNSP *); int getbit_from_table(uint16_t *, struct UNSP *); uint32_t get_100_bits_from_tablesize(uint16_t *, struct UNSP *, uint32_t); diff --git a/libclamav/unzip.c b/libclamav/unzip.c index 0b3ce8437..caa752f91 100644 --- a/libclamav/unzip.c +++ b/libclamav/unzip.c @@ -56,7 +56,7 @@ static int wrap_inflateinit2(void *a, int b) { return inflateInit2(a, b); } -static int unz(uint8_t *src, uint32_t csize, uint32_t usize, uint16_t method, uint16_t flags, unsigned int *fu, cli_ctx *ctx, char *tmpd) { +static int unz(const uint8_t *src, uint32_t csize, uint32_t usize, uint16_t method, uint16_t flags, unsigned int *fu, cli_ctx *ctx, char *tmpd) { char name[1024], obuf[BUFSIZ]; char *tempfile = name; int of, ret=CL_CLEAN; @@ -134,7 +134,7 @@ static int unz(uint8_t *src, uint32_t csize, uint32_t usize, uint16_t method, ui memset(&strm, 0, sizeof(strm)); - *next_in = src; + *next_in = (void*) src; *next_out = obuf; *avail_in = csize; *avail_out = sizeof(obuf); @@ -216,7 +216,7 @@ static int unz(uint8_t *src, uint32_t csize, uint32_t usize, uint16_t method, ui case ALG_IMPLODE: { struct xplstate strm; - strm.next_in = src; + strm.next_in = (void*)src; strm.next_out = (uint8_t *)obuf; strm.avail_in = csize; strm.avail_out = sizeof(obuf); @@ -297,8 +297,8 @@ static int unz(uint8_t *src, uint32_t csize, uint32_t usize, uint16_t method, ui return ret; } -static unsigned int lhdr(fmap_t *map, uint32_t loff,uint32_t zsize, unsigned int *fu, unsigned int fc, uint8_t *ch, int *ret, cli_ctx *ctx, char *tmpd, int detect_encrypted) { - uint8_t *lh, *zip; +static unsigned int lhdr(fmap_t *map, uint32_t loff,uint32_t zsize, unsigned int *fu, unsigned int fc, const uint8_t *ch, int *ret, cli_ctx *ctx, char *tmpd, int detect_encrypted) { + const uint8_t *lh, *zip; char name[256]; uint32_t csize, usize; @@ -323,7 +323,7 @@ static unsigned int lhdr(fmap_t *map, uint32_t loff,uint32_t zsize, unsigned int } if(ctx->engine->cdb || cli_debug_flag) { uint32_t nsize = (LH_flen>=sizeof(name))?sizeof(name)-1:LH_flen; - char *src; + const char *src; if(nsize && (src = fmap_need_ptr_once(map, zip, nsize))) { memcpy(name, zip, nsize); name[nsize]='\0'; @@ -416,7 +416,7 @@ static unsigned int lhdr(fmap_t *map, uint32_t loff,uint32_t zsize, unsigned int static unsigned int chdr(fmap_t *map, uint32_t coff, uint32_t zsize, unsigned int *fu, unsigned int fc, int *ret, cli_ctx *ctx, char *tmpd) { char name[256]; int last = 0; - uint8_t *ch; + const uint8_t *ch; if(!(ch = fmap_need_off(map, coff, SIZEOF_CH)) || CH_magic != 0x02014b50) { if(ch) fmap_unneed_ptr(map, ch, SIZEOF_CH); @@ -433,7 +433,7 @@ static unsigned int chdr(fmap_t *map, uint32_t coff, uint32_t zsize, unsigned in } if(cli_debug_flag && !last) { unsigned int size = (CH_flen>=sizeof(name))?sizeof(name)-1:CH_flen; - char *src = fmap_need_off_once(map, coff, size); + const char *src = fmap_need_off_once(map, coff, size); if(src) { memcpy(name, src, size); name[size]='\0'; @@ -467,7 +467,8 @@ int cli_unzip(cli_ctx *ctx) { int ret=CL_CLEAN; uint32_t fsize, lhoff = 0, coff = 0; fmap_t *map = *ctx->fmap; - char *tmpd, *ptr; + char *tmpd; + const char *ptr; cli_dbgmsg("in cli_unzip\n"); fsize = (uint32_t)map->len; diff --git a/libclamav/upx.c b/libclamav/upx.c index 066ad7ca2..bfa0e2751 100644 --- a/libclamav/upx.c +++ b/libclamav/upx.c @@ -116,7 +116,7 @@ static char *checkpe(char *dst, uint32_t dsize, char *pehdr, uint32_t *valign, u /* PE from UPX */ -static int pefromupx (char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_t ep, uint32_t upx0, uint32_t upx1, uint32_t *magic, uint32_t dend) +static int pefromupx (const char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_t ep, uint32_t upx0, uint32_t upx1, uint32_t *magic, uint32_t dend) { char *imports, *sections=NULL, *pehdr=NULL, *newbuf; unsigned int sectcnt=0, upd=1; @@ -259,7 +259,7 @@ static int pefromupx (char *src, uint32_t ssize, char *dst, uint32_t *dsize, uin /* [doubleebx] */ -static int doubleebx(char *src, uint32_t *myebx, uint32_t *scur, uint32_t ssize) +static int doubleebx(const char *src, uint32_t *myebx, uint32_t *scur, uint32_t ssize) { uint32_t oldebx = *myebx; @@ -276,7 +276,7 @@ static int doubleebx(char *src, uint32_t *myebx, uint32_t *scur, uint32_t ssize) /* [inflate] */ -int upx_inflate2b(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_t upx0, uint32_t upx1, uint32_t ep) +int upx_inflate2b(const char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_t upx0, uint32_t upx1, uint32_t ep) { int32_t backbytes, unp_offset = -1; uint32_t backsize, myebx = 0, scur=0, dcur=0, i, magic[]={0x108,0x110,0xd5,0}; @@ -351,7 +351,7 @@ int upx_inflate2b(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_ return pefromupx (src, ssize, dst, dsize, ep, upx0, upx1, magic, dcur); } -int upx_inflate2d(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_t upx0, uint32_t upx1, uint32_t ep) +int upx_inflate2d(const char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_t upx0, uint32_t upx1, uint32_t ep) { int32_t backbytes, unp_offset = -1; uint32_t backsize, myebx = 0, scur=0, dcur=0, i, magic[]={0x11c,0x124,0}; @@ -433,7 +433,7 @@ int upx_inflate2d(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_ return pefromupx (src, ssize, dst, dsize, ep, upx0, upx1, magic, dcur); } -int upx_inflate2e(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_t upx0, uint32_t upx1, uint32_t ep) +int upx_inflate2e(const char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_t upx0, uint32_t upx1, uint32_t ep) { int32_t backbytes, unp_offset = -1; uint32_t backsize, myebx = 0, scur=0, dcur=0, i, magic[]={0x128,0x130,0}; @@ -522,7 +522,7 @@ int upx_inflate2e(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_ return pefromupx (src, ssize, dst, dsize, ep, upx0, upx1, magic, dcur); } -int upx_inflatelzma(char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_t upx0, uint32_t upx1, uint32_t ep) { +int upx_inflatelzma(const char *src, uint32_t ssize, char *dst, uint32_t *dsize, uint32_t upx0, uint32_t upx1, uint32_t ep) { struct CLI_LZMA l; uint32_t magic[]={0xb16,0xb1e,0}; unsigned char fake_lzmahdr[5]; diff --git a/libclamav/upx.h b/libclamav/upx.h index 88c9dceb7..e30148492 100644 --- a/libclamav/upx.h +++ b/libclamav/upx.h @@ -23,9 +23,9 @@ #include "cltypes.h" -int upx_inflate2b(char *, uint32_t, char *, uint32_t *, uint32_t, uint32_t, uint32_t); -int upx_inflate2d(char *, uint32_t, char *, uint32_t *, uint32_t, uint32_t, uint32_t); -int upx_inflate2e(char *, uint32_t, char *, uint32_t *, uint32_t, uint32_t, uint32_t); -int upx_inflatelzma(char *, uint32_t, char *, uint32_t *, uint32_t, uint32_t, uint32_t); +int upx_inflate2b(const char *, uint32_t, char *, uint32_t *, uint32_t, uint32_t, uint32_t); +int upx_inflate2d(const char *, uint32_t, char *, uint32_t *, uint32_t, uint32_t, uint32_t); +int upx_inflate2e(const char *, uint32_t, char *, uint32_t *, uint32_t, uint32_t, uint32_t); +int upx_inflatelzma(const char *, uint32_t, char *, uint32_t *, uint32_t, uint32_t, uint32_t); #endif