First draft of binhex.c

git-svn: trunk@1108
remotes/push_mirror/metadata
Nigel Horne 21 years ago
parent 0f5e1958c9
commit e72de3f1d8
  1. 12
      clamav-devel/libclamav/Makefile.in
  2. 135
      clamav-devel/libclamav/binhex.c
  3. 38
      clamav-devel/libclamav/mbox.c
  4. 90
      clamav-devel/libclamav/message.c

@ -1,4 +1,4 @@
# Makefile.in generated by automake 1.8.5 from Makefile.am.
# Makefile.in generated by automake 1.8.3 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@ -387,7 +387,7 @@ clean-libLTLIBRARIES:
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
test "$$dir" != "$$p" || dir=.; \
test "$$dir" = "$$p" && dir=.; \
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
@ -830,11 +830,9 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
test -z "$(ETAGS_ARGS)$$tags$$unique" \
|| $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)

@ -0,0 +1,135 @@
/*
* Copyright (C) 2004 Nigel Horne <njh@bandsman.co.uk>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Change History:
* $Log: binhex.c,v $
* Revision 1.2 2004/11/18 18:09:06 nigelhorne
* First draft of binhex.c
*
*/
static char const rcsid[] = "$Id: binhex.c,v 1.2 2004/11/18 18:09:06 nigelhorne Exp $";
#include "clamav.h"
#if HAVE_CONFIG_H
#include "clamav-config.h"
#endif
#ifndef CL_DEBUG
#define NDEBUG /* map CLAMAV debug onto standard */
#endif
#ifdef CL_THREAD_SAFE
#ifndef _REENTRANT
#define _REENTRANT /* for Solaris 2.8 */
#endif
#endif
#if HAVE_MMAP
#if HAVE_SYS_MMAN_H
#include <sys/mman.h>
#else /* HAVE_SYS_MMAN_H */
#undef HAVE_MMAP
#endif
#endif
#include <stdio.h>
#include <memory.h>
#include <sys/stat.h>
#include "line.h"
#include "mbox.h"
#include "table.h"
#include "blob.h"
#include "text.h"
#include "others.h"
int
cli_binhex(const char *dir, int desc)
{
struct stat statb;
char *buf, *start;
size_t size, bytesleft;
message *m;
fileblob *fb;
#ifndef HAVE_MMAP
cli_errmsg("Binhex decoding needs mmap() (for now)\n");
return CL_EMEM;
#else
if(fstat(desc, &statb) < 0)
return CL_EOPEN;
m = messageCreate();
if(m == NULL)
return CL_EMEM;
size = statb.st_size;
start = buf = mmap(NULL, size, PROT_READ, MAP_PRIVATE, desc, 0);
if (buf == MAP_FAILED)
return CL_EMEM;
cli_dbgmsg("mmap'ed binhex file\n");
bytesleft = size;
while(bytesleft) {
int length = 0;
char *ptr, *line;
for(ptr = buf; bytesleft && *ptr != '\r'; ptr++) {
length++;
--bytesleft;
}
printf("%d: ", length);
line = cli_malloc(length + 1);
memcpy(line, buf, length);
line[length] = '\0';
puts(line);
if(messageAddStr(m, line) < 0)
break;
free(line);
buf = ++ptr;
}
munmap(start, size);
if(m->binhex == NULL) {
messageDestroy(m);
cli_errmsg("No binhex line found\n");
return CL_EFORMAT;
}
messageSetEncoding(m, "x-binhex");
fb = messageToFileblob(m, dir);
if(fb) {
cli_dbgmsg("Binhex file decoded to %s\n", fileblobGetFilename(fb));
fileblobDestroy(fb);
} else
cli_errmsg("Couldn't decode binhex file to %s\n", fileblobGetFilename(fb));
messageDestroy(m);
if(fb)
return CL_CLEAN; /* a lie - but it gets things going */
return CL_EOPEN;
#endif
}

