fix fmap stuff in sigtool

0.96
aCaB 16 years ago
parent 3e975a6042
commit 3ef137af1b
  1. 24
      sigtool/sigtool.c
  2. 43
      sigtool/vba.c
  3. 4
      sigtool/vba.h

@ -59,7 +59,6 @@
#include "libclamav/clamav.h"
#include "libclamav/matcher.h"
#include "libclamav/cvd.h"
#include "libclamav/others.h"
#include "libclamav/str.h"
#include "libclamav/ole2_extract.h"
#include "libclamav/htmlnorm.h"
@ -74,6 +73,7 @@
*/
#define COMPATIBILITY_LIMIT 980
static const struct dblist_s {
const char *name;
unsigned int count;
@ -1382,7 +1382,7 @@ static int vbadump(const struct optstruct *opts)
char *dir;
const char *pt;
struct uniq *vba = NULL;
cli_ctx ctx;
cli_ctx *ctx;
if(optget(opts, "vba-hex")->enabled) {
@ -1411,25 +1411,17 @@ static int vbadump(const struct optstruct *opts)
close(fd);
return -1;
}
ctx.fmap = cli_malloc(sizeof(struct F_MAP *));
if(!ctx.fmap) {
printf("malloc failed\n");
return 1;
}
*ctx.fmap = fmap(fd, 0, 0);
if(*ctx.fmap) {
printf("fmap failed\n");
return 1;
if(!(ctx = convenience_ctx(fd))) {
close(fd);
return -1;
}
if(cli_ole2_extract(dir, NULL, &vba)) {
if(cli_ole2_extract(dir, ctx, &vba)) {
destroy_ctx(ctx);
cli_rmdirs(dir);
free(dir);
close(fd);
return -1;
}
close(fd);
destroy_ctx(ctx);
if (vba)
sigtool_vba_scandir(dir, hex_output, vba);
cli_rmdirs(dir);

@ -33,7 +33,6 @@
#include "libclamav/clamav.h"
#include "libclamav/vba_extract.h"
#include "libclamav/others.h"
#include "libclamav/cltypes.h"
#include "libclamav/ole2_extract.h"
#include "shared/output.h"
@ -51,6 +50,26 @@ typedef struct mac_token2_tag
} mac_token2_t;
cli_ctx *convenience_ctx(int fd) {
cli_ctx *ctx;
if(!(ctx = malloc(sizeof(*ctx))) ||
!(ctx->engine = cl_engine_new()) ||
!(ctx->fmap = cli_malloc(sizeof(struct F_MAP *))) ||
!(*ctx->fmap = fmap(fd, 0, 0))) {
printf("malloc failed\n");
return NULL; /* and leak */
}
return ctx;
}
void destroy_ctx(cli_ctx *ctx) {
close((*(ctx->fmap))->fd);
funmap(*(ctx->fmap));
free(ctx->fmap);
cl_engine_free(ctx->engine);
free(ctx);
}
int sigtool_vba_scandir(const char *dirname, int hex_output, struct uniq *U);
static char *get_unicode_name (char *name, int size)
@ -967,7 +986,7 @@ static int sigtool_scandir (const char *dirname, int hex_output)
const char *tmpdir;
char *dir;
int ret = CL_CLEAN, desc;
cli_ctx ctx;
cli_ctx *ctx;
if ((dd = opendir (dirname)) != NULL) {
@ -1013,38 +1032,26 @@ static int sigtool_scandir (const char *dirname, int hex_output)
return 1;
}
ctx.fmap = cli_malloc(sizeof(struct F_MAP *));
if(!ctx.fmap) {
printf("malloc failed\n");
closedir (dd);
close(desc);
free(dir);
return 1;
}
*ctx.fmap = fmap(desc, 0, 0);
if(*ctx.fmap) {
printf("fmap failed\n");
closedir (dd);
if(!(ctx = convenience_ctx(desc))) {
close(desc);
closedir(dd);
free(dir);
return 1;
}
if ((ret = cli_ole2_extract (dir, &ctx, &vba))) {
printf ("ERROR %s\n", cl_strerror (ret));
destroy_ctx(ctx);
cli_rmdirs (dir);
free (dir);
closedir (dd);
close(desc);
return ret;
}
if(vba)
sigtool_vba_scandir (dir, hex_output, vba);
destroy_ctx(ctx);
cli_rmdirs (dir);
free (dir);
funmap(*ctx.fmap);
free(ctx.fmap);
close(desc);
}
}

@ -21,6 +21,10 @@
#define __VBA_H
#include "libclamav/uniq.h"
#include "libclamav/others.h"
int sigtool_vba_scandir(const char *dirname, int hex_output, struct uniq *U);
cli_ctx *convenience_ctx(int fd);
void destroy_ctx(cli_ctx *ctx);
#endif

Loading…
Cancel
Save