[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:02:56 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit 084d19aa8cf216d784b3e48bf4999967ae218c11
Author: aCaB <acab at clamav.net>
Date: Mon Aug 31 06:16:12 2009 +0200
(some) html to fmap
diff --git a/libclamav/htmlnorm.c b/libclamav/htmlnorm.c
index 79cfdb8..8da82cc 100644
--- a/libclamav/htmlnorm.c
+++ b/libclamav/htmlnorm.c
@@ -1710,28 +1710,15 @@ int html_normalise_mem(unsigned char *in_buff, off_t in_size, const char *dirnam
return cli_html_normalise(-1, &m_area, dirname, hrefs, dconf);
}
-int html_normalise_fd(int fd, const char *dirname, tag_arguments_t *hrefs,const struct cli_dconf* dconf)
+int html_normalise_map(struct F_MAP *map, const char *dirname, tag_arguments_t *hrefs,const struct cli_dconf* dconf)
{
int retval=FALSE;
m_area_t m_area;
- struct stat statbuf;
-
- if (fstat(fd, &statbuf) == 0) {
- m_area.length = statbuf.st_size;
- m_area.offset = 0;
- m_area.map = fmap(fd, m_area.offset, m_area.length);
- if (!m_area.map) {
- cli_dbgmsg("fmmap HTML failed\n");
- retval = cli_html_normalise(fd, NULL, dirname, hrefs, dconf);
- } else {
- cli_dbgmsg("fmap'ed HTML file\n");
- retval = cli_html_normalise(-1, &m_area, dirname, hrefs, dconf);
- fmunmap(m_area.map);
- }
- } else {
- cli_dbgmsg("fstat HTML failed\n");
- retval = cli_html_normalise(fd, NULL, dirname, hrefs, dconf);
- }
+
+ m_area.length = map->len;
+ m_area.offset = 0;
+ m_area.map = map;
+ retval = cli_html_normalise(-1, &m_area, dirname, hrefs, dconf);
return retval;
}
diff --git a/libclamav/htmlnorm.h b/libclamav/htmlnorm.h
index 2d52e93..1a8075c 100644
--- a/libclamav/htmlnorm.h
+++ b/libclamav/htmlnorm.h
@@ -38,7 +38,7 @@ typedef struct m_area_tag {
} m_area_t;
int html_normalise_mem(unsigned char *in_buff, off_t in_size, const char *dirname, tag_arguments_t *hrefs,const struct cli_dconf* dconf);
-int html_normalise_fd(int fd, const char *dirname, tag_arguments_t *hrefs, const struct cli_dconf* dconf);
+int html_normalise_map(struct F_MAP *map, const char *dirname, tag_arguments_t *hrefs, const struct cli_dconf* dconf);
void html_tag_arg_free(tag_arguments_t *tags);
int html_screnc_decode(int fd, const char *dirname);
void html_tag_arg_add(tag_arguments_t *tags, const char *tag, char *value);
diff --git a/libclamav/libclamav.map b/libclamav/libclamav.map
index 870c19e..6eba55b 100644
--- a/libclamav/libclamav.map
+++ b/libclamav/libclamav.map
@@ -62,7 +62,7 @@ CLAMAV_PRIVATE {
cli_str2hex;
cli_md5file;
cli_md5stream;
- html_normalise_fd;
+ html_normalise_map;
cli_utf16toascii;
cli_malloc;
@@ -155,6 +155,8 @@ CLAMAV_PRIVATE {
cli_bytecode_context_setparam_ptr;
cli_bytecode_context_getresult_int;
cli_bytecode_context_clear;
+ fmap;
+ fmunmap;
local:
*;
};
diff --git a/libclamav/matcher.c b/libclamav/matcher.c
index 88adafd..c1015a7 100644
--- a/libclamav/matcher.c
+++ b/libclamav/matcher.c
@@ -557,7 +557,7 @@ int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli
if(!ftonly && ctx->engine->md5_hdb)
cli_md5_init(&md5ctx);
- while(1) {
+ while(offset < map->len) {
bytes = map->len - offset > SCANBUFF ? SCANBUFF : map->len - offset;
if(!(buff = fmap_need_off_once(map, offset, bytes))) {
/* FIXME: FAIL HERE */
diff --git a/libclamav/pdf.c b/libclamav/pdf.c
index b4d6af1..cca98f9 100644
--- a/libclamav/pdf.c
+++ b/libclamav/pdf.c
@@ -91,7 +91,7 @@ cli_pdf(const char *dir, cli_ctx *ctx, off_t offset)
if(size <= 7) /* doesn't even include the file header */
return CL_CLEAN;
- p = buf = fmap_need_off(map, 0, size); /* FIXME: really port to fmap */
+ p = buf = fmap_need_off_once(map, 0, size); /* FIXME: really port to fmap */
if(!buf) {
cli_errmsg("cli_pdf: mmap() failed\n");
return CL_EMAP;
diff --git a/libclamav/scanners.c b/libclamav/scanners.c
index 1f8f97f..81f0b73 100644
--- a/libclamav/scanners.c
+++ b/libclamav/scanners.c
@@ -910,24 +910,19 @@ static int cli_vba_scandir(const char *dirname, cli_ctx *ctx, struct uniq *U)
return ret;
}
-static int cli_scanhtml(int desc, cli_ctx *ctx)
+static int cli_scanhtml(cli_ctx *ctx)
{
char *tempname, fullname[1024];
int ret=CL_CLEAN, fd;
- struct stat sb;
+ struct F_MAP *map = *ctx->fmap;
cli_dbgmsg("in cli_scanhtml()\n");
- if(fstat(desc, &sb) == -1) {
- cli_errmsg("cli_scanhtml: fstat() failed for descriptor %d\n", desc);
- return CL_ESTAT;
- }
-
/* Because HTML detection is FP-prone and html_normalise_fd() needs to
* mmap the file don't normalise files larger than 10 MB.
*/
- if(sb.st_size > 10485760) {
+ if(map->len > 10485760) {
cli_dbgmsg("cli_scanhtml: exiting (file larger than 10 MB)\n");
return CL_CLEAN;
}
@@ -943,7 +938,7 @@ static int cli_scanhtml(int desc, cli_ctx *ctx)
cli_dbgmsg("cli_scanhtml: using tempdir %s\n", tempname);
- html_normalise_fd(desc, tempname, NULL, ctx->dconf);
+ html_normalise_map(map, tempname, NULL, ctx->dconf);
snprintf(fullname, 1024, "%s/nocomment.html", tempname);
fd = open(fullname, O_RDONLY|O_BINARY);
if (fd >= 0) {
@@ -951,7 +946,7 @@ static int cli_scanhtml(int desc, cli_ctx *ctx)
close(fd);
}
- if(ret == CL_CLEAN && sb.st_size < 2097152) {
+ if(ret == CL_CLEAN && map->len < 2097152) {
/* limit to 2 MB, we're not interesting in scanning large files in notags form */
/* TODO: don't even create notags if file is over 2 MB */
snprintf(fullname, 1024, "%s/notags.html", tempname);
@@ -1084,11 +1079,12 @@ static int cli_scanscript(int desc, cli_ctx *ctx)
return ret;
}
-static int cli_scanhtml_utf16(int desc, cli_ctx *ctx)
+static int cli_scanhtml_utf16(cli_ctx *ctx)
{
- char *tempname, buff[512], *decoded;
+ char *tempname, *decoded, *buff;
int ret = CL_CLEAN, fd, bytes;
-
+ size_t at = 0;
+ struct F_MAP *map = *ctx->fmap;
cli_dbgmsg("in cli_scanhtml_utf16()\n");
@@ -1103,23 +1099,36 @@ static int cli_scanhtml_utf16(int desc, cli_ctx *ctx)
cli_dbgmsg("cli_scanhtml_utf16: using tempfile %s\n", tempname);
- while((bytes = read(desc, buff, sizeof(buff))) > 0) {
+ while(at < map->len) {
+ bytes = map->len - at > map->pgsz * 16 ? map->pgsz * 16 : map->len - at;
+ if(!(buff = fmap_need_off_once(map, at, bytes))) {
+ close(fd);
+ cli_unlink(tempname);
+ free(tempname);
+ return CL_EREAD;
+ }
decoded = cli_utf16toascii(buff, bytes);
if(decoded) {
if(write(fd, decoded, strlen(decoded)) == -1) {
cli_errmsg("cli_scanhtml_utf16: Can't write to file %s\n", tempname);
free(decoded);
+ close(fd);
cli_unlink(tempname);
free(tempname);
- close(fd);
return CL_EWRITE;
}
free(decoded);
}
}
- lseek(fd, 0, SEEK_SET);
- ret = cli_scanhtml(fd, ctx);
+ *ctx->fmap = fmap(fd, 0, 0);
+ if(*ctx->fmap) {
+ ret = cli_scanhtml(ctx);
+ fmunmap(*ctx->fmap);
+ } else
+ cli_errmsg("cli_scanhtml_utf16: fmap of %s failed\n", tempname);
+
+ *ctx->fmap = map;
close(fd);
if(!ctx->engine->keeptmp) {
@@ -1813,7 +1822,7 @@ static int cli_scanraw(cli_ctx *ctx, cli_file_t type, uint8_t typercg, cli_file_
case CL_TYPE_HTML:
if(SCAN_HTML && type == CL_TYPE_TEXT_ASCII && (DCONF_DOC & DOC_CONF_HTML)) {
*dettype = CL_TYPE_HTML;
- nret = cli_scanhtml(map->fd, ctx);
+ nret = cli_scanhtml(ctx);
}
break;
@@ -1966,12 +1975,12 @@ int cli_magic_scandesc(int desc, cli_ctx *ctx)
case CL_TYPE_HTML:
if(SCAN_HTML && (DCONF_DOC & DOC_CONF_HTML))
- ret = cli_scanhtml(desc, ctx);
+ ret = cli_scanhtml(ctx);
break;
case CL_TYPE_HTML_UTF16:
if(SCAN_HTML && (DCONF_DOC & DOC_CONF_HTML))
- ret = cli_scanhtml_utf16(desc, ctx);
+ ret = cli_scanhtml_utf16(ctx);
break;
case CL_TYPE_SCRIPT:
diff --git a/sigtool/sigtool.c b/sigtool/sigtool.c
index d2dd4e0..562caa9 100644
--- a/sigtool/sigtool.c
+++ b/sigtool/sigtool.c
@@ -61,6 +61,7 @@
#include "libclamav/ole2_extract.h"
#include "libclamav/htmlnorm.h"
#include "libclamav/default.h"
+#include "libclamav/fmap.h"
#define MAX_DEL_LOOKAHEAD 200
@@ -182,14 +183,19 @@ static int md5sig(const struct optstruct *opts, unsigned int mdb)
static int htmlnorm(const struct optstruct *opts)
{
int fd;
-
+ struct F_MAP *map;
if((fd = open(optget(opts, "html-normalise")->strarg, O_RDONLY)) == -1) {
mprintf("!htmlnorm: Can't open file %s\n", optget(opts, "html-normalise")->strarg);
return -1;
}
- html_normalise_fd(fd, ".", NULL, NULL);
+ if((map = fmap(fd, 0, 0))) {
+ html_normalise_map(map, ".", NULL, NULL);
+ fmunmap(map);
+ } else
+ mprintf("!fmap failed\n");
+
close(fd);
return 0;
diff --git a/unit_tests/check_htmlnorm.c b/unit_tests/check_htmlnorm.c
index 613998c..902f3f7 100644
--- a/unit_tests/check_htmlnorm.c
+++ b/unit_tests/check_htmlnorm.c
@@ -26,6 +26,7 @@
#include "../libclamav/dconf.h"
#include "../libclamav/htmlnorm.h"
#include "../libclamav/others.h"
+#include "../libclamav/fmap.h"
static char *dir;
@@ -105,34 +106,39 @@ START_TEST (test_htmlnorm_api)
{
int fd;
tag_arguments_t hrefs;
+ struct F_MAP *map;
memset(&hrefs, 0, sizeof(hrefs));
fd = open_testfile(tests[_i].input);
fail_unless(fd > 0,"open_testfile failed");
+ map = fmap(fd, 0, 0);
+ fail_unless(!!map, "fmap failed");
fail_unless(mkdir(dir, 0700) == 0,"mkdir failed");
- fail_unless(html_normalise_fd(fd, dir, NULL, dconf) == 1, "html_normalise_fd failed");
+ fail_unless(html_normalise_map(map, dir, NULL, dconf) == 1, "html_normalise_map failed");
check_dir(dir, &tests[_i]);
fail_unless(cli_rmdirs(dir) == 0, "rmdirs failed");
fail_unless(mkdir(dir, 0700) == 0,"mkdir failed");
- fail_unless(html_normalise_fd(fd, dir, NULL, NULL) == 1, "html_normalise_fd failed");
+ fail_unless(html_normalise_map(map, dir, NULL, NULL) == 1, "html_normalise_map failed");
fail_unless(cli_rmdirs(dir) == 0, "rmdirs failed");
fail_unless(mkdir(dir, 0700) == 0,"mkdir failed");
- fail_unless(html_normalise_fd(fd, dir, &hrefs, dconf) == 1, "html_normalise_fd failed");
+ fail_unless(html_normalise_map(map, dir, &hrefs, dconf) == 1, "html_normalise_map failed");
fail_unless(cli_rmdirs(dir) == 0, "rmdirs failed");
html_tag_arg_free(&hrefs);
memset(&hrefs, 0, sizeof(hrefs));
hrefs.scanContents = 1;
fail_unless(mkdir(dir, 0700) == 0,"mkdir failed");
- fail_unless(html_normalise_fd(fd, dir, &hrefs, dconf) == 1, "html_normalise_fd failed");
+ fail_unless(html_normalise_map(map, dir, &hrefs, dconf) == 1, "html_normalise_map failed");
fail_unless(cli_rmdirs(dir) == 0, "rmdirs failed");
html_tag_arg_free(&hrefs);
+ fmunmap(map);
+
close(fd);
}
END_TEST
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list