There were some variables initialized with values from dereferenced pointers,
and the null check after the init.
Also sizeof must be applied to pointed to element.
... | ... |
@@ -110,7 +110,7 @@ static int cli_bytecode_context_reset(struct cli_bc_ctx *ctx) |
110 | 110 |
int cli_bytecode_context_clear(struct cli_bc_ctx *ctx) |
111 | 111 |
{ |
112 | 112 |
cli_bytecode_context_reset(ctx); |
113 |
- memset(ctx, 0, sizeof(ctx)); |
|
113 |
+ memset(ctx, 0, sizeof(*ctx)); |
|
114 | 114 |
return CL_SUCCESS; |
115 | 115 |
} |
116 | 116 |
|
... | ... |
@@ -722,13 +722,16 @@ void cache_add(unsigned char *md5, size_t size, cli_ctx *ctx) { |
722 | 722 |
/* Hashes a file onto the provided buffer and looks it up the cache. |
723 | 723 |
Returns CL_VIRUS if found, CL_CLEAN if not FIXME or an error */ |
724 | 724 |
int cache_check(unsigned char *hash, cli_ctx *ctx) { |
725 |
- fmap_t *map = *ctx->fmap; |
|
726 |
- size_t todo = map->len, at = 0; |
|
725 |
+ fmap_t *map; |
|
726 |
+ size_t todo, at = 0; |
|
727 | 727 |
cli_md5_ctx md5; |
728 | 728 |
|
729 | 729 |
if(!ctx || !ctx->engine || !ctx->engine->cache) |
730 | 730 |
return CL_VIRUS; |
731 | 731 |
|
732 |
+ map = *ctx->fmap; |
|
733 |
+ todo = map->len; |
|
734 |
+ |
|
732 | 735 |
cli_md5_init(&md5); |
733 | 736 |
while(todo) { |
734 | 737 |
void *buf; |
... | ... |
@@ -1173,12 +1173,14 @@ static int parseicon(icon_groupset *set, uint32_t rva, cli_ctx *ctx, struct cli_ |
1173 | 1173 |
unsigned int scanlinesz, andlinesz; |
1174 | 1174 |
unsigned int width, height, depth, x, y; |
1175 | 1175 |
unsigned int err, scalemode = 2, enginesize; |
1176 |
- fmap_t *map = *ctx->fmap; |
|
1177 |
- uint32_t icoff = cli_rawaddr(rva, exe_sections, nsections, &err, map->len, hdr_size); |
|
1176 |
+ fmap_t *map; |
|
1177 |
+ uint32_t icoff; |
|
1178 | 1178 |
struct icon_matcher *matcher; |
1179 | 1179 |
|
1180 | 1180 |
if(!ctx || !ctx->engine || !(matcher=ctx->engine->iconcheck)) |
1181 | 1181 |
return CL_SUCCESS; |
1182 |
+ map = *ctx->fmap; |
|
1183 |
+ icoff = cli_rawaddr(rva, exe_sections, nsections, &err, map->len, hdr_size); |
|
1182 | 1184 |
|
1183 | 1185 |
/* read the bitmap header */ |
1184 | 1186 |
if(err || !(imagedata = fmap_need_off_once(map, icoff, 4))) { |