git-svn: trunk@896
remotes/push_mirror/metadata
Nigel Horne 21 years ago
parent 4210e5db17
commit 767f16ab23
  1. 4
      clamav-devel/ChangeLog
  2. 80
      clamav-devel/libclamav/blob.c
  3. 26
      clamav-devel/libclamav/mbox.c
  4. 15
      clamav-devel/libclamav/message.c
  5. 3
      clamav-devel/libclamav/table.c

@ -1,3 +1,7 @@
Sat Sep 18 16:02:32 BST 2004 (njh)
----------------------------------
* libclamav: Some minor code tidies
Sat Sep 18 16:26:53 CEST 2004 (tk)
----------------------------------
* docs: remove outdated docs

@ -16,6 +16,9 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: blob.c,v $
* Revision 1.22 2004/09/18 14:59:26 nigelhorne
* Code tidy
*
* Revision 1.21 2004/09/06 08:34:47 nigelhorne
* Randomise extracted file names from tar file
*
@ -65,7 +68,7 @@
* Change LOG to Log
*
*/
static char const rcsid[] = "$Id: blob.c,v 1.21 2004/09/06 08:34:47 nigelhorne Exp $";
static char const rcsid[] = "$Id: blob.c,v 1.22 2004/09/18 14:59:26 nigelhorne Exp $";
#if HAVE_CONFIG_H
#include "clamav-config.h"
@ -151,6 +154,8 @@ blobDestroy(blob *b)
void
blobArrayDestroy(blob *blobList[], int n)
{
assert(blobList != NULL);
while(--n >= 0) {
cli_dbgmsg("blobArrayDestroy: %d\n", n);
if(blobList[n]) {
@ -191,6 +196,10 @@ blobGetFilename(const blob *b)
void
blobAddData(blob *b, const unsigned char *data, size_t len)
{
#ifdef HAVE_GETPAGESIZE
const int pagesize = getpagesize();
#endif
assert(b != NULL);
assert(b->magic == BLOB);
assert(data != NULL);
@ -206,6 +215,32 @@ blobAddData(blob *b, const unsigned char *data, size_t len)
cli_warnmsg("Reopening closed blob\n");
b->isClosed = 0;
}
/*
* The payoff here is between reducing the number of calls to
* malloc/realloc and not overallocating memory. A lot of machines
* are more tight with memory than one may imagine which is why
* we don't just allocate a *huge* amount and be done with it. Closing
* the blob helps because that reclaims memory. If you know the maximum
* size of a blob before you start adding data, use blobGrow() that's
* the most optimum
*/
#ifdef HAVE_GETPAGESIZE
if(b->data == NULL) {
assert(b->len == 0);
assert(b->size == 0);
b->size = pagesize;
b->data = cli_malloc(pagesize);
} else if(b->size < b->len + len) {
unsigned char *p = cli_realloc(b->data, b->size + pagesize);
if(p == NULL)
return;
b->size += pagesize;
b->data = p;
}
#else
if(b->data == NULL) {
assert(b->len == 0);
assert(b->size == 0);
@ -221,6 +256,7 @@ blobAddData(blob *b, const unsigned char *data, size_t len)
b->size += len * 4;
b->data = p;
}
#endif
if(b->data) {
memcpy(&b->data[b->len], data, len);
@ -249,20 +285,32 @@ blobGetDataSize(const blob *b)
void
blobClose(blob *b)
{
assert(b != NULL);
assert(b->magic == BLOB);
assert(!(b->isClosed));
/*
* Nothing more is going to be added to this blob. If it'll save more
* than a trivial amount (say 64 bytes) of memory, shrink the allocation
*/
if((b->size - b->len) >= 64) {
unsigned char *ptr = cli_realloc(b->data, b->len);
if(ptr == NULL)
return;
cli_dbgmsg("blobClose: recovered %u bytes from %u\n",
b->size - b->len, b->size);
b->size = b->len;
b->data = ptr;
if(b->len == 0) { /* Not likely */
free(b->data);
b->data = NULL;
cli_dbgmsg("blobClose: recovered all %u bytes\n",
b->size);
b->size = 0;
} else {
unsigned char *ptr = cli_realloc(b->data, b->len);
if(ptr == NULL)
return;
cli_dbgmsg("blobClose: recovered %u bytes from %u\n",
b->size - b->len, b->size);
b->size = b->len;
b->data = ptr;
}
}
b->isClosed = 1;
}
@ -287,6 +335,9 @@ blobcmp(const blob *b1, const blob *b2)
if(s1 != s2)
return 1;
if((s1 == 0) && (s2 == 0))
return 0;
return memcmp(blobGetData(b1), blobGetData(b2), s1);
}
@ -345,6 +396,10 @@ fileblobDestroy(fileblob *fb)
if(fb->b.name) {
assert(fb->fp != NULL);
if(ftell(fb->fp) == 0L) {
cli_dbgmsg("fileblobDestroy: not saving empty file\n");
unlink(fb->b.name);
}
fclose(fb->fp);
free(fb->b.name);
@ -471,9 +526,8 @@ sanitiseName(char *name)
while(*name) {
#ifdef C_DARWIN
*name &= '\177';
#endif
#if defined(MSDOS) || defined(C_CYGWIN) || defined(WIN32)
if(strchr("/*?<>|\"+=,;: ", *name))
#elif defined(MSDOS) || defined(C_CYGWIN) || defined(WIN32)
if(strchr("/*?<>|\\\"+=,;: ", *name))
#else
if(*name == '/')
#endif

@ -17,6 +17,9 @@
*
* Change History:
* $Log: mbox.c,v $
* Revision 1.131 2004/09/18 14:59:25 nigelhorne
* Code tidy
*
* Revision 1.130 2004/09/17 10:56:29 nigelhorne
* Handle multiple content-type headers and use the most likely
*
@ -378,7 +381,7 @@
* Compilable under SCO; removed duplicate code with message.c
*
*/
static char const rcsid[] = "$Id: mbox.c,v 1.130 2004/09/17 10:56:29 nigelhorne Exp $";
static char const rcsid[] = "$Id: mbox.c,v 1.131 2004/09/18 14:59:25 nigelhorne Exp $";
#if HAVE_CONFIG_H
#include "clamav-config.h"
@ -1943,6 +1946,7 @@ initialiseTables(table_t **rfc821Table, table_t **subtypeTable)
for(tableinit = rfc821headers; tableinit->key; tableinit++)
if(tableInsert(*rfc821Table, tableinit->key, tableinit->value) < 0) {
tableDestroy(*rfc821Table);
*rfc821Table = NULL;
return -1;
}
@ -1953,6 +1957,8 @@ initialiseTables(table_t **rfc821Table, table_t **subtypeTable)
if(tableInsert(*subtypeTable, tableinit->key, tableinit->value) < 0) {
tableDestroy(*rfc821Table);
tableDestroy(*subtypeTable);
*rfc821Table = NULL;
*subtypeTable = NULL;
return -1;
}
@ -1986,7 +1992,13 @@ getTextPart(message *const messages[], size_t size)
/*
* strip -
* Remove the trailing spaces from a buffer
* Remove the trailing spaces from a buffer. Don't call this directly,
* always call strstrip() which is a wrapper to this routine to be used with
* NUL terminated strings. This code looks a bit strange because of it's
* heritage from code that worked on strings that weren't necessarily NUL
* terminated.
* TODO: rewrite for clamAV
*
* Returns it's new length (a la strlen)
*
* len must be int not size_t because of the >= 0 test, it is sizeof(buf)
@ -1999,12 +2011,11 @@ strip(char *buf, int len)
register size_t i;
if((buf == NULL) || (len <= 0))
return(0);
return 0;
i = strlen(buf);
if(len > (int)(i + 1))
return(i);
return i;
ptr = &buf[--len];
#if defined(UNIX) || defined(C_LINUX) || defined(C_DARWIN) /* watch - it may be in shared text area */
@ -2378,7 +2389,7 @@ rfc2047(const char *in)
}
messageAddStr(m, enctext);
free(enctext);
switch(tolower(encoding)) {
switch(encoding) {
case 'q':
messageSetEncoding(m, "quoted-printable");
break;
@ -2421,6 +2432,7 @@ checkURLs(message *m, const char *dir)
if(b == NULL)
return;
blobClose(b);
len = blobGetDataSize(b);
if(len == 0)
@ -2688,7 +2700,7 @@ print_trace(int use_syslog)
for(i = 0; i < size; i++)
if(use_syslog)
syslog(LOG_ERR, "bt[%d]: %s", i, strings[i]);
syslog(LOG_ERR, "bt[%d]: %s", (int)i, strings[i]);
else
cli_dbgmsg("%s\n", strings[i]);

@ -17,6 +17,9 @@
*
* Change History:
* $Log: message.c,v $
* Revision 1.86 2004/09/18 14:59:26 nigelhorne
* Code tidy
*
* Revision 1.85 2004/09/17 13:47:19 nigelhorne
* Handle yEnc attachments
*
@ -252,7 +255,7 @@
* uuencodebegin() no longer static
*
*/
static char const rcsid[] = "$Id: message.c,v 1.85 2004/09/17 13:47:19 nigelhorne Exp $";
static char const rcsid[] = "$Id: message.c,v 1.86 2004/09/18 14:59:26 nigelhorne Exp $";
#if HAVE_CONFIG_H
#include "clamav-config.h"
@ -362,6 +365,8 @@ messageCreate(void)
void
messageDestroy(message *m)
{
assert(m != NULL);
messageReset(m);
free(m);
@ -478,7 +483,9 @@ messageSetMimeType(message *mess, const char *type)
mime_type
messageGetMimeType(const message *m)
{
return(m->mimeType);
assert(m != NULL);
return m->mimeType;
}
void
@ -678,6 +685,10 @@ messageAddArguments(message *m, const char *s)
* closing quotes
*/
key = strdup(key);
if(key == NULL)
return;
ptr = strchr(key, '=');
if(ptr == NULL)
ptr = strchr(key, ':');

@ -72,6 +72,9 @@ tableInsert(table_t *table, const char *key, int value)
table->tableLast = table->tableLast->next =
(tableEntry *)cli_calloc(1, sizeof(tableEntry));
if(table->tableLast == NULL)
return -1;
table->tableLast->next = NULL;
table->tableLast->key = strdup(key);
table->tableLast->value = value;

Loading…
Cancel
Save