[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b
aCaB
acab at clamav.net
Sun Apr 4 01:19:42 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit 3ef137af1b1010e45e3fe3be53c82ffcb369e8cb
Author: aCaB <acab at clamav.net>
Date: Wed Feb 10 17:53:27 2010 +0100
fix fmap stuff in sigtool
diff --git a/sigtool/sigtool.c b/sigtool/sigtool.c
index 1f3ae16..f54397e 100644
--- a/sigtool/sigtool.c
+++ b/sigtool/sigtool.c
@@ -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);
diff --git a/sigtool/vba.c b/sigtool/vba.c
index 06cff44..2cccda4 100644
--- a/sigtool/vba.c
+++ b/sigtool/vba.c
@@ -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);
}
}
diff --git a/sigtool/vba.h b/sigtool/vba.h
index 074195f..96ce1de 100644
--- a/sigtool/vba.h
+++ b/sigtool/vba.h
@@ -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
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list