merge mempool branch

git-svn: trunk@4320
0.95
aCaB 17 years ago
commit 946bd26646
  1. 15
      ChangeLog
  2. 6652
      aclocal.m4
  3. 9
      clamav-config.h.in
  4. 318
      configure
  5. 17
      configure.in
  6. 6
      libclamav/Makefile.am
  7. 9
      libclamav/Makefile.in
  8. 5
      libclamav/clamav.h
  9. 9
      libclamav/dconf.c
  10. 9
      libclamav/dconf.h
  11. 11
      libclamav/filetypes.c
  12. 2
      libclamav/filetypes.h
  13. 154
      libclamav/matcher-ac.c
  14. 23
      libclamav/matcher-bm.c
  15. 8
      libclamav/matcher.h
  16. 525
      libclamav/mpool.c
  17. 46
      libclamav/mpool.h
  18. 3
      libclamav/phish_domaincheck_db.c
  19. 11
      libclamav/phish_whitelist.c
  20. 8
      libclamav/phishcheck.c
  21. 381
      libclamav/readdb.c
  22. 32
      libclamav/regex_list.c
  23. 5
      libclamav/regex_list.h
  24. 20
      m4/mmap_private.m4

@ -1,3 +1,18 @@
Sat Nov 1 03:51:58 CET 2008 (acab)
-----------------------------------
* mempool: New configure option --enable-mempool (requires mmap)
To overcome the memory fragmentation issue (bb#1063, bb#1028)
in clamd this option allows the databases to be loaded in
different memory "pools".
As soon as a database is no longer needed its pool is destroyed
and the memory is *really* returned to the system.
The performace is comparable to that of the glibc allocator,
when not better, however there is a small overhead (a few MB)
in the initial memory usage (but at least it no longer grows).
Thanks a lot sgran for the idea and nitrox for the extensive
testing. Please test and report any problem (expecially on
non-x86 and non-Linux setups).
Thu Oct 30 17:18:28 CET 2008 (tk)
---------------------------------
* V 0.94.1

6652
aclocal.m4 vendored

File diff suppressed because it is too large Load Diff

@ -1,5 +1,8 @@
/* clamav-config.h.in. Generated from configure.in by autoheader. */
/* mmap flag for anonymous maps */
#undef ANONYMOUS_MAP
/* enable bind8 compatibility */
#undef BIND_8_COMPAT
@ -371,12 +374,18 @@
/* The number of bytes in type short */
#undef SIZEOF_SHORT
/* The number of bytes in type void * */
#undef SIZEOF_VOID_P
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Support for IPv6 */
#undef SUPPORT_IPv6
/* enable memory pools */
#undef USE_MPOOL
/* use syslog */
#undef USE_SYSLOG

318
configure vendored

@ -1517,6 +1517,7 @@ Optional Features:
--disable-libtool-lock avoid locking (might break parallel builds)
--disable-gcc-vcheck do not check for buggy gcc version
--enable-experimental enable experimental code
--enable-mempool enable memory pools
--enable-check Enable 'check' unit tests (default=auto)
--disable-rpath do not hardcode runtime library paths
--enable-coverage turn on test coverage [default=no]
@ -4755,13 +4756,13 @@ if test "${lt_cv_nm_interface+set}" = set; then
else
lt_cv_nm_interface="BSD nm"
echo "int some_variable = 0;" > conftest.$ac_ext
(eval echo "\"\$as_me:4758: $ac_compile\"" >&5)
(eval echo "\"\$as_me:4759: $ac_compile\"" >&5)
(eval "$ac_compile" 2>conftest.err)
cat conftest.err >&5
(eval echo "\"\$as_me:4761: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
(eval echo "\"\$as_me:4762: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
(eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
cat conftest.err >&5
(eval echo "\"\$as_me:4764: output\"" >&5)
(eval echo "\"\$as_me:4765: output\"" >&5)
cat conftest.out >&5
if $GREP 'External.*some_variable' conftest.out > /dev/null; then
lt_cv_nm_interface="MS dumpbin"
@ -5972,7 +5973,7 @@ ia64-*-hpux*)
;;
*-*-irix6*)
# Find out which ABI we are using.
echo '#line 5975 "configure"' > conftest.$ac_ext
echo '#line 5976 "configure"' > conftest.$ac_ext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>&5
ac_status=$?
@ -7823,11 +7824,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:7826: $lt_compile\"" >&5)
(eval echo "\"\$as_me:7827: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
echo "$as_me:7830: \$? = $ac_status" >&5
echo "$as_me:7831: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@ -8162,11 +8163,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:8165: $lt_compile\"" >&5)
(eval echo "\"\$as_me:8166: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
echo "$as_me:8169: \$? = $ac_status" >&5
echo "$as_me:8170: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@ -8267,11 +8268,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:8270: $lt_compile\"" >&5)
(eval echo "\"\$as_me:8271: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
echo "$as_me:8274: \$? = $ac_status" >&5
echo "$as_me:8275: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@ -8322,11 +8323,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:8325: $lt_compile\"" >&5)
(eval echo "\"\$as_me:8326: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
echo "$as_me:8329: \$? = $ac_status" >&5
echo "$as_me:8330: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@ -11078,7 +11079,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 11081 "configure"
#line 11082 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -11174,7 +11175,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 11177 "configure"
#line 11178 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -13422,6 +13423,74 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
{ echo "$as_me:$LINENO: checking size of void *" >&5
echo $ECHO_N "checking size of void *... $ECHO_C" >&6; }
if test "${ac_cv_sizeof_void_p+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
for ac_size in 4 8 1 2 16 ; do # List sizes in rough order of prevalence.
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include "confdefs.h"
#include <sys/types.h>
int
main ()
{
switch (0) case 0: case (sizeof (void *) == $ac_size):;
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext
if { (ac_try="$ac_compile"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
(eval "$ac_compile") 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } && {
test -z "$ac_c_werror_flag" ||
test ! -s conftest.err
} && test -s conftest.$ac_objext; then
ac_cv_sizeof_void_p=$ac_size
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
if test x$ac_cv_sizeof_void_p != x ; then break; fi
done
fi
if test x$ac_cv_sizeof_void_p = x ; then
{ { echo "$as_me:$LINENO: error: cannot determine a size for void *" >&5
echo "$as_me: error: cannot determine a size for void *" >&2;}
{ (exit 1); exit 1; }; }
fi
{ echo "$as_me:$LINENO: result: $ac_cv_sizeof_void_p" >&5
echo "${ECHO_T}$ac_cv_sizeof_void_p" >&6; }
cat >>confdefs.h <<_ACEOF
#define SIZEOF_VOID_P $ac_cv_sizeof_void_p
_ACEOF
# Check whether --enable-experimental was given.
if test "${enable_experimental+set}" = set; then
@ -13942,6 +14011,227 @@ _ACEOF
fi
# Check whether --enable-mempool was given.
if test "${enable_mempool+set}" = set; then
enableval=$enable_mempool; enable_mempool=$enableval
else
enable_mempool="no"
fi
if test "$enable_mempool" = "yes"; then
if test "$ac_cv_c_mmap_private" != "yes"; then
{ echo "$as_me:$LINENO: WARNING: ****** mempool support disabled (mmap not available or not usable)" >&5
echo "$as_me: WARNING: ****** mempool support disabled (mmap not available or not usable)" >&2;}
else
{ echo "$as_me:$LINENO: checking for getpagesize" >&5
echo $ECHO_N "checking for getpagesize... $ECHO_C" >&6; }
if test "${ac_cv_func_getpagesize+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
/* Define getpagesize to an innocuous variant, in case <limits.h> declares getpagesize.
For example, HP-UX 11i <limits.h> declares gettimeofday. */
#define getpagesize innocuous_getpagesize
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char getpagesize (); below.
Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
<limits.h> exists even on freestanding compilers. */
#ifdef __STDC__
# include <limits.h>
#else
# include <assert.h>
#endif
#undef getpagesize
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char getpagesize ();
/* The GNU C library defines this for functions which it implements
to always fail with ENOSYS. Some functions are actually named
something starting with __ and the normal name is an alias. */
#if defined __stub_getpagesize || defined __stub___getpagesize
choke me
#endif
int
main ()
{
return getpagesize ();
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext conftest$ac_exeext
if { (ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
(eval "$ac_link") 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } && {
test -z "$ac_c_werror_flag" ||
test ! -s conftest.err
} && test -s conftest$ac_exeext &&
$as_test_x conftest$ac_exeext; then
ac_cv_func_getpagesize=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_cv_func_getpagesize=no
fi
rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
conftest$ac_exeext conftest.$ac_ext
fi
{ echo "$as_me:$LINENO: result: $ac_cv_func_getpagesize" >&5
echo "${ECHO_T}$ac_cv_func_getpagesize" >&6; }
if test $ac_cv_func_getpagesize = yes; then
{ echo "$as_me:$LINENO: checking for MAP_ANON(YMOUS)" >&5
echo $ECHO_N "checking for MAP_ANON(YMOUS)... $ECHO_C" >&6; }
if test "${ac_cv_c_mmap_anonymous+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
ac_cv_c_mmap_anonymous='no'
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <sys/mman.h>
int
main ()
{
mmap((void *)0, 0, PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext
if { (ac_try="$ac_compile"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
(eval "$ac_compile") 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } && {
test -z "$ac_c_werror_flag" ||
test ! -s conftest.err
} && test -s conftest.$ac_objext; then
ac_cv_c_mmap_anonymous='MAP_ANONYMOUS'
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <sys/mman.h>
int
main ()
{
mmap((void *)0, 0, PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext conftest$ac_exeext
if { (ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
(eval "$ac_link") 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } && {
test -z "$ac_c_werror_flag" ||
test ! -s conftest.err
} && test -s conftest$ac_exeext &&
$as_test_x conftest$ac_exeext; then
ac_cv_c_mmap_anonymous='MAP_ANONYMOUS'
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
fi
rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
conftest$ac_exeext conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
{ echo "$as_me:$LINENO: result: $ac_cv_c_mmap_anonymous" >&5
echo "${ECHO_T}$ac_cv_c_mmap_anonymous" >&6; }
if test "$ac_cv_c_mmap_anonymous" != "no"; then
cat >>confdefs.h <<_ACEOF
#define ANONYMOUS_MAP $ac_cv_c_mmap_anonymous
_ACEOF
fi
if test "$ac_cv_c_mmap_anonymous" = "no"; then
{ echo "$as_me:$LINENO: WARNING: ****** mempool support disabled (anonymous mmap not available)" >&5
echo "$as_me: WARNING: ****** mempool support disabled (anonymous mmap not available)" >&2;}
else
cat >>confdefs.h <<\_ACEOF
#define USE_MPOOL 1
_ACEOF
fi
else
{ echo "$as_me:$LINENO: WARNING: ****** mempool support disabled (getpagesize not available)" >&5
echo "$as_me: WARNING: ****** mempool support disabled (getpagesize not available)" >&2;}
fi
fi
fi
enable_check_ut=auto
enable_ut_install=no
# Check whether --enable-check was given.

@ -400,6 +400,7 @@ AC_COMPILE_CHECK_SIZEOF([short])
AC_COMPILE_CHECK_SIZEOF([int])
AC_COMPILE_CHECK_SIZEOF([long])
AC_COMPILE_CHECK_SIZEOF([long long])
AC_COMPILE_CHECK_SIZEOF([void *])
AC_ARG_ENABLE([experimental],
[ --enable-experimental enable experimental code],
@ -417,6 +418,22 @@ AC_CHECK_FUNCS([poll setsid memcpy snprintf vsnprintf strerror_r strlcpy strlcat
AC_C_FUNC_MMAP_PRIVATE
AC_FUNC_FSEEKO
AC_ARG_ENABLE([mempool],[ --enable-mempool enable memory pools], enable_mempool=$enableval, enable_mempool="no")
if test "$enable_mempool" = "yes"; then
if test "$ac_cv_c_mmap_private" != "yes"; then
AC_MSG_WARN([****** mempool support disabled (mmap not available or not usable)])
else
AC_CHECK_FUNC([getpagesize], [
AC_C_FUNC_MMAP_ANONYMOUS
if test "$ac_cv_c_mmap_anonymous" = "no"; then
AC_MSG_WARN([****** mempool support disabled (anonymous mmap not available)])
else
AC_DEFINE([USE_MPOOL],1,[enable memory pools])
fi
], [AC_MSG_WARN([****** mempool support disabled (getpagesize not available)])])
fi
fi
enable_check_ut=auto
enable_ut_install=no
AC_ARG_ENABLE(check,

@ -18,7 +18,7 @@
SUBDIRS = lzma .
AM_CPPFLAGS = -I$(top_srcdir) -I@srcdir@/nsis -I@srcdir@/lzma
AM_CPPFLAGS = -I$(top_srcdir) -I@srcdir@/nsis -I@srcdir@/lzma
libclamav_la_LIBADD = lzma/liblzma.la @CLAMAV_UNRAR_LIBS@ @LIBCLAMAV_LIBS@ @THREAD_LIBS@
@ -198,7 +198,9 @@ libclamav_la_SOURCES = \
uniq.c \
uniq.h \
version.c\
version.h
version.h\
mpool.c\
mpool.h
.PHONY: version.h.tmp
version.lo: version.h

@ -92,7 +92,7 @@ am_libclamav_la_OBJECTS = matcher-ac.lo matcher-bm.lo matcher.lo \
uuencode.lo phishcheck.lo phish_domaincheck_db.lo \
phish_whitelist.lo regex_list.lo regex_suffix.lo mspack.lo \
cab.lo entconv.lo hashtab.lo dconf.lo lzma_iface.lo explode.lo \
textnorm.lo dlp.lo js-norm.lo uniq.lo version.lo
textnorm.lo dlp.lo js-norm.lo uniq.lo version.lo mpool.lo
libclamav_la_OBJECTS = $(am_libclamav_la_OBJECTS)
libclamav_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
@ -281,7 +281,7 @@ target_vendor = @target_vendor@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = lzma .
AM_CPPFLAGS = -I$(top_srcdir) -I@srcdir@/nsis -I@srcdir@/lzma
AM_CPPFLAGS = -I$(top_srcdir) -I@srcdir@/nsis -I@srcdir@/lzma
libclamav_la_LIBADD = lzma/liblzma.la @CLAMAV_UNRAR_LIBS@ @LIBCLAMAV_LIBS@ @THREAD_LIBS@
libclamav_la_LDFLAGS = @TH_SAFE@ -version-info @LIBCLAMAV_VERSION@ \
-no-undefined $(am__append_1)
@ -454,7 +454,9 @@ libclamav_la_SOURCES = \
uniq.c \
uniq.h \
version.c\
version.h
version.h\
mpool.c\
mpool.h
libclamav_internal_utils_la_SOURCES = str.c \
str.h \
@ -589,6 +591,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/md5.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/message.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mew.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mpool.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msexpand.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mspack.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nulsft.Plo@am__quote@

@ -23,7 +23,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#ifdef __cplusplus
extern "C"
{
@ -152,6 +152,9 @@ struct cl_engine {
/* PUA categories (to be included or excluded) */
char *pua_cats;
/* Used for memory pools */
void *mempool;
};
struct cl_limits {

@ -35,6 +35,8 @@
#include "str.h"
#include "others.h"
#include "mpool.h"
struct dconf_module {
const char *mname; /* module name */
const char *sname; /* submodule name */
@ -109,13 +111,16 @@ static struct dconf_module modules[] = {
{ NULL, NULL, 0, 0 }
};
#ifdef USE_MPOOL
struct cli_dconf *cli_dconf_init(mp_t *mempool)
#else
struct cli_dconf *cli_dconf_init(void)
#endif
{
unsigned int i;
struct cli_dconf *dconf;
dconf = (struct cli_dconf *) cli_calloc(sizeof(struct cli_dconf), 1);
dconf = (struct cli_dconf *) mp_calloc(mempool, sizeof(struct cli_dconf), 1);
if(!dconf)
return NULL;

@ -21,7 +21,6 @@
#ifndef __DCONF_H
#define __DCONF_H
#include <stdio.h>
#include <zlib.h>
@ -29,6 +28,8 @@
#include "cltypes.h"
#include "cvd.h"
#include "mpool.h"
struct cli_dconf {
uint32_t pe;
uint32_t elf;
@ -98,7 +99,13 @@ struct cli_dconf {
#define PHISHING_CONF_ENGINE 0x1
#define PHISHING_CONF_ENTCONV 0x2
#ifdef USE_MPOOL
struct cli_dconf *cli_dconf_init(mp_t *);
#define cli_mp_dconf_init(a) cli_dconf_init(a)
#else
struct cli_dconf *cli_dconf_init(void);
#define cli_mp_dconf_init(a) cli_dconf_init()
#endif
void cli_dconf_print(struct cli_dconf *dconf);
int cli_dconf_load(FILE *fs, struct cl_engine **engine, unsigned int options, struct cli_dbio *dbio);
#endif

@ -40,6 +40,7 @@
#include "htmlnorm.h"
#include "entconv.h"
#include "mpool.h"
static const struct ftmap_s {
const char *name;
@ -100,16 +101,16 @@ cli_file_t cli_ftcode(const char *name)
return CL_TYPE_ERROR;
}
void cli_ftfree(struct cli_ftype *ftypes)
void cli_ftfree(const struct cl_engine *engine)
{
struct cli_ftype *pt;
struct cli_ftype *ftypes=engine->ftypes, *pt;
while(ftypes) {
pt = ftypes;
ftypes = ftypes->next;
free(pt->magic);
free(pt->tname);
free(pt);
mp_free(engine->mempool, pt->magic);
mp_free(engine->mempool, pt->tname);
mp_free(engine->mempool, pt);
}
}

@ -95,7 +95,7 @@ struct cli_matched_type {
};
cli_file_t cli_ftcode(const char *name);
void cli_ftfree(struct cli_ftype *ftypes);
void cli_ftfree(const struct cl_engine *engine);
cli_file_t cli_filetype(const unsigned char *buf, size_t buflen, const struct cl_engine *engine);
cli_file_t cli_filetype2(int desc, const struct cl_engine *engine);
int cli_addtypesigs(struct cl_engine *engine);

@ -39,6 +39,8 @@
#include "str.h"
#include "readdb.h"
#include "mpool.h"
uint8_t cli_ac_mindepth = AC_DEFAULT_MIN_DEPTH;
uint8_t cli_ac_maxdepth = AC_DEFAULT_MAX_DEPTH;
@ -66,7 +68,7 @@ int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern)
for(i = 0; i < len; i++) {
if(!pt->trans) {
pt->trans = (struct cli_ac_node **) cli_calloc(256, sizeof(struct cli_ac_node *));
pt->trans = (struct cli_ac_node **) mp_calloc(root->mempool, 256, sizeof(struct cli_ac_node *));
if(!pt->trans) {
cli_errmsg("cli_ac_addpatt: Can't allocate memory for pt->trans\n");
return CL_EMEM;
@ -76,17 +78,17 @@ int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern)
next = pt->trans[(unsigned char) (pattern->pattern[i] & 0xff)];
if(!next) {
next = (struct cli_ac_node *) cli_calloc(1, sizeof(struct cli_ac_node));
next = (struct cli_ac_node *) mp_calloc(root->mempool, 1, sizeof(struct cli_ac_node));
if(!next) {
cli_errmsg("cli_ac_addpatt: Can't allocate memory for AC node\n");
return CL_EMEM;
}
if(i != len - 1) {
next->trans = (struct cli_ac_node **) cli_calloc(256, sizeof(struct cli_ac_node *));
next->trans = (struct cli_ac_node **) mp_calloc(root->mempool, 256, sizeof(struct cli_ac_node *));
if(!next->trans) {
cli_errmsg("cli_ac_addpatt: Can't allocate memory for next->trans\n");
free(next);
mp_free(root->mempool, next);
return CL_EMEM;
}
} else {
@ -94,13 +96,13 @@ int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern)
}
root->ac_nodes++;
newtable = cli_realloc(root->ac_nodetable, root->ac_nodes * sizeof(struct cli_ac_node *));
newtable = mp_realloc(root->mempool, root->ac_nodetable, root->ac_nodes * sizeof(struct cli_ac_node *));
if(!newtable) {
root->ac_nodes--;
cli_errmsg("cli_ac_addpatt: Can't realloc ac_nodetable\n");
if(next->trans)
free(next->trans);
free(next);
mp_free(root->mempool, next->trans);
mp_free(root->mempool, next);
return CL_EMEM;
}
root->ac_nodetable = (struct cli_ac_node **) newtable;
@ -114,7 +116,7 @@ int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern)
}
root->ac_patterns++;
newtable = cli_realloc(root->ac_pattable, root->ac_patterns * sizeof(struct cli_ac_patt *));
newtable = mp_realloc(root->mempool, root->ac_pattable, root->ac_patterns * sizeof(struct cli_ac_patt *));
if(!newtable) {
root->ac_patterns--;
cli_errmsg("cli_ac_addpatt: Can't realloc ac_pattable\n");
@ -299,16 +301,16 @@ int cli_ac_buildtrie(struct cli_matcher *root)
int cli_ac_init(struct cli_matcher *root, uint8_t mindepth, uint8_t maxdepth)
{
root->ac_root = (struct cli_ac_node *) cli_calloc(1, sizeof(struct cli_ac_node));
root->ac_root = (struct cli_ac_node *) mp_calloc(root->mempool, 1, sizeof(struct cli_ac_node));
if(!root->ac_root) {
cli_errmsg("cli_ac_init: Can't allocate memory for ac_root\n");
return CL_EMEM;
}
root->ac_root->trans = (struct cli_ac_node **) cli_calloc(256, sizeof(struct cli_ac_node *));
root->ac_root->trans = (struct cli_ac_node **) mp_calloc(root->mempool, 256, sizeof(struct cli_ac_node *));
if(!root->ac_root->trans) {
cli_errmsg("cli_ac_init: Can't allocate memory for ac_root->trans\n");
free(root->ac_root);
mp_free(root->mempool, root->ac_root);
return CL_EMEM;
}
@ -318,7 +320,13 @@ int cli_ac_init(struct cli_matcher *root, uint8_t mindepth, uint8_t maxdepth)
return CL_SUCCESS;
}
#ifdef USE_MPOOL
#define mp_ac_free_alt(a, b) ac_free_alt(a, b)
static void ac_free_alt(mp_t *mempool, struct cli_ac_patt *p)
#else
#define mp_ac_free_alt(a, b) ac_free_alt(b)
static void ac_free_alt(struct cli_ac_patt *p)
#endif
{
uint16_t i;
struct cli_ac_alt *a1, *a2;
@ -333,11 +341,11 @@ static void ac_free_alt(struct cli_ac_patt *p)
a2 = a1;
a1 = a1->next;
if(a2->str)
free(a2->str);
free(a2);
mp_free(mempool, a2->str);
mp_free(mempool, a2);
}
}
free(p->alttable);
mp_free(mempool, p->alttable);
}
void cli_ac_free(struct cli_matcher *root)
@ -348,29 +356,28 @@ void cli_ac_free(struct cli_matcher *root)
for(i = 0; i < root->ac_patterns; i++) {
patt = root->ac_pattable[i];
patt->prefix ? free(patt->prefix) : free(patt->pattern);
free(patt->virname);
mp_free(root->mempool, patt->prefix ? patt->prefix : patt->pattern);
mp_free(root->mempool, patt->virname);
if(patt->offset)
free(patt->offset);
mp_free(root->mempool, patt->offset);
if(patt->alt)
ac_free_alt(patt);
free(patt);
mp_ac_free_alt(root->mempool, patt);
mp_free(root->mempool, patt);
}
if(root->ac_pattable)
free(root->ac_pattable);
mp_free(root->mempool, root->ac_pattable);
for(i = 0; i < root->ac_nodes; i++) {
if(!root->ac_nodetable[i]->leaf)
free(root->ac_nodetable[i]->trans);
free(root->ac_nodetable[i]);
mp_free(root->mempool, root->ac_nodetable[i]->trans);
mp_free(root->mempool, root->ac_nodetable[i]);
}
if(root->ac_nodetable)
free(root->ac_nodetable);
mp_free(root->mempool, root->ac_nodetable);
if(root->ac_root) {
free(root->ac_root->trans);
free(root->ac_root);
mp_free(root->mempool, root->ac_root->trans);
mp_free(root->mempool, root->ac_root);
}
}
@ -1093,8 +1100,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
if(strlen(hexsig) / 2 < root->ac_mindepth)
return CL_EPATSHORT;
if((new = (struct cli_ac_patt *) cli_calloc(1, sizeof(struct cli_ac_patt))) == NULL)
if((new = (struct cli_ac_patt *) mp_calloc(root->mempool, 1, sizeof(struct cli_ac_patt))) == NULL)
return CL_EMEM;
new->rtype = rtype;
@ -1114,7 +1120,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
if(strchr(hexsig, '[')) {
if(!(hexcpy = cli_strdup(hexsig))) {
free(new);
mp_free(root->mempool, new);
return CL_EMEM;
}
@ -1179,14 +1185,14 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
if(error) {
free(hexcpy);
free(new);
mp_free(root->mempool, new);
return error;
}
hex = cli_strdup(hex);
free(hexcpy);
if(!hex) {
free(new);
mp_free(root->mempool, new);
return CL_EMEM;
}
}
@ -1197,13 +1203,13 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
if(hex) {
hexcpy = hex;
} else if(!(hexcpy = cli_strdup(hexsig))) {
free(new);
mp_free(root->mempool, new);
return CL_EMEM;
}
if(!(hexnew = (char *) cli_calloc(strlen(hexsig) + 1, 1))) {
free(hexcpy);
free(new);
free(hexcpy);
return CL_EMEM;
}
@ -1225,7 +1231,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
}
*start++ = 0;
newalt = (struct cli_ac_alt *) cli_calloc(1, sizeof(struct cli_ac_alt));
newalt = (struct cli_ac_alt *) mp_calloc(root->mempool, 1, sizeof(struct cli_ac_alt));
if(!newalt) {
cli_errmsg("cli_ac_addsig: Can't allocate newalt\n");
error = CL_EMEM;
@ -1233,10 +1239,11 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
}
new->alt++;
newtable = (struct cli_ac_alt **) cli_realloc(new->alttable, new->alt * sizeof(struct cli_ac_alt *));
newtable = (struct cli_ac_alt **) mp_realloc(root->mempool, new->alttable, new->alt * sizeof(struct cli_ac_alt *));
if(!newtable) {
new->alt--;
free(newalt);
mp_free(root->mempool, newalt);
cli_errmsg("cli_ac_addsig: Can't realloc new->alttable\n");
error = CL_EMEM;
break;
@ -1256,7 +1263,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
if(3 * newalt->num - 1 == (uint16_t) strlen(pt)) {
newalt->chmode = 1;
newalt->str = (unsigned char *) cli_malloc(newalt->num);
newalt->str = (unsigned char *) mp_malloc(root->mempool, newalt->num);
if(!newalt->str) {
cli_errmsg("cli_ac_addsig: Can't allocate newalt->str\n");
error = CL_EMEM;
@ -1285,7 +1292,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
while(altpt->next)
altpt = altpt->next;
altpt->next = (struct cli_ac_alt *) cli_calloc(1, sizeof(struct cli_ac_alt));
altpt->next = (struct cli_ac_alt *) mp_calloc(root->mempool, 1, sizeof(struct cli_ac_alt));
if(!altpt->next) {
cli_errmsg("cli_ac_addsig: Can't allocate altpt->next\n");
error = CL_EMEM;
@ -1318,20 +1325,35 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
if(error) {
if(new->alt) {
free(hex);
ac_free_alt(new);
mp_ac_free_alt(root->mempool, new);
}
free(new);
mp_free(root->mempool, new);
return error;
}
}
if((new->pattern = cli_hex2ui(hex ? hex : hexsig)) == NULL) {
#ifdef USE_MPOOL
{
unsigned int mpoolpattsz = (strlen(hex ? hex : hexsig) / 2 + 1) * sizeof(uint16_t);
uint16_t *mpoolpatt = cli_hex2ui(hex ? hex : hexsig);
if(mpoolpatt) {
if((new->pattern = mp_malloc(root->mempool, mpoolpattsz)) != NULL)
memcpy(new->pattern, mpoolpatt, mpoolpattsz);
free(mpoolpatt);
} else new->pattern = NULL;
}
#else
new->pattern = cli_hex2ui(hex ? hex : hexsig);
#endif
if(new->pattern == NULL) {
if(new->alt)
ac_free_alt(new);
mp_ac_free_alt(root->mempool, new);
mp_free(root->mempool, new);
free(hex);
free(new);
return CL_EMALFDB;
}
new->length = strlen(hex ? hex : hexsig) / 2;
free(hex);
@ -1375,9 +1397,9 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
if(plen < root->ac_mindepth) {
cli_errmsg("cli_ac_addsig: Can't find a static subpattern of length %u\n", root->ac_mindepth);
ac_free_alt(new);
free(new->pattern);
free(new);
mp_ac_free_alt(root->mempool, new);
mp_free(root->mempool, new->pattern);
mp_free(root->mempool, new);
return CL_EMALFDB;
}
@ -1394,11 +1416,22 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
if(new->length > root->maxpatlen)
root->maxpatlen = new->length;
#ifdef USE_MPOOL
{
char *mpoolvirname = cli_virname((char *) virname, options & CL_DB_OFFICIAL, 0);
if(mpoolvirname) {
if((new->virname = mp_malloc(root->mempool, strlen(mpoolvirname) + 1)) != NULL)
strcpy(new->virname, mpoolvirname);
free(mpoolvirname);
} else new->virname = NULL;
}
#else
new->virname = cli_virname((char *) virname, options & CL_DB_OFFICIAL, 0);
#endif
if(!new->virname) {
new->prefix ? free(new->prefix) : free(new->pattern);
ac_free_alt(new);
free(new);
mp_free(root->mempool, new->prefix ? new->prefix : new->pattern);
mp_ac_free_alt(root->mempool, new);
mp_free(root->mempool, new);
return CL_EMEM;
}
@ -1406,23 +1439,28 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
root->ac_lsigtable[new->lsigid[1]]->virname = new->virname;
if(offset) {
#ifdef USE_MPOOL
if((new->offset = mp_malloc(root->mempool, strlen(offset) + 1)))
strcpy(new->offset, offset);
#else
new->offset = cli_strdup(offset);
#endif
if(!new->offset) {
new->prefix ? free(new->prefix) : free(new->pattern);
ac_free_alt(new);
free(new->virname);
free(new);
mp_free(root->mempool, new->prefix ? new->prefix : new->pattern);
mp_ac_free_alt(root->mempool, new);
mp_free(root->mempool, new->virname);
mp_free(root->mempool, new);
return CL_EMEM;
}
}
if((ret = cli_ac_addpatt(root, new))) {
new->prefix ? free(new->prefix) : free(new->pattern);
free(new->virname);
ac_free_alt(new);
mp_free(root->mempool, new->prefix ? new->prefix : new->pattern);
mp_free(root->mempool, new->virname);
mp_ac_free_alt(root->mempool, new);
if(new->offset)
free(new->offset);
free(new);
mp_free(root->mempool, new->offset);
mp_free(root->mempool, new);
return ret;
}

@ -32,6 +32,8 @@
#include "matcher-bm.h"
#include "filetypes.h"
#include "mpool.h"
#define BM_MIN_LENGTH 3
#define BM_BLOCK_SIZE 3
#define HASH(a,b,c) (211 * a + 37 * b + c)
@ -97,12 +99,11 @@ int cli_bm_init(struct cli_matcher *root)
{
uint16_t i, size = HASH(255, 255, 255) + 1;
if(!(root->bm_shift = (uint8_t *) cli_calloc(size, sizeof(uint8_t))))
if(!(root->bm_shift = (uint8_t *) mp_calloc(root->mempool, size, sizeof(uint8_t))))
return CL_EMEM;
if(!(root->bm_suffix = (struct cli_bm_patt **) cli_calloc(size, sizeof(struct cli_bm_patt *)))) {
free(root->bm_shift);
if(!(root->bm_suffix = (struct cli_bm_patt **) mp_calloc(root->mempool, size, sizeof(struct cli_bm_patt *)))) {
mp_free(root->mempool, root->bm_shift);
return CL_EMEM;
}
@ -119,7 +120,7 @@ void cli_bm_free(struct cli_matcher *root)
if(root->bm_shift)
free(root->bm_shift);
mp_free(root->mempool, root->bm_shift);
if(root->bm_suffix) {
for(i = 0; i < size; i++) {
@ -128,17 +129,17 @@ void cli_bm_free(struct cli_matcher *root)
prev = patt;
patt = patt->next;
if(prev->prefix)
free(prev->prefix);
mp_free(root->mempool, prev->prefix);
else
free(prev->pattern);
mp_free(root->mempool, prev->pattern);
if(prev->virname)
free(prev->virname);
mp_free(root->mempool, prev->virname);
if(prev->offset)
free(prev->offset);
free(prev);
mp_free(root->mempool, prev->offset);
mp_free(root->mempool, prev);
}
}
free(root->bm_suffix);
mp_free(root->mempool, root->bm_suffix);
}
}

@ -34,6 +34,8 @@
#include "matcher-bm.h"
#include "hashtab.h"
#include "mpool.h"
#define CLI_MATCH_WILDCARD 0xff00
#define CLI_MATCH_CHAR 0x0000
#define CLI_MATCH_IGNORE 0x0100
@ -54,6 +56,9 @@ struct cli_lsig_tdb {
const uint32_t *engine, *nos, *ep;
const uint32_t *sectoff, *sectrva, *sectvsz, *sectraw, *sectrsz,
*secturva, *sectuvsz, *secturaw, *sectursz;
#ifdef USE_MPOOL
mp_t *mempool;
#endif
};
struct cli_ac_lsig {
@ -80,6 +85,9 @@ struct cli_matcher {
uint16_t maxpatlen;
uint8_t ac_only;
#ifdef USE_MPOOL
mp_t *mempool;
#endif
};
struct cli_meta_node {

@ -0,0 +1,525 @@
/*
* Copyright (C) 2008 Sourcefire, Inc.
*
* Authors: aCaB <acab@clamav.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
/* a naive pool allocator */
#if HAVE_CONFIG_H
#include "clamav-config.h"
#endif
#ifdef USE_MPOOL
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_STRING_H
#include <string.h>
#endif
#include <sys/mman.h>
#include <stddef.h>
#include "others.h"
/* #define DEBUGMPOOL /\* DO NOT define *\/ */
#ifdef DEBUGMPOOL
FILE *lfd = NULL;
#define spam(...) cli_warnmsg(lfd, __VA_ARGS__)
#else
#define spam
#endif
#include "mpool.h"
/* #define MIN_FRAGSIZE 4096 /\* 1m2.282s *\/ */
/* #define MIN_FRAGSIZE 8192 /\* 0m46.652s *\/ */
/* #define MIN_FRAGSIZE 16384 /\* 0m8.365s *\/ */
/* #define MIN_FRAGSIZE 32768 /\* 0m3.788s *\/ */
/* #define MIN_FRAGSIZE 65536 /\* 0m2.759s *\/ */
/* #define MIN_FRAGSIZE 131072 /\* 0m2.445s *\/ */
#define MIN_FRAGSIZE 262144 /* 0m2.343s */
/* #define MIN_FRAGSIZE 524288 /\* 0m2.387s *\/ */
/* #define MIN_FRAGSIZE 1048576 /\* 0m2.392s *\/ */
/* #define MIN_FRAGSIZE 2097152 /\* 0m2.402s *\/ */
#if SIZEOF_VOID_P==8
static const unsigned int fragsz[] = {
24, /* (33067) */
32, /* (93970) */
40, /* (731473) */
48, /* (35342) */
56, /* (6967) */
64, /* (442053) */
72, /* (2706) */
80, /* (2281) */
88, /* (3658) */
96, /* (2620) */
104, /* (3705) */
112, /* (3722) */
120, /* (4012) */
128, /* (5161) */
136, /* (22458) */
144, /* (4339) */
152, /* (4315) */
160, /* (12195) */
168, /* (18042) */
/* 176, /\* (341) *\/ */
/* 184, /\* (329) *\/ */
192, /* (202) */
/* 200, /\* (238) *\/ */
/* 208, /\* (166) *\/ */
/* 216, /\* (179) *\/ */
224, /* (216) */
/* 232, /\* (189) *\/ */
/* 240, /\* (157) *\/ */
/* 248, /\* (178) *\/ */
256, /* (133) */
/* 264, /\* (157) *\/ */
/* 272, /\* (140) *\/ */
/* 280, /\* (161) *\/ */
/* 288, /\* (125) *\/ */
/* 296, /\* (141) *\/ */
304, /* (100) */
/* 312, /\* (114) *\/ */
/* 320, /\* (70) *\/ */
/* 328, /\* (13) *\/ */
/* 336, /\* (21) *\/ */
/* 344, /\* (21) *\/ */
352, /* (13) */
/* 360, /\* (26) *\/ */
/* 368, /\* (8) *\/ */
/* 376, /\* (14) *\/ */
/* 384, /\* (5) *\/ */
/* 392, /\* (6) *\/ */
/* 400, /\* (4) *\/ */
/* 408, /\* (2) *\/ */
/* 416, /\* (6) *\/ */
424, /* (20) */
/* 432, /\* (4) *\/ */
/* 440, /\* (4) *\/ */
/* 448, /\* (4) *\/ */
/* 464, /\* (2) *\/ */
/* 472, /\* (2) *\/ */
/* 480, /\* (1) *\/ */
/* 496, /\* (1) *\/ */
/* 512, /\* (2) *\/ */
528, /* (15) */
/* 536, /\* (1) *\/ */
/* 544, /\* (2) *\/ */
/* 552, /\* (1) *\/ */
/* 584, /\* (3) *\/ */
/* 600, /\* (1) *\/ */
/* 624, /\* (1) *\/ */
/* 656, /\* (1) *\/ */
/* 784, /\* (2) *\/ */
1040, /* (15) */
/* 2064, /\* (7456) *\/ */
2072, /* (14) */
4112, /* (14) */
8208, /* (9) */
16400, /* (6) */
32784, /* (4) */
63512, /* (7) */
134408, /* (2) */
507984, /* (7) */
1051040, /* (1) */
2097152
/* ^^ This shouldn't be reached but it's a good fall back
* MAX_ALLOCATION is 184549376 but that's really not need here */
};
#else
static const unsigned int fragsz[] = {
12, /* (2297) */
16, /* (30785) */
20, /* (41460) */
24, /* (69214) */
28, /* (639488) */
32, /* (107920) */
36, /* (454213) */
40, /* (11497) */
44, /* (1688) */
48, /* (5294) */
52, /* (1496) */
56, /* (3738) */
60, /* (1719) */
64, /* (918) */
68, /* (956) */
72, /* (1324) */
76, /* (1905) */
80, /* (1745) */
84, /* (1053) */
88, /* (1566) */
92, /* (2081) */
96, /* (20851) */
100, /* (1882) */
104, /* (1848) */
108, /* (1931) */
112, /* (2079) */
116, /* (1736) */
120, /* (3425) */
124, /* (2115) */
128, /* (1298) */
132, /* (2307) */
136, /* (2033) */
140, /* (2837) */
144, /* (1479) */
148, /* (1607) */
152, /* (10587) */
156, /* (2719) */
160, /* (15311) */
164, /* (196) */
168, /* (145) */
172, /* (211) */
176, /* (140) */
180, /* (116) */
/* 184, /\* (86) *\/ */
188, /* (119) */
192, /* (104) */
/* 196, /\* (99) *\/ */
/* 200, /\* (84) *\/ */
/* 204, /\* (94) *\/ */
/* 208, /\* (86) *\/ */
212, /* (136) */
/* 216, /\* (80) *\/ */
/* 220, /\* (75) *\/ */
/* 224, /\* (97) *\/ */
/* 228, /\* (99) *\/ */
/* 232, /\* (74) *\/ */
236, /* (114) */
/* 240, /\* (64) *\/ */
/* 244, /\* (73) *\/ */
/* 248, /\* (62) *\/ */
/* 252, /\* (71) *\/ */
/* 256, /\* (69) *\/ */
/* 260, /\* (85) *\/ */
/* 264, /\* (71) *\/ */
268, /* (92) */
/* 272, /\* (69) *\/ */
/* 276, /\* (56) *\/ */
/* 280, /\* (69) *\/ */
/* 284, /\* (71) *\/ */
/* 288, /\* (70) *\/ */
/* 292, /\* (62) *\/ */
/* 296, /\* (39) *\/ */
/* 300, /\* (54) *\/ */
/* 304, /\* (43) *\/ */
/* 308, /\* (54) *\/ */
312, /* (30) */
/* 316, /\* (8) *\/ */
/* 320, /\* (5) *\/ */
/* 324, /\* (7) *\/ */
/* 328, /\* (14) *\/ */
/* 332, /\* (13) *\/ */
/* 336, /\* (8) *\/ */
/* 340, /\* (7) *\/ */
/* 344, /\* (6) *\/ */
/* 348, /\* (2) *\/ */
/* 352, /\* (7) *\/ */
/* 356, /\* (18) *\/ */
/* 360, /\* (5) *\/ */
364, /* (12) */
/* 368, /\* (2) *\/ */
/* 372, /\* (4) *\/ */
/* 376, /\* (2) *\/ */
/* 380, /\* (5) *\/ */
/* 384, /\* (1) *\/ */
/* 392, /\* (4) *\/ */
/* 396, /\* (3) *\/ */
/* 404, /\* (4) *\/ */
/* 408, /\* (2) *\/ */
/* 412, /\* (3) *\/ */
/* 416, /\* (2) *\/ */
/* 420, /\* (3) *\/ */
/* 424, /\* (2) *\/ */
428, /* (16) */
/* 432, /\* (4) *\/ */
/* 436, /\* (1) *\/ */
/* 440, /\* (3) *\/ */
/* 452, /\* (1) *\/ */
/* 456, /\* (2) *\/ */
/* 460, /\* (8) *\/ */
/* 468, /\* (1) *\/ */
/* 472, /\* (2) *\/ */
/* 484, /\* (1) *\/ */
/* 492, /\* (4) *\/ */
/* 500, /\* (1) *\/ */
/* 504, /\* (2) *\/ */
/* 508, /\* (1) *\/ */
/* 516, /\* (2) *\/ */
/* 524, /\* (5) *\/ */
532, /* (15) */
/* 536, /\* (3) *\/ */
/* 540, /\* (1) *\/ */
/* 556, /\* (4) *\/ */
/* 576, /\* (3) *\/ */
/* 588, /\* (8) *\/ */
/* 612, /\* (1) *\/ */
/* 616, /\* (1) *\/ */
/* 620, /\* (5) *\/ */
/* 648, /\* (1) *\/ */
/* 652, /\* (1) *\/ */
/* 680, /\* (1) *\/ */
/* 704, /\* (1) *\/ */
/* 716, /\* (1) *\/ */
/* 772, /\* (1) *\/ */
/* 776, /\* (1) *\/ */
1032, /* (7549) */
/* 1044, /\* (14) *\/ */
2076, /* (14) */
4116, /* (9) */
8212, /* (6) */
16404, /* (4) */
63504, /* (7) */
135636, /* (2) */
253992, /* (7) */
1050864, /* (1) */
2097152
};
#endif
#define FRAGSBITS (sizeof(fragsz)/sizeof(fragsz[0]))
struct MPMAP {
struct MPMAP *next;
unsigned int size;
unsigned int usize;
};
struct MP {
unsigned int psize;
struct FRAG *avail[FRAGSBITS];
struct MPMAP mpm;
};
struct FRAG {
struct FRAG *next;
unsigned int sbits;
void *fake;
};
#define FRAG_OVERHEAD (offsetof(struct FRAG, fake))
#define align_to_voidptr(size) (((size) / sizeof(void *) + ((size) % sizeof(void *) != 0)) * sizeof(void *))
#define roundup(size) (FRAG_OVERHEAD + align_to_voidptr(size))
static unsigned int align_to_pagesize(struct MP *mp, unsigned int size) {
return (size / mp->psize + (size % mp->psize != 0)) * mp->psize;
}
static unsigned int to_bits(unsigned int size) {
unsigned int i;
for(i=0; i<FRAGSBITS; i++)
if(fragsz[i] >= size) return i;
return FRAGSBITS;
}
static unsigned int from_bits(unsigned int bits) {
if (bits >= FRAGSBITS) return 0;
return fragsz[bits];
}
struct MP *mp_create() {
struct MP mp, *mp_p;
unsigned int sz;
memset(&mp, 0, sizeof(mp));
mp.psize = getpagesize();
#ifdef DEBUGMPOOL
lfd = fopen("mmpool_log", "w");
#endif
sz = align_to_pagesize(&mp, MIN_FRAGSIZE);
mp.mpm.usize = align_to_voidptr(sizeof(struct MPMAP));
mp.mpm.size = sz - align_to_voidptr(sizeof(mp));
if ((mp_p = (struct MP *)mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)) == MAP_FAILED)
return NULL;
memcpy(mp_p, &mp, sizeof(mp));
spam("Map created @ %p->%p - size %u out of %u\n", mp_p, (void*)mp_p + mp.mpm.size, mp.mpm.usize, mp.mpm.size);
return mp_p;
}
void mp_destroy(struct MP *mp) {
struct MPMAP *mpm_next = mp->mpm.next, *mpm;
while((mpm = mpm_next)) {
mpm_next = mpm->next;
munmap((void *)mpm, mpm->size);
}
munmap((void *)mp, mp->mpm.size + align_to_voidptr(sizeof(mp)));
spam("Map destroyed @ %p\n", mp);
}
void mp_flush(struct MP *mp) {
struct MPMAP *mpm_next = mp->mpm.next, *mpm;
while((mpm = mpm_next)) {
mpm_next = mpm->next;
munmap((void *)mpm + align_to_pagesize(mp, mpm->usize), mpm->size - align_to_pagesize(mp, mpm->usize));
mpm->size = mpm->usize = align_to_pagesize(mp, mpm->usize);
}
munmap(&mp->mpm + align_to_pagesize(mp, mp->mpm.usize + align_to_voidptr(sizeof(mp))), mp->mpm.size - align_to_pagesize(mp, mp->mpm.usize + align_to_voidptr(sizeof(mp))));
mp->mpm.size = mp->mpm.usize;
spam("Map flushed @ %p\n", mp);
}
void *mp_malloc(struct MP *mp, size_t size) {
unsigned int i, j, needed = align_to_voidptr(size + FRAG_OVERHEAD);
const unsigned int sbits = to_bits(needed);
struct FRAG *f = NULL;
struct MPMAP *mpm = &mp->mpm;
/* check_all(mp); */
if (!size || sbits == FRAGSBITS) {
cli_errmsg("mp_malloc(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", (unsigned long int) size);
return NULL;
}
/* Case 1: We have a free'd frag */
if((f = mp->avail[sbits])) {
spam("malloc %p size %u (freed)\n", f, roundup(size));
mp->avail[sbits] = f->next;
return &f->fake;
}
if (!(needed = from_bits(sbits))) {
cli_errmsg("mp_malloc(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", (unsigned long int) size);
return NULL;
}
/* Case 2: We have nuff room available for this frag already */
while(mpm) {
if(mpm->size - mpm->usize >= needed) {
f = (struct FRAG *)((void *)mpm + mpm->usize);
spam("malloc %p size %u (hole)\n", f, roundup(size));
mpm->usize += needed;
f->sbits = sbits;
return &f->fake;
}
mpm = mpm->next;
}
/* Case 3: We allocate more */
if (needed + align_to_voidptr(sizeof(*mpm)) > MIN_FRAGSIZE)
i = align_to_pagesize(mp, needed + align_to_voidptr(sizeof(*mpm)));
else
i = align_to_pagesize(mp, MIN_FRAGSIZE);
if ((mpm = (struct MPMAP *)mmap(NULL, i, PROT_READ | PROT_WRITE, MAP_PRIVATE|ANONYMOUS_MAP, -1, 0)) == MAP_FAILED) {
cli_errmsg("mp_malloc(): Can't allocate memory (%lu bytes).\n", (unsigned long int)i);
spam("failed to alloc %u bytes (%u requested)\n", i, size);
return NULL;
}
mpm->size = i;
mpm->usize = needed + align_to_voidptr(sizeof(*mpm));
mpm->next = mp->mpm.next;
mp->mpm.next = mpm;
f = (struct FRAG *)((void *)mpm + align_to_voidptr(sizeof(*mpm)));
spam("malloc %p size %u (new map)\n", f, roundup(size));
f->sbits = sbits;
return &f->fake;
}
void mp_free(struct MP *mp, void *ptr) {
struct FRAG *f = (struct FRAG *)(ptr - FRAG_OVERHEAD);
if (!ptr) return;
f->next = mp->avail[f->sbits];
mp->avail[f->sbits] = f;
spam("free @ %p\n", f);
}
void *mp_calloc(struct MP *mp, size_t nmemb, size_t size) {
unsigned int needed = nmemb*size;
void *ptr;
if(!needed) return NULL;
if((ptr = mp_malloc(mp, needed)))
memset(ptr, 0, needed);
return ptr;
}
void *mp_realloc(struct MP *mp, void *ptr, size_t size) {
struct FRAG *f = (struct FRAG *)(ptr - FRAG_OVERHEAD);
unsigned int csize;
void *new_ptr;
if (!ptr) return mp_malloc(mp, size);
spam("realloc @ %p (size %u -> %u))\n", f, from_bits(f->sbits), size);
if(!size || !(csize = from_bits(f->sbits))) {
cli_errmsg("mp_realloc(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", (unsigned long int) size);
return NULL;
}
csize -= FRAG_OVERHEAD;
if (csize >= size) return ptr;
if (!(new_ptr = mp_malloc(mp, size)))
return NULL;
memcpy(new_ptr, ptr, csize);
mp_free(mp, ptr);
return new_ptr;
}
void *mp_realloc2(struct MP *mp, void *ptr, size_t size) {
struct FRAG *f = (struct FRAG *)(ptr - FRAG_OVERHEAD);
unsigned int csize;
void *new_ptr;
if (!ptr) return mp_malloc(mp, size);
spam("realloc @ %p (size %u -> %u))\n", f, from_bits(f->sbits), size);
if(!size || !(csize = from_bits(f->sbits))) {
cli_errmsg("mp_realloc2(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", (unsigned long int) size);
mp_free(mp, ptr);
return NULL;
}
csize -= FRAG_OVERHEAD;
if (csize >= size) return ptr;
if ((new_ptr = mp_malloc(mp, size)))
memcpy(new_ptr, ptr, csize);
mp_free(mp, ptr);
return new_ptr;
}
#ifdef DEBUGMPOOL
void mp_stats(struct MP *mp) {
unsigned int i=0, ta=0, tu=0;
struct MPMAP *mpm = &mp->mpm;
cli_warnmsg("MEMORY POOL STATISTICS\n map \tsize\tused\t%\n");
while(mpm) {
cli_warnmsg("- %u\t%u\t%u\t%f%%\n", i, mpm->size, mpm->usize, (float)mpm->usize/(float)mpm->size*100);
ta+=mpm->size;
tu+=mpm->usize;
i++;
mpm = mpm->next;
}
cli_warnmsg("MEMORY POOL SUMMARY\nMaps: %u\nTotal: %u\nUsed: %u (%f%%)\n", i, ta, tu, (float)tu/(float)ta*100);
}
void check_all(struct MP *mp) {
struct MPMAP *mpm = &mp->mpm;
while(mpm) {
volatile unsigned char *c = (unsigned char *)mpm;
unsigned int len = mpm->size;
spam("checking object %p - size %u\n", mpm, len);
while (len--) {
c[len];
}
mpm=mpm->next;
}
}
#endif /* DEBUGMPOOL */
#endif /* USE_MPOOL */

@ -0,0 +1,46 @@
/*
* Copyright (C) 2008 Sourcefire, Inc.
*
* Authors: aCaB <acab@clamav.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#ifndef MPOOL_H
#define MPOOL_H
#ifdef USE_MPOOL
typedef struct MP mp_t;
mp_t *mp_create(void);
void mp_destroy(mp_t *mp);
void *mp_malloc(mp_t *mp, size_t size);
void mp_free(mp_t *mp, void *ptr);
void *mp_calloc(mp_t *mp, size_t nmemb, size_t size);
void *mp_realloc(mp_t *mp, void *ptr, size_t size);
void *mp_realloc2(mp_t *mp, void *ptr, size_t size);
#else /* USE_MPOOL */
#define mp_malloc(a, b) cli_malloc(b)
#define mp_free(a, b) free(b)
#define mp_calloc(a, b, c) cli_calloc(b, c)
#define mp_realloc(a, b, c) cli_realloc(b, c)
#define mp_realloc2(a, b, c) cli_realloc2(b, c)
#endif /* USE_MPOOL */
#endif

@ -58,6 +58,9 @@ int init_domainlist(struct cl_engine* engine)
engine->domainlist_matcher = (struct regex_matcher *) cli_malloc(sizeof(struct regex_matcher));
if(!engine->domainlist_matcher)
return CL_EMEM;
#ifdef USE_MPOOL
((struct regex_matcher*)engine->domainlist_matcher)->mempool = engine->mempool;
#endif
return init_regex_list(engine->domainlist_matcher);
}
else

@ -45,6 +45,8 @@
#include "phish_whitelist.h"
#include "regex_list.h"
#include "mpool.h"
int whitelist_match(const struct cl_engine* engine,char* real_url,const char* display_url,int hostOnly)
{
const char* info;/*unused*/
@ -55,7 +57,10 @@ int whitelist_match(const struct cl_engine* engine,char* real_url,const char* di
int init_whitelist(struct cl_engine* engine)
{
if(engine) {
engine->whitelist_matcher = (struct regex_matcher *) cli_malloc(sizeof(struct regex_matcher));
engine->whitelist_matcher = (struct regex_matcher *) mp_malloc(engine->mempool, sizeof(struct regex_matcher));
#ifdef USE_MPOOL
((struct regex_matcher *)(engine->whitelist_matcher))->mempool = engine->mempool;
#endif
if(!engine->whitelist_matcher)
return CL_EMEM;
return init_regex_list(engine->whitelist_matcher);
@ -72,8 +77,8 @@ int is_whitelist_ok(const struct cl_engine* engine)
void whitelist_done(struct cl_engine* engine)
{
if(engine && engine->whitelist_matcher) {
regex_list_done(engine->whitelist_matcher);
free(engine->whitelist_matcher);
regex_list_done(engine->whitelist_matcher);
mp_free(engine->mempool, engine->whitelist_matcher);
engine->whitelist_matcher = NULL;
}
}

@ -52,6 +52,8 @@
#include "md5.h"
#include <assert.h>
#include "mpool.h"
#define DOMAIN_REAL 1
#define DOMAIN_DISPLAY 0
@ -857,7 +859,7 @@ int phishing_init(struct cl_engine* engine)
{
struct phishcheck* pchk;
if(!engine->phishcheck) {
pchk = engine->phishcheck = cli_malloc(sizeof(struct phishcheck));
pchk = engine->phishcheck = mp_malloc(engine->mempool, sizeof(struct phishcheck));
if(!pchk)
return CL_EMEM;
pchk->is_disabled=1;
@ -875,7 +877,7 @@ int phishing_init(struct cl_engine* engine)
cli_dbgmsg("Initializing phishcheck module\n");
if(build_regex(&pchk->preg_numeric,numeric_url_regex,1)) {
free(pchk);
mp_free(engine->mempool, pchk);
engine->phishcheck = NULL;
return CL_EFORMAT;
}
@ -895,7 +897,7 @@ void phishing_done(struct cl_engine* engine)
domainlist_done(engine);
if(pchk) {
cli_dbgmsg("Freeing phishcheck struct\n");
free(pchk);
mp_free(engine->mempool, pchk);
}
cli_dbgmsg("Phishcheck cleaned up\n");
}

@ -67,6 +67,8 @@
#include <stddef.h>
#endif
#include "mpool.h"
#ifdef CL_THREAD_SAFE
# include <pthread.h>
static pthread_mutex_t cli_ref_mutex = PTHREAD_MUTEX_INITIALIZER;
@ -279,29 +281,58 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex
}
} else {
bm_new = (struct cli_bm_patt *) cli_calloc(1, sizeof(struct cli_bm_patt));
bm_new = (struct cli_bm_patt *) mp_calloc(root->mempool, 1, sizeof(struct cli_bm_patt));
if(!bm_new)
return CL_EMEM;
if(!(bm_new->pattern = (unsigned char *) cli_hex2str(hexsig))) {
free(bm_new);
#ifdef USE_MPOOL
{
unsigned char *mpoolhexsig = (unsigned char *) cli_hex2str(hexsig);
if(mpoolhexsig) {
unsigned int mpoolhexsigsz = strlen(hexsig) / 2 + 1;
if((bm_new->pattern = mp_malloc(root->mempool, mpoolhexsigsz)))
memcpy(bm_new->pattern, mpoolhexsig, mpoolhexsigsz);
free(mpoolhexsig);
} else bm_new->pattern = NULL;
}
#else
bm_new->pattern = (unsigned char *) cli_hex2str(hexsig);
#endif
if(!bm_new->pattern) {
mp_free(root->mempool, bm_new);
return CL_EMALFDB;
}
bm_new->length = strlen(hexsig) / 2;
#ifdef USE_MPOOL
{
char *mpoolvirname = cli_virname((char *) virname, options & CL_DB_OFFICIAL, 0);
if(mpoolvirname) {
if((bm_new->virname = mp_malloc(root->mempool, strlen(mpoolvirname) + 1)))
strcpy(bm_new->virname, mpoolvirname);
free(mpoolvirname);
} else bm_new->virname = NULL;
}
#else
bm_new->virname = cli_virname((char *) virname, options & CL_DB_OFFICIAL, 0);
#endif
if(!bm_new->virname) {
free(bm_new->pattern);
free(bm_new);
mp_free(root->mempool, bm_new->pattern);
mp_free(root->mempool, bm_new);
return CL_EMEM;
}
if(offset) {
#ifdef USE_MPOOL
if((bm_new->offset = mp_malloc(root->mempool, strlen(offset) + 1)))
strcpy(bm_new->offset, offset);
#else
bm_new->offset = cli_strdup(offset);
#endif
if(!bm_new->offset) {
free(bm_new->pattern);
free(bm_new->virname);
free(bm_new);
mp_free(root->mempool, bm_new->pattern);
mp_free(root->mempool, bm_new->virname);
mp_free(root->mempool, bm_new);
return CL_EMEM;
}
}
@ -313,9 +344,9 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex
if((ret = cli_bm_addpatt(root, bm_new))) {
cli_errmsg("cli_parse_add(): Problem adding signature (4).\n");
free(bm_new->pattern);
free(bm_new->virname);
free(bm_new);
mp_free(root->mempool, bm_new->pattern);
mp_free(root->mempool, bm_new->virname);
mp_free(root->mempool, bm_new);
return ret;
}
}
@ -339,14 +370,20 @@ int cli_initengine(struct cl_engine **engine, unsigned int options)
(*engine)->refcount = 1;
(*engine)->root = cli_calloc(CLI_MTARGETS, sizeof(struct cli_matcher *));
#ifdef USE_MPOOL
if(!((*engine)->mempool = mp_create())) {
cli_errmsg("Can't allocate memory for memory pool!\n");
return CL_EMEM;
}
#endif
(*engine)->root = mp_calloc((*engine)->mempool, CLI_MTARGETS, sizeof(struct cli_matcher *));
if(!(*engine)->root) {
/* no need to free previously allocated memory here */
cli_errmsg("Can't allocate memory for roots!\n");
return CL_EMEM;
}
(*engine)->dconf = cli_dconf_init();
(*engine)->dconf = cli_mp_dconf_init((*engine)->mempool);
if(!(*engine)->dconf) {
cli_errmsg("Can't initialize dynamic configuration\n");
return CL_EMEM;
@ -369,7 +406,10 @@ static int cli_initroots(struct cl_engine *engine, unsigned int options)
for(i = 0; i < CLI_MTARGETS; i++) {
if(!engine->root[i]) {
cli_dbgmsg("Initializing engine->root[%d]\n", i);
root = engine->root[i] = (struct cli_matcher *) cli_calloc(1, sizeof(struct cli_matcher));
root = engine->root[i] = (struct cli_matcher *) mp_calloc(engine->mempool, 1, sizeof(struct cli_matcher));
#ifdef USE_MPOOL
root->mempool = engine->mempool;
#endif
if(!root) {
cli_errmsg("cli_initroots: Can't allocate memory for cli_matcher\n");
return CL_EMEM;
@ -791,7 +831,7 @@ static int lsigattribs(char *attribs, struct cli_lsig_tdb *tdb)
switch(apt->type) {
case CLI_TDB_UINT:
off[i] = cnt = tdb->cnt[CLI_TDB_UINT]++;
tdb->val = (uint32_t *) cli_realloc2(tdb->val, tdb->cnt[CLI_TDB_UINT] * sizeof(uint32_t));
tdb->val = (uint32_t *) mp_realloc2(tdb->mempool, tdb->val, tdb->cnt[CLI_TDB_UINT] * sizeof(uint32_t));
if(!tdb->val) {
tdb->cnt[CLI_TDB_UINT] = 0;
return -1;
@ -807,7 +847,7 @@ static int lsigattribs(char *attribs, struct cli_lsig_tdb *tdb)
*pt2++ = 0;
off[i] = cnt = tdb->cnt[CLI_TDB_RANGE];
tdb->cnt[CLI_TDB_RANGE] += 2;
tdb->range = (uint32_t *) cli_realloc2(tdb->range, tdb->cnt[CLI_TDB_RANGE] * sizeof(uint32_t));
tdb->range = (uint32_t *) mp_realloc2(tdb->mempool, tdb->range, tdb->cnt[CLI_TDB_RANGE] * sizeof(uint32_t));
if(!tdb->range) {
tdb->cnt[CLI_TDB_RANGE] = 0;
return -1;
@ -823,7 +863,7 @@ static int lsigattribs(char *attribs, struct cli_lsig_tdb *tdb)
}
off[i] = cnt = tdb->cnt[CLI_TDB_RANGE];
tdb->cnt[CLI_TDB_RANGE] += 3;
tdb->range = (uint32_t *) cli_realloc2(tdb->range, tdb->cnt[CLI_TDB_RANGE] * sizeof(uint32_t));
tdb->range = (uint32_t *) mp_realloc2(tdb->mempool, tdb->range, tdb->cnt[CLI_TDB_RANGE] * sizeof(uint32_t));
if(!tdb->range) {
tdb->cnt[CLI_TDB_RANGE] = 0;
return -1;
@ -840,7 +880,7 @@ static int lsigattribs(char *attribs, struct cli_lsig_tdb *tdb)
case CLI_TDB_STR:
off[i] = cnt = tdb->cnt[CLI_TDB_STR];
tdb->cnt[CLI_TDB_STR] += strlen(pt) + 1;
tdb->str = (char *) cli_realloc2(tdb->str, tdb->cnt[CLI_TDB_STR] * sizeof(char));
tdb->str = (char *) mp_realloc2(tdb->mempool, tdb->str, tdb->cnt[CLI_TDB_STR] * sizeof(char));
if(!tdb->str) {
cli_errmsg("lsigattribs: Can't allocate memory for tdb->str\n");
return -1;
@ -882,13 +922,14 @@ static int lsigattribs(char *attribs, struct cli_lsig_tdb *tdb)
return 0;
}
#define FREE_TDB(x) \
if(x.cnt[CLI_TDB_UINT]) \
free(x.val); \
if(x.cnt[CLI_TDB_RANGE]) \
free(x.range); \
if(x.cnt[CLI_TDB_STR]) \
free(x.str);
#define FREE_TDB(x) do { \
if(x.cnt[CLI_TDB_UINT]) \
mp_free(x.mempool, x.val); \
if(x.cnt[CLI_TDB_RANGE]) \
mp_free(x.mempool, x.range); \
if(x.cnt[CLI_TDB_STR]) \
mp_free(x.mempool, x.str); \
} while(0);
#define LDB_TOKENS 67
static int cli_loadldb(FILE *fs, struct cl_engine **engine, unsigned int *signo, unsigned int options, struct cli_dbio *dbio, const char *dbname)
@ -954,6 +995,9 @@ static int cli_loadldb(FILE *fs, struct cl_engine **engine, unsigned int *signo,
/* TDB */
memset(&tdb, 0, sizeof(tdb));
#ifdef USE_MPOOL
tdb.mempool = (*engine)->mempool;
#endif
if(lsigattribs(tokens[1], &tdb) == -1) {
FREE_TDB(tdb);
@ -988,19 +1032,24 @@ static int cli_loadldb(FILE *fs, struct cl_engine **engine, unsigned int *signo,
root = (*engine)->root[tdb.target[0]];
lsig = (struct cli_ac_lsig *) cli_calloc(1, sizeof(struct cli_ac_lsig));
lsig = (struct cli_ac_lsig *) mp_calloc((*engine)->mempool, 1, sizeof(struct cli_ac_lsig));
if(!lsig) {
cli_errmsg("cli_loadldb: Can't allocate memory for lsig\n");
FREE_TDB(tdb);
ret = CL_EMEM;
break;
}
#ifdef USE_MPOOL
if((lsig->logic = mp_malloc((*engine)->mempool, strlen(logic)+1)))
strcpy(lsig->logic, logic);
#else
lsig->logic = cli_strdup(logic);
#endif
if(!lsig->logic) {
cli_errmsg("cli_loadldb: Can't allocate memory for lsig->logic\n");
FREE_TDB(tdb);
ret = CL_EMEM;
free(lsig);
mp_free((*engine)->mempool, lsig);
break;
}
@ -1008,12 +1057,12 @@ static int cli_loadldb(FILE *fs, struct cl_engine **engine, unsigned int *signo,
memcpy(&lsig->tdb, &tdb, sizeof(tdb));
root->ac_lsigs++;
newtable = (struct cli_ac_lsig **) cli_realloc(root->ac_lsigtable, root->ac_lsigs * sizeof(struct cli_ac_lsig *));
newtable = (struct cli_ac_lsig **) mp_realloc((*engine)->mempool, root->ac_lsigtable, root->ac_lsigs * sizeof(struct cli_ac_lsig *));
if(!newtable) {
root->ac_lsigs--;
cli_errmsg("cli_loadldb: Can't realloc root->ac_lsigtable\n");
FREE_TDB(tdb);
free(lsig);
mp_free((*engine)->mempool, lsig);
ret = CL_EMEM;
break;
}
@ -1138,25 +1187,42 @@ static int cli_loadftm(FILE *fs, struct cl_engine **engine, unsigned int options
break;
} else if(atoi(tokens[0]) == 0) { /* memcmp() */
new = (struct cli_ftype *) cli_malloc(sizeof(struct cli_ftype));
new = (struct cli_ftype *) mp_malloc((*engine)->mempool, sizeof(struct cli_ftype));
if(!new) {
ret = CL_EMEM;
break;
}
new->type = type;
new->offset = atoi(tokens[1]);
#ifdef USE_MPOOL
{
unsigned char *mpoolmagic = cli_hex2str(tokens[2]);
if(mpoolmagic) {
unsigned int mpoolmagicsz = strlen(tokens[2]) / 2 + 1;
if((new->magic = mp_malloc((*engine)->mempool, mpoolmagicsz)))
memcpy(new->magic, mpoolmagic, mpoolmagicsz);
free(mpoolmagic);
} else new->magic = NULL;
}
#else
new->magic = (unsigned char *) cli_hex2str(tokens[2]);
#endif
if(!new->magic) {
cli_errmsg("cli_loadftm: Can't decode the hex string\n");
ret = CL_EMALFDB;
free(new);
mp_free((*engine)->mempool, new);
break;
}
new->length = strlen(tokens[2]) / 2;
#ifdef USE_MPOOL
if((new->tname = mp_malloc((*engine)->mempool, strlen(tokens[3])+1)))
strcpy(new->tname, tokens[3]);
#else
new->tname = cli_strdup(tokens[3]);
#endif
if(!new->tname) {
free(new->magic);
free(new);
mp_free((*engine)->mempool, new->magic);
mp_free((*engine)->mempool, new);
ret = CL_EMEM;
break;
}
@ -1211,22 +1277,33 @@ static int cli_loadign(FILE *fs, struct cl_engine **engine, unsigned int options
while(cli_dbgets(buffer, FILEBUFF, fs, dbio)) {
line++;
cli_chomp(buffer);
new = (struct cli_ignsig *) cli_calloc(1, sizeof(struct cli_ignsig));
new = (struct cli_ignsig *) mp_calloc((*engine)->mempool, 1, sizeof(struct cli_ignsig));
if(!new) {
ret = CL_EMEM;
break;
}
if(!(new->dbname = cli_strtok(buffer, 0, ":"))) {
free(new);
#ifdef USE_MPOOL
{
unsigned char *mpooldbname = cli_strtok(buffer, 0, ":");
if(mpooldbname) {
if((new->dbname = mp_malloc((*engine)->mempool, strlen(mpooldbname) + 1)))
strcpy(new->dbname, mpooldbname);
free(mpooldbname);
} else new->dbname = NULL;
}
#else
new->dbname = cli_strtok(buffer, 0, ":");
#endif
if(!new->dbname) {
mp_free((*engine)->mempool, new);
ret = CL_EMALFDB;
break;
}
if(!(pt = cli_strtok(buffer, 1, ":"))) {
free(new->dbname);
free(new);
mp_free((*engine)->mempool, new->dbname);
mp_free((*engine)->mempool, new);
ret = CL_EMALFDB;
break;
} else {
@ -1237,9 +1314,21 @@ static int cli_loadign(FILE *fs, struct cl_engine **engine, unsigned int options
if((ret = hashset_addkey(&ignored->hs, new->line)))
break;
if(!(new->signame = cli_strtok(buffer, 2, ":"))) {
free(new->dbname);
free(new);
#ifdef USE_MPOOL
{
unsigned char *mpoolsigname = cli_strtok(buffer, 2, ":");
if(mpoolsigname) {
if((new->signame = mp_malloc((*engine)->mempool, strlen(mpoolsigname) + 1)))
strcpy(new->signame, mpoolsigname);
free(mpoolsigname);
} else new->signame = NULL;
}
#else
new->signame = cli_strtok(buffer, 2, ":");
#endif
if(!new->signame) {
mp_free((*engine)->mempool, new->dbname);
mp_free((*engine)->mempool, new);
ret = CL_EMALFDB;
break;
}
@ -1266,9 +1355,9 @@ static void cli_freeign(struct cl_engine *engine)
while(ignored->list) {
pt = ignored->list;
ignored->list = ignored->list->next;
free(pt->dbname);
free(pt->signame);
free(pt);
mp_free(engine->mempool, pt->dbname);
mp_free(engine->mempool, pt->signame);
mp_free(engine->mempool,pt);
}
hashset_destroy(&ignored->hs);
free(engine->ignored);
@ -1292,16 +1381,18 @@ static int cli_md5db_init(struct cl_engine **engine, unsigned int mode)
if(mode == MD5_HDB) {
bm = (*engine)->md5_hdb = (struct cli_matcher *) cli_calloc(sizeof(struct cli_matcher), 1);
bm = (*engine)->md5_hdb = (struct cli_matcher *) mp_calloc((*engine)->mempool, sizeof(struct cli_matcher), 1);
} else if(mode == MD5_MDB) {
bm = (*engine)->md5_mdb = (struct cli_matcher *) cli_calloc(sizeof(struct cli_matcher), 1);
bm = (*engine)->md5_mdb = (struct cli_matcher *) mp_calloc((*engine)->mempool, sizeof(struct cli_matcher), 1);
} else {
bm = (*engine)->md5_fp = (struct cli_matcher *) cli_calloc(sizeof(struct cli_matcher), 1);
bm = (*engine)->md5_fp = (struct cli_matcher *) mp_calloc((*engine)->mempool, sizeof(struct cli_matcher), 1);
}
if(!bm)
return CL_EMEM;
#ifdef USE_MPOOL
bm->mempool = (*engine)->mempool;
#endif
if((ret = cli_bm_init(bm))) {
cli_errmsg("cli_md5db_init: Failed to initialize B-M\n");
return ret;
@ -1357,47 +1448,75 @@ static int cli_loadmd5(FILE *fs, struct cl_engine **engine, unsigned int *signo,
if((*engine)->ignored && cli_chkign((*engine)->ignored, dbname, line, pt))
continue;
new = (struct cli_bm_patt *) cli_calloc(1, sizeof(struct cli_bm_patt));
new = (struct cli_bm_patt *) mp_calloc((*engine)->mempool, 1, sizeof(struct cli_bm_patt));
if(!new) {
ret = CL_EMEM;
break;
}
if(!(pt = tokens[md5_field])) {
free(new);
mp_free((*engine)->mempool, new);
ret = CL_EMALFDB;
break;
}
#ifdef USE_MPOOL
if(strlen(pt) == 32) {
unsigned char *mpoolhex = (unsigned char *) cli_hex2str(pt);
if(mpoolhex) {
if((new->pattern = mp_malloc((*engine)->mempool, 17)))
memcpy(new->pattern, mpoolhex, 17);
free(mpoolhex);
} else new->pattern = NULL;
} else new->pattern = NULL;
if(new->pattern == NULL) {
cli_errmsg("cli_loadmd5: Malformed MD5 string at line %u\n", line);
mp_free((*engine)->mempool, new);
ret = CL_EMALFDB;
break;
}
#else
if(strlen(pt) != 32 || !(new->pattern = (unsigned char *) cli_hex2str(pt))) {
cli_errmsg("cli_loadmd5: Malformed MD5 string at line %u\n", line);
free(new);
ret = CL_EMALFDB;
break;
}
#endif
new->length = 16;
if(!(pt = tokens[size_field])) {
free(new->pattern);
free(new);
mp_free((*engine)->mempool, new->pattern);
mp_free((*engine)->mempool, new);
ret = CL_EMALFDB;
break;
}
size = atoi(pt);
if(!(new->virname = cli_virname((char *) tokens[2], options & CL_DB_OFFICIAL, 0))) {
free(new->pattern);
free(new);
#ifdef USE_MPOOL
{
char *mpoolvname = cli_virname((char *) tokens[2], options & CL_DB_OFFICIAL, 0);
if(mpoolvname) {
if((new->virname = mp_malloc((*engine)->mempool, strlen(mpoolvname) + 1)))
strcpy(new->virname, mpoolvname);
free(mpoolvname);
} else new->virname = NULL;
}
#else
new->virname = cli_virname((char *) tokens[2], options & CL_DB_OFFICIAL, 0);
#endif
if(!new->virname) {
mp_free((*engine)->mempool, new->pattern);
mp_free((*engine)->mempool, new);
ret = CL_EMALFDB;
break;
}
MD5_DB;
if(!db && (ret = cli_md5db_init(engine, mode))) {
free(new->pattern);
free(new->virname);
free(new);
mp_free((*engine)->mempool, new->pattern);
mp_free((*engine)->mempool, new->virname);
mp_free((*engine)->mempool, new);
break;
} else {
MD5_DB;
@ -1405,9 +1524,9 @@ static int cli_loadmd5(FILE *fs, struct cl_engine **engine, unsigned int *signo,
if((ret = cli_bm_addpatt(db, new))) {
cli_errmsg("cli_loadmd5: Error adding BM pattern\n");
free(new->pattern);
free(new->virname);
free(new);
mp_free((*engine)->mempool, new->pattern);
mp_free((*engine)->mempool, new->virname);
mp_free((*engine)->mempool, new);
break;
}
@ -1459,27 +1578,39 @@ static int cli_loadmd(FILE *fs, struct cl_engine **engine, unsigned int *signo,
cli_chomp(buffer);
new = (struct cli_meta_node *) cli_calloc(1, sizeof(struct cli_meta_node));
new = (struct cli_meta_node *) mp_calloc((*engine)->mempool, 1, sizeof(struct cli_meta_node));
if(!new) {
ret = CL_EMEM;
break;
}
if(!(new->virname = cli_virname(cli_strtok(buffer, 0, ":"), options & CL_DB_OFFICIAL, 1))) {
free(new);
#ifdef USE_MPOOL
{
char *mpoolvname = cli_virname(cli_strtok(buffer, 0, ":"), options & CL_DB_OFFICIAL, 1);
if(mpoolvname) {
if((new->virname = mp_malloc((*engine)->mempool, strlen(mpoolvname) + 1)))
strcpy(new->virname, mpoolvname);
free(mpoolvname);
} else new->virname = NULL;
}
#else
new->virname = cli_virname(cli_strtok(buffer, 0, ":"), options & CL_DB_OFFICIAL, 1);
#endif
if(!new->virname) {
mp_free((*engine)->mempool, new);
ret = CL_EMEM;
break;
}
if((*engine)->ignored && cli_chkign((*engine)->ignored, dbname, line, new->virname)) {
free(new->virname);
free(new);
mp_free((*engine)->mempool, new->virname);
mp_free((*engine)->mempool, new);
continue;
}
if(!(pt = cli_strtok(buffer, 1, ":"))) {
free(new->virname);
free(new);
mp_free((*engine)->mempool, new->virname);
mp_free((*engine)->mempool, new);
ret = CL_EMALFDB;
break;
} else {
@ -1487,22 +1618,34 @@ static int cli_loadmd(FILE *fs, struct cl_engine **engine, unsigned int *signo,
free(pt);
}
if(!(new->filename = cli_strtok(buffer, 2, ":"))) {
free(new->virname);
free(new);
#ifdef USE_MPOOL
{
char *mpoolfname = cli_strtok(buffer, 2, ":");
if(mpoolfname) {
if((new->filename = mp_malloc((*engine)->mempool, strlen(mpoolfname) + 1)))
strcpy(new->filename, mpoolfname);
free(mpoolfname);
} else new->filename = NULL;
}
#else
new->filename = cli_strtok(buffer, 2, ":");
#endif
if(!new->filename) {
mp_free((*engine)->mempool, new->virname);
mp_free((*engine)->mempool, new);
ret = CL_EMALFDB;
break;
} else {
if(!strcmp(new->filename, "*")) {
free(new->filename);
mp_free((*engine)->mempool, new->filename);
new->filename = NULL;
}
}
if(!(pt = cli_strtok(buffer, 3, ":"))) {
free(new->filename);
free(new->virname);
free(new);
if(new->filename) mp_free((*engine)->mempool, new->filename);
mp_free((*engine)->mempool, new->virname);
mp_free((*engine)->mempool, new);
ret = CL_EMALFDB;
break;
} else {
@ -1514,9 +1657,9 @@ static int cli_loadmd(FILE *fs, struct cl_engine **engine, unsigned int *signo,
}
if(!(pt = cli_strtok(buffer, 4, ":"))) {
free(new->filename);
free(new->virname);
free(new);
if(new->filename) mp_free((*engine)->mempool, new->filename);
mp_free((*engine)->mempool, new->virname);
mp_free((*engine)->mempool, new);
ret = CL_EMALFDB;
break;
} else {
@ -1528,9 +1671,9 @@ static int cli_loadmd(FILE *fs, struct cl_engine **engine, unsigned int *signo,
}
if(!(pt = cli_strtok(buffer, 5, ":"))) {
free(new->filename);
free(new->virname);
free(new);
if(new->filename) mp_free((*engine)->mempool, new->filename);
mp_free((*engine)->mempool, new->virname);
mp_free((*engine)->mempool, new);
ret = CL_EMALFDB;
break;
} else {
@ -1548,9 +1691,9 @@ static int cli_loadmd(FILE *fs, struct cl_engine **engine, unsigned int *signo,
}
if(!(pt = cli_strtok(buffer, 6, ":"))) {
free(new->filename);
free(new->virname);
free(new);
if(new->filename) mp_free((*engine)->mempool, new->filename);
mp_free((*engine)->mempool, new->virname);
mp_free((*engine)->mempool, new);
ret = CL_EMALFDB;
break;
} else {
@ -1562,9 +1705,9 @@ static int cli_loadmd(FILE *fs, struct cl_engine **engine, unsigned int *signo,
}
if(!(pt = cli_strtok(buffer, 7, ":"))) {
free(new->filename);
free(new->virname);
free(new);
if(new->filename) mp_free((*engine)->mempool, new->filename);
mp_free((*engine)->mempool, new->virname);
mp_free((*engine)->mempool, new);
ret = CL_EMALFDB;
break;
} else {
@ -1576,9 +1719,9 @@ static int cli_loadmd(FILE *fs, struct cl_engine **engine, unsigned int *signo,
}
if(!(pt = cli_strtok(buffer, 8, ":"))) {
free(new->filename);
free(new->virname);
free(new);
if(new->filename) mp_free((*engine)->mempool, new->filename);
mp_free((*engine)->mempool, new->virname);
mp_free((*engine)->mempool, new);
ret = CL_EMALFDB;
break;
} else {
@ -1883,7 +2026,6 @@ int cl_load(const char *path, struct cl_engine **engine, unsigned int *signo, un
cli_errmsg("cl_load(%s): Not supported database file type\n", path);
return CL_EOPEN;
}
return ret;
}
@ -2120,7 +2262,6 @@ void cl_free(struct cl_engine *engine)
#ifdef CL_THREAD_SAFE
pthread_mutex_unlock(&cli_ref_mutex);
#endif
if(engine->root) {
for(i = 0; i < CLI_MTARGETS; i++) {
if((root = engine->root[i])) {
@ -2129,68 +2270,70 @@ void cl_free(struct cl_engine *engine)
cli_ac_free(root);
if(root->ac_lsigtable) {
for(j = 0; j < root->ac_lsigs; j++) {
free(root->ac_lsigtable[j]->logic);
mp_free(engine->mempool, root->ac_lsigtable[j]->logic);
FREE_TDB(root->ac_lsigtable[j]->tdb);
free(root->ac_lsigtable[j]);
mp_free(engine->mempool, root->ac_lsigtable[j]);
}
free(root->ac_lsigtable);
mp_free(engine->mempool, root->ac_lsigtable);
}
free(root);
mp_free(engine->mempool, root);
}
}
free(engine->root);
mp_free(engine->mempool, engine->root);
}
if((root = engine->md5_hdb)) {
cli_bm_free(root);
free(root);
mp_free(engine->mempool, root);
}
if((root = engine->md5_mdb)) {
cli_bm_free(root);
free(root->soff);
mp_free(engine->mempool, root->soff);
if(root->md5_sizes_hs.capacity) {
hashset_destroy(&root->md5_sizes_hs);
}
free(root);
mp_free(engine->mempool, root);
}
if((root = engine->md5_fp)) {
cli_bm_free(root);
free(root);
mp_free(engine->mempool, root);
}
metapt = engine->zip_mlist;
while(metapt) {
metah = metapt;
metapt = metapt->next;
free(metah->virname);
mp_free(engine->mempool, metah->virname);
if(metah->filename)
free(metah->filename);
free(metah);
mp_free(engine->mempool, metah->filename);
mp_free(engine->mempool, metah);
}
metapt = engine->rar_mlist;
while(metapt) {
metah = metapt;
metapt = metapt->next;
free(metah->virname);
mp_free(engine->mempool, metah->virname);
if(metah->filename)
free(metah->filename);
free(metah);
mp_free(engine->mempool, metah->filename);
mp_free(engine->mempool, metah);
}
if(((struct cli_dconf *) engine->dconf)->phishing & PHISHING_CONF_ENGINE)
phishing_done(engine);
if(engine->dconf)
free(engine->dconf);
mp_free(engine->mempool, engine->dconf);
if(engine->pua_cats)
free(engine->pua_cats);
mp_free(engine->mempool, engine->pua_cats);
cli_ftfree(engine->ftypes);
cli_ftfree(engine);
cli_freeign(engine);
#ifdef USE_MPOOL
if(engine->mempool) mp_destroy(engine->mempool);
#endif
free(engine);
}
@ -2199,7 +2342,19 @@ static void cli_md5db_build(struct cli_matcher* root)
if(root && root->md5_sizes_hs.capacity) {
/* TODO: use hashset directly, instead of the array when matching*/
cli_dbgmsg("Converting hashset to array: %lu entries\n", root->md5_sizes_hs.count);
#ifdef USE_MPOOL
{
uint32_t *mpoolht;
unsigned int mpoolhtsz = root->md5_sizes_hs.count * sizeof(*mpoolht);
root->soff = mp_malloc(root->mempool, mpoolhtsz);
root->soff_len = hashset_toarray(&root->md5_sizes_hs, &mpoolht);
memcpy(root->soff, mpoolht, mpoolhtsz);
free(mpoolht);
}
#else
root->soff_len = hashset_toarray(&root->md5_sizes_hs, &root->soff);
#endif
hashset_destroy(&root->md5_sizes_hs);
qsort(root->soff, root->soff_len, sizeof(uint32_t), scomp);
}

@ -57,6 +57,9 @@
#include "readdb.h"
#include "jsparse/textbuf.h"
#include "regex_suffix.h"
#include "mpool.h"
/* Prototypes */
static regex_t *new_preg(struct regex_matcher *matcher);
static size_t reverse_string(char *pattern);
@ -342,6 +345,9 @@ int regex_list_match(struct regex_matcher* matcher,char* real_url,const char* di
/* Initializes @matcher, allocating necesarry substructures */
int init_regex_list(struct regex_matcher* matcher)
{
#ifdef USE_MPOOL
mp_t *mp = matcher->mempool;
#endif
int rc;
assert(matcher);
@ -350,11 +356,17 @@ int init_regex_list(struct regex_matcher* matcher)
matcher->list_inited=1;
matcher->list_built=0;
matcher->list_loaded=0;
hashtab_init(&matcher->suffix_hash, 10);
#ifdef USE_MPOOL
matcher->mempool = mp;
matcher->suffixes.mempool = mp;
#endif
if((rc = cli_ac_init(&matcher->suffixes, 2, 32))) {
return rc;
}
#ifdef USE_MPOOL
matcher->md5_hashes.mempool = mp;
#endif
if((rc = cli_bm_init(&matcher->md5_hashes))) {
return rc;
}
@ -581,9 +593,9 @@ void regex_list_done(struct regex_matcher* matcher)
for(i=0;i<matcher->regex_cnt;i++) {
regex_t *r = matcher->all_pregs[i];
cli_regfree(r);
free(r);
mp_free(matcher->mempool, r);
}
free(matcher->all_pregs);
mp_free(matcher->mempool, matcher->all_pregs);
}
hashtab_free(&matcher->suffix_hash);
cli_bm_free(&matcher->md5_hashes);
@ -599,7 +611,7 @@ int is_regex_ok(struct regex_matcher* matcher)
static int add_newsuffix(struct regex_matcher *matcher, struct regex_list *info, const char *suffix, size_t len)
{
struct cli_matcher *root = &matcher->suffixes;
struct cli_ac_patt *new = cli_calloc(1,sizeof(*new));
struct cli_ac_patt *new = mp_calloc(matcher->mempool,1,sizeof(*new));
size_t i;
int ret;
@ -621,9 +633,9 @@ static int add_newsuffix(struct regex_matcher *matcher, struct regex_list *info,
if(new->length > root->maxpatlen)
root->maxpatlen = new->length;
new->pattern = cli_malloc(sizeof(new->pattern[0])*len);
new->pattern = mp_malloc(matcher->mempool, sizeof(new->pattern[0])*len);
if(!new->pattern) {
free(new);
mp_free(matcher->mempool, new);
return CL_EMEM;
}
for(i=0;i<len;i++)
@ -632,8 +644,8 @@ static int add_newsuffix(struct regex_matcher *matcher, struct regex_list *info,
new->customdata = info;
new->virname = NULL;
if((ret = cli_ac_addpatt(root,new))) {
free(new->pattern);
free(new);
mp_free(matcher->mempool, new->pattern);
mp_free(matcher->mempool, new);
return ret;
}
SO_preprocess_add(&matcher->filter, (const unsigned char*)suffix, len);
@ -704,10 +716,10 @@ static size_t reverse_string(char *pattern)
static regex_t *new_preg(struct regex_matcher *matcher)
{
regex_t *r;
matcher->all_pregs = cli_realloc(matcher->all_pregs, ++matcher->regex_cnt * sizeof(*matcher->all_pregs));
matcher->all_pregs = mp_realloc(matcher->mempool, matcher->all_pregs, ++matcher->regex_cnt * sizeof(*matcher->all_pregs));
if(!matcher->all_pregs)
return NULL;
r = cli_malloc(sizeof(*r));
r = mp_malloc(matcher->mempool, sizeof(*r));
if(!r)
return NULL;
matcher->all_pregs[matcher->regex_cnt-1] = r;

@ -29,6 +29,8 @@
#include "matcher.h"
#include <zlib.h> /* for gzFile */
#include "mpool.h"
struct filter {
uint32_t B[65536];
uint32_t end_fast[256];
@ -51,6 +53,9 @@ struct regex_matcher {
struct cli_matcher md5_hashes;
struct filter md5_filter;
struct filter filter;
#ifdef USE_MPOOL
mp_t *mempool;
#endif
int list_inited:2;
int list_loaded:2;
int list_built:2;

@ -76,4 +76,22 @@ rm -f conftest.mmap
])
AC_DEFUN([AC_C_FUNC_MMAP_ANONYMOUS],
[
AC_CACHE_CHECK([for MAP_ANON(YMOUS)], [ac_cv_c_mmap_anonymous],[
ac_cv_c_mmap_anonymous='no'
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[#include <sys/mman.h>]], [[mmap((void *)0, 0, PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);]])],
[ac_cv_c_mmap_anonymous='MAP_ANONYMOUS'],
[
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[#include <sys/mman.h>]], [[mmap((void *)0, 0, PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);]])],
[ac_cv_c_mmap_anonymous='MAP_ANONYMOUS']
)
]
)
])
if test "$ac_cv_c_mmap_anonymous" != "no"; then
AC_DEFINE_UNQUOTED([ANONYMOUS_MAP],[$ac_cv_c_mmap_anonymous],[mmap flag for anonymous maps])
fi
])
Loading…
Cancel
Save