[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:01:54 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit 747c2055e439ec83b533a6a26cbf5f5cdcf7776f
Author: aCaB <acab at clamav.net>
Date: Tue Aug 25 01:21:15 2009 +0200
port pdf and ole2_extract to fmap
diff --git a/libclamav/ole2_extract.c b/libclamav/ole2_extract.c
index 9766ac8..2addd4c 100644
--- a/libclamav/ole2_extract.c
+++ b/libclamav/ole2_extract.c
@@ -36,19 +36,11 @@
#include <stdlib.h>
#include "clamav.h"
-#if HAVE_MMAP
-#if HAVE_SYS_MMAN_H
-#include <sys/mman.h>
-#else /* HAVE_SYS_MMAN_H */
-#undef HAVE_MMAP
-#endif
-#endif
-
#include "cltypes.h"
#include "others.h"
#include "ole2_extract.h"
#include "scanners.h"
-#include "mbox.h"
+#include "fmap.h"
#define ole2_endian_convert_16(v) le16_to_host((uint16_t)(v))
#define ole2_endian_convert_32(v) le32_to_host((uint32_t)(v))
@@ -99,10 +91,10 @@ typedef struct ole2_header_tag
reading the header */
int32_t sbat_root_start __attribute__ ((packed));
uint32_t max_block_no;
- unsigned char *m_area;
off_t m_length;
bitset_t *bitset;
struct uniq *U;
+ struct F_MAP *map;
int has_vba;
} ole2_header_t;
@@ -297,7 +289,7 @@ static int ole2_read_block(int fd, ole2_header_t *hdr, void *buff, unsigned int
/* other methods: (blockno+1) * 512 or (blockno * block_size) + 512; */
offset = (blockno << hdr->log2_big_block_size) + MAX(512, 1 << hdr->log2_big_block_size); /* 512 is header size */
- if (hdr->m_area == NULL) {
+ if (hdr->map == NULL) {
if (lseek(fd, offset, SEEK_SET) != offset) {
return FALSE;
}
@@ -305,11 +297,15 @@ static int ole2_read_block(int fd, ole2_header_t *hdr, void *buff, unsigned int
return FALSE;
}
} else {
+ void *pblock;
offend = offset + size;
if ((offend <= 0) || (offend > hdr->m_length)) {
return FALSE;
}
- memcpy(buff, hdr->m_area+offset, size);
+ if(!(pblock = fmap_need_off_once(hdr->map, offset, size))) {
+ return FALSE;
+ }
+ memcpy(buff, pblock, size);
}
return TRUE;
}
@@ -905,28 +901,30 @@ int cli_ole2_extract(int fd, const char *dirname, cli_ctx *ctx, struct uniq **vb
/* size of header - size of other values in struct */
hdr_size = sizeof(struct ole2_header_tag) - sizeof(int32_t) - sizeof(uint32_t) -
- sizeof(unsigned char *) - sizeof(off_t) - sizeof(bitset_t *) -
- sizeof(struct uniq *) - sizeof(int);
+ sizeof(off_t) - sizeof(bitset_t *) -
+ sizeof(struct uniq *) - sizeof(int) - sizeof(struct F_MAP *);
- hdr.m_area = NULL;
+ hdr.map = NULL;
if (fstat(fd, &statbuf) == 0) {
if (statbuf.st_size < hdr_size) {
return CL_CLEAN;
}
-#ifdef HAVE_MMAP
hdr.m_length = statbuf.st_size;
- hdr.m_area = (unsigned char *) mmap(NULL, hdr.m_length, PROT_READ, MAP_PRIVATE, fd, 0);
- if (hdr.m_area == MAP_FAILED) {
- hdr.m_area = NULL;
- } else {
- cli_dbgmsg("mmap'ed file\n");
- memcpy(&hdr, hdr.m_area, hdr_size);
+ hdr.map = fmap(fd, 0, hdr.m_length);
+ if (hdr.map) {
+ void *phdr = fmap_need_off(hdr.map, 0, hdr_size);
+ if(phdr) {
+ cli_dbgmsg("mmap'ed file\n");
+ memcpy(&hdr, phdr, hdr_size);
+ } else {
+ fmunmap(hdr.map);
+ hdr.map = NULL;
+ }
}
-#endif
}
- if (hdr.m_area == NULL) {
+ if (hdr.map == NULL) {
hdr.bitset = NULL;
#if defined(HAVE_ATTRIB_PACKED) || defined(HAVE_PRAGMA_PACK) || defined(HAVE_PRAGMA_PACK_HPPA)
if (cli_readn(fd, &hdr, hdr_size) != hdr_size) {
@@ -1015,11 +1013,9 @@ int cli_ole2_extract(int fd, const char *dirname, cli_ctx *ctx, struct uniq **vb
}
abort:
-#ifdef HAVE_MMAP
- if (hdr.m_area != NULL) {
- munmap(hdr.m_area, hdr.m_length);
+ if (hdr.map != NULL) {
+ fmunmap(hdr.map);
}
-#endif
if(hdr.bitset)
cli_bitset_free(hdr.bitset);
diff --git a/libclamav/pdf.c b/libclamav/pdf.c
index 5fa7230..fc93cfe 100644
--- a/libclamav/pdf.c
+++ b/libclamav/pdf.c
@@ -26,7 +26,6 @@ static char const rcsid[] = "$Id: pdf.c,v 1.61 2007/02/12 20:46:09 njh Exp $";
#include "clamav-config.h"
#endif
-#ifdef HAVE_MMAP
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -41,11 +40,6 @@ static char const rcsid[] = "$Id: pdf.c,v 1.61 2007/02/12 20:46:09 njh Exp $";
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-
-#ifdef HAVE_SYS_MMAN_H
-#include <sys/mman.h>
-#endif
-
#include <zlib.h>
#ifdef C_WINDOWS
@@ -57,6 +51,7 @@ static char const rcsid[] = "$Id: pdf.c,v 1.61 2007/02/12 20:46:09 njh Exp $";
#include "mbox.h"
#include "pdf.h"
#include "scanners.h"
+#include "fmap.h"
#ifndef O_BINARY
#define O_BINARY 0
@@ -87,6 +82,7 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
int printed_predictor_message, printed_embedded_font_message, rc;
unsigned int files;
struct stat statb;
+ struct F_MAP *map;
cli_dbgmsg("in cli_pdf(%s)\n", dir);
@@ -100,8 +96,13 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
if(size <= 7) /* doesn't even include the file header */
return CL_CLEAN;
- p = buf = mmap(NULL, size, PROT_READ, MAP_PRIVATE, desc, offset);
- if(buf == MAP_FAILED) {
+ if(!(map = fmap(desc, offset, size))) {
+ cli_errmsg("cli_pdf: mmap() failed\n");
+ return CL_EMAP;
+ }
+
+ p = buf = fmap_need_off(map, 0, size); /* FIXME: really port to fmap */
+ if(!buf) {
cli_errmsg("cli_pdf: mmap() failed\n");
return CL_EMAP;
}
@@ -121,7 +122,7 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
}
if(!bytesleft) {
- munmap(buf, size);
+ fmunmap(map);
cli_dbgmsg("cli_pdf: file header not found\n");
return CL_CLEAN;
}
@@ -132,7 +133,7 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
break;
if(q <= p) {
- munmap(buf, size);
+ fmunmap(map);
cli_dbgmsg("cli_pdf: trailer not found\n");
return CL_CLEAN;
}
@@ -151,7 +152,7 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
* http://www.cs.cmu.edu/~dst/Adobe/Gallery/anon21jul01-pdf-encryption.txt
* http://www.adobe.com/devnet/pdf/
*/
- munmap(buf, size);
+ fmunmap(map);
cli_dbgmsg("cli_pdf: Encrypted PDF files not yet supported\n");
return CL_CLEAN;
}
@@ -174,7 +175,7 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
break;
if(xrefstart == p) {
- munmap(buf, size);
+ fmunmap(map);
cli_dbgmsg("cli_pdf: xref not found\n");
return CL_CLEAN;
}
@@ -545,7 +546,7 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
if(rc != CL_CLEAN) break;
}
- munmap(buf, size);
+ fmunmap(map);
tableDestroy(md5table);
@@ -881,16 +882,3 @@ cli_pmemstr(const char *haystack, size_t hs, const char *needle, size_t ns)
return NULL;
}
-#else /*!HAVE_MMAP*/
-
-#include "clamav.h"
-#include "others.h"
-#include "pdf.h"
-
-int
-cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
-{
- cli_dbgmsg("File not decoded - PDF decoding needs mmap() (for now)\n");
- return CL_CLEAN;
-}
-#endif
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list