@ -17,6 +17,9 @@
*
* Change History:
* $Log: mbox.c,v $
* Revision 1.179 2004/11/18 18:09:07 nigelhorne
* First draft of binhex.c
*
* Revision 1.178 2004/11/15 13:58:50 nigelhorne
* Fix obscure chance of memory leak
*
@ -522,7 +525,7 @@
* Compilable under SCO; removed duplicate code with message.c
*
*/
static char const rcsid[] = "$Id: mbox.c,v 1.178 2004/11/15 13:58:50 nigelhorne Exp $";
static char const rcsid[] = "$Id: mbox.c,v 1.179 2004/11/18 18:09:07 nigelhorne Exp $";
#if HAVE_CONFIG_H
#include "clamav-config.h"
@ -2192,18 +2195,19 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t
} else if((encodingLine(mainMessage) != NULL) &&
((t_line = bounceBegin(mainMessage)) != NULL)) {
const text *t;
static const char encoding[] = "Content-Transfer-Encoding";
static const char type[] = "Content-Type:";
/*
* Attempt to save the original (unbounced)
* message - clamscan will find that in the
* directory and call us again (with any luck)
* having found an e-mail message to handle
* having found an e-mail message to handle.
*
* This finds a lot of false positives, the
* search that an encoding line is in the
* search that a content type is in the
* bounce (i.e. it's after the bounce header)
* helps a bit, but at the expense of scanning
* the entire message. messageAddLine
* helps a bit.
*
* messageAddLine
* optimisation could help here, but needs
* careful thought, do it with line numbers
* would be best, since the current method in
@ -2214,10 +2218,12 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t
for(t = t_line; t; t = t->t_next) {
const char *txt = lineGetData(t->t_line);
if(txt == NULL) {
t = NULL;
break;
}
if(txt &&
(strncasecmp(txt, encoding, sizeof(encoding) - 1) == 0) &&
(strstr(txt, "7bit") == NULL) &&
(strstr(txt, "8bit") == NULL))
(strncasecmp(txt, type, sizeof(type) - 1)))
break;
}
if(t && ((fb = fileblobCreate()) != NULL)) {
@ -3371,6 +3377,20 @@ getURL(struct arg *arg)
* quit. But the program seems to work OK without valgrind...
* Perhaps Curl_resolv() isn't thread safe?
*/
/*
* Curl 7.12.1 has a memory leak here :-(
* ==10634== at 0x1B904A90: malloc (vg_replace_malloc.c:131)
* ==10634== by 0x1BCA2AEF: strdup (in /lib/tls/libc-2.3.3.so)
* ==10634== by 0x1BCE7CDD: gaih_inet (in /lib/tls/libc-2.3.3.so)
* ==10634== by 0x1BCE96D0: getaddrinfo (in /lib/tls/libc-2.3.3.so)
* ==10634== by 0x1B9CCF23: Curl_getaddrinfo (in /usr/lib/libcurl.so.3.0.0)
* ==10634== by 0x1B9AC7C9: Curl_resolv (in /usr/lib/libcurl.so.3.0.0)
* ==10634== by 0x1B9BC1BD: Curl_connect (in /usr/lib/libcurl.so.3.0.0)
* ==10634== by 0x1B9C734C: (within /usr/lib/libcurl.so.3.0.0)
* ==10634== by 0x1B9C7573: Curl_perform (in /usr/lib/libcurl.so.3.0.0)
* ==10634== by 0x1B9C7CC1: curl_easy_perform (in /usr/lib/libcurl.so.3.0.0)
*/
if(curl_easy_perform(curl) != CURLE_OK) {
cli_warnmsg("URL %s failed to download\n", url);
unlink(fout);

@ -17,6 +17,9 @@
*
* Change History:
* $Log: message.c,v $
* Revision 1.118 2004/11/18 18:09:08 nigelhorne
* First draft of binhex.c
*
* Revision 1.117 2004/11/18 10:39:56 nigelhorne
* Added binhex filetype decoding
*
@ -348,7 +351,7 @@
* uuencodebegin() no longer static
*
*/
static char const rcsid[] = "$Id: message.c,v 1.117 2004/11/18 10:39:56 nigelhorne Exp $";
static char const rcsid[] = "$Id: message.c,v 1.118 2004/11/18 18:09:08 nigelhorne Exp $";
#if HAVE_CONFIG_H
#include "clamav-config.h"
@ -388,14 +391,6 @@ static char const rcsid[] = "$Id: message.c,v 1.117 2004/11/18 10:39:56 nigelhor
#include "str.h"
#include "filetypes.h"
#if HAVE_MMAP
#if HAVE_SYS_MMAN_H
#include <sys/mman.h>
#else /* HAVE_SYS_MMAN_H */
#undef HAVE_MMAP
#endif
#endif
/* required for AIX and Tru64 */
#ifdef TRUE
#undef TRUE
@ -2857,80 +2852,3 @@ pop(LINK1 *top, char *buffer)
}
return FAILURE;
}
int
cli_binhex(const char *dir, int desc)
{
struct stat statb;
char *buf, *start;
size_t size, bytesleft;
message *m;
fileblob *fb;
#ifndef HAVE_MMAP
cli_errmsg("Binhex decoding needs mmap() (for now)\n");
return CL_EMEM;
#else
if(fstat(desc, &statb) < 0)
return CL_EOPEN;
m = messageCreate();
if(m == NULL)
return CL_EMEM;
size = statb.st_size;
start = buf = mmap(NULL, size, PROT_READ, MAP_PRIVATE, desc, 0);
if (buf == MAP_FAILED)
return CL_EMEM;
cli_dbgmsg("mmap'ed binhex file\n");
bytesleft = size;
while(bytesleft) {
int length = 0;
char *ptr, *line;
for(ptr = buf; bytesleft && *ptr != '\r'; ptr++) {
length++;
--bytesleft;
}
printf("%d: ", length);
line = cli_malloc(length + 1);
memcpy(line, buf, length);
line[length] = '\0';
puts(line);
if(messageAddStr(m, line) < 0)
break;
free(line);
buf = ++ptr;
}
munmap(start, size);
if(m->binhex == NULL) {
messageDestroy(m);
cli_errmsg("No binhex line found\n");
return CL_EFORMAT;
}
messageSetEncoding(m, "x-binhex");
fb = messageToFileblob(m, dir);
if(fb) {
cli_dbgmsg("Binhex file decoded to %s\n", fileblobGetFilename(fb));
fileblobDestroy(fb);
} else
cli_errmsg("Couldn't decode binhex file to %s\n", fileblobGetFilename(fb));
messageDestroy(m);
if(fb)
return CL_CLEAN; /* a lie - but it gets things going */
return CL_EOPEN;
#endif
}

Loading…
Cancel
Save