[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:00:55 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit ba65fdc81538e8cf11139cd2348528ff27deee1f
Author: aCaB <acab at clamav.net>
Date: Sat Aug 22 16:31:14 2009 +0200
port htmlnorm to fmap
diff --git a/libclamav/htmlnorm.c b/libclamav/htmlnorm.c
index 7646859..7ba6847 100644
--- a/libclamav/htmlnorm.c
+++ b/libclamav/htmlnorm.c
@@ -40,14 +40,7 @@
#include <stdio.h>
#include <ctype.h>
-#if HAVE_MMAP
-#if HAVE_SYS_MMAN_H
-#include <sys/mman.h>
-#else /* HAVE_SYS_MMAN_H */
-#undef HAVE_MMAP
-#endif
-#endif
-
+#include "fmap.h"
#include "others.h"
#include "htmlnorm.h"
@@ -185,15 +178,23 @@ static unsigned char *cli_readchunk(FILE *stream, m_area_t *m_area, unsigned int
/* Try and use the memory buffer first */
if (m_area) {
- start = ptr = m_area->buffer + m_area->offset;
- end = m_area->buffer + m_area->length;
+ /* maximum we can copy into the buffer,
+ * we could have less than max_len bytes available */
+ chunk_len = MIN(m_area->length-m_area->offset, max_len-1);
+ if(!chunk_len) {
+ free(chunk);
+ return NULL;
+ }
+ if(m_area->map)
+ ptr = (unsigned char *)fmap_need_off(m_area->map, m_area->offset, chunk_len); /* FIXME: make this need_once */
+ else
+ ptr = m_area->buffer + m_area->offset;
+ start = ptr;
+ end = ptr - m_area->offset + m_area->length;
if (start >= end) {
free(chunk);
return NULL;
}
- /* maximum we can copy into the buffer,
- * we could have less than max_len bytes available */
- chunk_len = MIN(end-start, max_len-1);
/* look for NULL chars */
ptr = memchr(start, 0, chunk_len);
@@ -218,14 +219,14 @@ static unsigned char *cli_readchunk(FILE *stream, m_area_t *m_area, unsigned int
* copy char-by-char and skip them */
while((ptr < end) && (chunk_len < max_len-1)) {
const unsigned char c = *ptr++;
+ /* we can't use chunk_len to determine how many bytes we read, since
+ * we skipped chars */
+ m_area->offset++;
if(c) {
chunk[chunk_len++] = c;
}
}
chunk[chunk_len] = '\0';
- /* we can't use chunk_len to determine how many bytes we read, since
- * we skipped chars */
- m_area->offset = ptr - m_area->buffer;
}
if(ptr && ptr < end && !isspace(*ptr)) {
/* we hit max_len, rewind to a space */
@@ -1702,37 +1703,34 @@ int html_normalise_mem(unsigned char *in_buff, off_t in_size, const char *dirnam
m_area.buffer = in_buff;
m_area.length = in_size;
m_area.offset = 0;
+ m_area.map = NULL;
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)
{
-#if HAVE_MMAP
int retval=FALSE;
m_area_t m_area;
struct stat statbuf;
if (fstat(fd, &statbuf) == 0) {
m_area.length = statbuf.st_size;
- m_area.buffer = (unsigned char *) mmap(NULL, m_area.length, PROT_READ, MAP_PRIVATE, fd, 0);
m_area.offset = 0;
- if (m_area.buffer == MAP_FAILED) {
- cli_dbgmsg("mmap HTML failed\n");
+ 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("mmap'ed file\n");
+ cli_dbgmsg("fmap'ed HTML file\n");
retval = cli_html_normalise(-1, &m_area, dirname, hrefs, dconf);
- munmap(m_area.buffer, m_area.length);
+ fmunmap(m_area.map);
}
} else {
cli_dbgmsg("fstat HTML failed\n");
retval = cli_html_normalise(fd, NULL, dirname, hrefs, dconf);
}
return retval;
-#else
- return cli_html_normalise(fd, NULL, dirname, hrefs, dconf);
-#endif
}
int html_screnc_decode(int fd, const char *dirname)
diff --git a/libclamav/htmlnorm.h b/libclamav/htmlnorm.h
index 1f56d26..2d52e93 100644
--- a/libclamav/htmlnorm.h
+++ b/libclamav/htmlnorm.h
@@ -34,6 +34,7 @@ typedef struct m_area_tag {
unsigned char *buffer;
off_t length;
off_t offset;
+ struct F_MAP *map;
} 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);
diff --git a/libclamav/ishield.c b/libclamav/ishield.c
index f8664fb..33dc3de 100644
--- a/libclamav/ishield.c
+++ b/libclamav/ishield.c
@@ -484,7 +484,8 @@ static int is_parse_hdr(int desc, cli_ctx *ctx, struct IS_CABSTUFF *c) {
uint32_t h1_data_off, objs_files_cnt, objs_dirs_off;
unsigned int off, i, scanned = 0;
int ret = CL_BREAK;
- char hash[33], *hdr, *map = NULL;
+ char hash[33], *hdr;
+ struct F_MAP *map = NULL;
size_t mp_hdrsz;
struct IS_HDR *h1;
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list