fix portability issues for fseeko, sysconf(_SC_PAGESIZE), getpagesize() (bb#1658)

0.96
aCaB 17 years ago
parent d0b31fa38c
commit 86d59b249e
  1. 5
      ChangeLog
  2. 6
      clamav-config.h.in
  3. 318
      configure
  4. 10
      configure.in
  5. 6
      libclamav/blob.c
  6. 15
      libclamav/ishield.c
  7. 2
      libclamav/mpool.c
  8. 11
      libclamav/others.h
  9. 29
      m4/mmap_private.m4

@ -1,3 +1,8 @@
Thu Jul 16 14:20:01 CEST 2009 (acab)
------------------------------------
* libclamav, build system: fix portability issues for fseeko, sysconf(_SC_PAGESIZE),
getpagesize() (bb#1658)
Wed Jul 15 23:36:09 EEST 2009 (edwin)
-------------------------------------
* libclamav/pe.c, yc.c: Make yC able to handle more samples and variants.

@ -196,6 +196,9 @@
/* gethostbyname_r takes 6 arguments */
#undef HAVE_GETHOSTBYNAME_R_6
/* Define to 1 if getpagesize() is available */
#undef HAVE_GETPAGESIZE
/* Define to 1 if you have the <grp.h> header file. */
#undef HAVE_GRP_H
@ -356,6 +359,9 @@
/* Define to 1 if you have the `strlcpy' function. */
#undef HAVE_STRLCPY
/* Define to 1 if sysconf(_SC_PAGESIZE) is available */
#undef HAVE_SYSCONF_SC_PAGESIZE
/* link against system-wide libtommath */
#undef HAVE_SYSTEM_TOMMATH

318
configure vendored

@ -16384,6 +16384,139 @@ _ACEOF
fi
done
{ $as_echo "$as_me:$LINENO: checking for _LARGEFILE_SOURCE value needed for large files" >&5
$as_echo_n "checking for _LARGEFILE_SOURCE value needed for large files... " >&6; }
if test "${ac_cv_sys_largefile_source+set}" = set; then
$as_echo_n "(cached) " >&6
else
while :; do
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <sys/types.h> /* for off_t */
#include <stdio.h>
int
main ()
{
int (*fp) (FILE *, off_t, int) = fseeko;
return fseeko (stdin, 0, 0) && fp (stdin, 0, 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 ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
$as_echo "$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
$as_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 && {
test "$cross_compiling" = yes ||
$as_test_x conftest$ac_exeext
}; then
ac_cv_sys_largefile_source=no; break
else
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
fi
rm -rf conftest.dSYM
rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
conftest$ac_exeext conftest.$ac_ext
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#define _LARGEFILE_SOURCE 1
#include <sys/types.h> /* for off_t */
#include <stdio.h>
int
main ()
{
int (*fp) (FILE *, off_t, int) = fseeko;
return fseeko (stdin, 0, 0) && fp (stdin, 0, 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 ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
$as_echo "$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
$as_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 && {
test "$cross_compiling" = yes ||
$as_test_x conftest$ac_exeext
}; then
ac_cv_sys_largefile_source=1; break
else
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
fi
rm -rf conftest.dSYM
rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
conftest$ac_exeext conftest.$ac_ext
ac_cv_sys_largefile_source=unknown
break
done
fi
{ $as_echo "$as_me:$LINENO: result: $ac_cv_sys_largefile_source" >&5
$as_echo "$ac_cv_sys_largefile_source" >&6; }
case $ac_cv_sys_largefile_source in #(
no | unknown) ;;
*)
cat >>confdefs.h <<_ACEOF
#define _LARGEFILE_SOURCE $ac_cv_sys_largefile_source
_ACEOF
;;
esac
rm -rf conftest*
# We used to try defining _XOPEN_SOURCE=500 too, to work around a bug
# in glibc 2.1.3, but that breaks too many other things.
# If you want fseeko and ftello with glibc, upgrade to a fixed glibc.
if test $ac_cv_sys_largefile_source != unknown; then
cat >>confdefs.h <<\_ACEOF
#define HAVE_FSEEKO 1
_ACEOF
fi
{ $as_echo "$as_me:$LINENO: checking for working mmap" >&5
$as_echo_n "checking for working mmap... " >&6; }
@ -16508,25 +16641,29 @@ _ACEOF
fi
rm -f conftest.mmap
{ $as_echo "$as_me:$LINENO: checking for _LARGEFILE_SOURCE value needed for large files" >&5
$as_echo_n "checking for _LARGEFILE_SOURCE value needed for large files... " >&6; }
if test "${ac_cv_sys_largefile_source+set}" = set; then
ac_cv_c_can_get_pagesize="no"
{ $as_echo "$as_me:$LINENO: checking for sysconf(_SC_PAGESIZE)" >&5
$as_echo_n "checking for sysconf(_SC_PAGESIZE)... " >&6; }
if test "${ac_cv_c_sysconf_sc_pagesize+set}" = set; then
$as_echo_n "(cached) " >&6
else
while :; do
cat >conftest.$ac_ext <<_ACEOF
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <sys/types.h> /* for off_t */
#include <stdio.h>
#include <sys/types.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
int
main ()
{
int (*fp) (FILE *, off_t, int) = fseeko;
return fseeko (stdin, 0, 0) && fp (stdin, 0, 0);
int x = sysconf(_SC_PAGESIZE);
;
return 0;
}
@ -16552,31 +16689,49 @@ $as_echo "$ac_try_echo") >&5
test "$cross_compiling" = yes ||
$as_test_x conftest$ac_exeext
}; then
ac_cv_sys_largefile_source=no; break
ac_cv_c_sysconf_sc_pagesize=yes
else
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_cv_c_sysconf_sc_pagesize=no
fi
rm -rf conftest.dSYM
rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
conftest$ac_exeext conftest.$ac_ext
cat >conftest.$ac_ext <<_ACEOF
fi
{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_sysconf_sc_pagesize" >&5
$as_echo "$ac_cv_c_sysconf_sc_pagesize" >&6; }
if test "$ac_cv_c_sysconf_sc_pagesize" = "yes"; then
cat >>confdefs.h <<\_ACEOF
#define HAVE_SYSCONF_SC_PAGESIZE 1
_ACEOF
ac_cv_c_can_get_pagesize="yes"
fi
{ $as_echo "$as_me:$LINENO: checking for getpagesize()" >&5
$as_echo_n "checking for getpagesize()... " >&6; }
if test "${ac_cv_c_getpagesize+set}" = set; then
$as_echo_n "(cached) " >&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 _LARGEFILE_SOURCE 1
#include <sys/types.h> /* for off_t */
#include <stdio.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
int
main ()
{
int (*fp) (FILE *, off_t, int) = fseeko;
return fseeko (stdin, 0, 0) && fp (stdin, 0, 0);
int x = getpagesize();
;
return 0;
}
@ -16602,45 +16757,30 @@ $as_echo "$ac_try_echo") >&5
test "$cross_compiling" = yes ||
$as_test_x conftest$ac_exeext
}; then
ac_cv_sys_largefile_source=1; break
ac_cv_c_getpagesize=yes
else
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_cv_c_getpagesize=no
fi
rm -rf conftest.dSYM
rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
conftest$ac_exeext conftest.$ac_ext
ac_cv_sys_largefile_source=unknown
break
done
fi
{ $as_echo "$as_me:$LINENO: result: $ac_cv_sys_largefile_source" >&5
$as_echo "$ac_cv_sys_largefile_source" >&6; }
case $ac_cv_sys_largefile_source in #(
no | unknown) ;;
*)
cat >>confdefs.h <<_ACEOF
#define _LARGEFILE_SOURCE $ac_cv_sys_largefile_source
_ACEOF
;;
esac
rm -rf conftest*
# We used to try defining _XOPEN_SOURCE=500 too, to work around a bug
# in glibc 2.1.3, but that breaks too many other things.
# If you want fseeko and ftello with glibc, upgrade to a fixed glibc.
if test $ac_cv_sys_largefile_source != unknown; then
fi
{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_getpagesize" >&5
$as_echo "$ac_cv_c_getpagesize" >&6; }
if test "$ac_cv_c_getpagesize" = "yes"; then
cat >>confdefs.h <<\_ACEOF
#define HAVE_FSEEKO 1
#define HAVE_GETPAGESIZE 1
_ACEOF
ac_cv_c_can_get_pagesize="yes"
fi
# Check whether --enable-mempool was given.
if test "${enable_mempool+set}" = set; then
enableval=$enable_mempool; enable_mempool=$enableval
@ -16653,93 +16793,10 @@ if test "$enable_mempool" = "yes"; then
{ $as_echo "$as_me:$LINENO: ****** mempool support disabled (mmap not available or not usable)" >&5
$as_echo "$as_me: ****** mempool support disabled (mmap not available or not usable)" >&6;}
else
{ $as_echo "$as_me:$LINENO: checking for getpagesize" >&5
$as_echo_n "checking for getpagesize... " >&6; }
if test "${ac_cv_func_getpagesize+set}" = set; then
$as_echo_n "(cached) " >&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 ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
$as_echo "$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
$as_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 && {
test "$cross_compiling" = yes ||
$as_test_x conftest$ac_exeext
}; then
ac_cv_func_getpagesize=yes
else
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_cv_func_getpagesize=no
fi
rm -rf conftest.dSYM
rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
conftest$ac_exeext conftest.$ac_ext
fi
{ $as_echo "$as_me:$LINENO: result: $ac_cv_func_getpagesize" >&5
$as_echo "$ac_cv_func_getpagesize" >&6; }
if test "x$ac_cv_func_getpagesize" = x""yes; then
if test "$ac_cv_c_can_get_pagesize" != "yes"; then
{ $as_echo "$as_me:$LINENO: ****** mempool support disabled (pagesize cannot be determined)" >&5
$as_echo "$as_me: ****** mempool support disabled (pagesize cannot be determined)" >&6;}
else
{ $as_echo "$as_me:$LINENO: checking for MAP_ANON(YMOUS)" >&5
$as_echo_n "checking for MAP_ANON(YMOUS)... " >&6; }
@ -16867,12 +16924,7 @@ cat >>confdefs.h <<\_ACEOF
_ACEOF
fi
else
{ $as_echo "$as_me:$LINENO: ****** mempool support disabled (getpagesize not available)" >&5
$as_echo "$as_me: ****** mempool support disabled (getpagesize not available)" >&6;}
fi
fi
fi
fi

@ -424,22 +424,26 @@ AC_CHECK_LIB([socket], [bind], [LIBS="$LIBS -lsocket"; CLAMAV_MILTER_LIBS="$CLAM
AC_SEARCH_LIBS([gethostent],[nsl], [(LIBS="$LIBS -lnsl"; CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lnsl"; FRESHCLAM_LIBS="$FRESHCLAM_LIBS -lnsl"; CLAMD_LIBS="$CLAMD_LIBS -lnsl")])
AC_CHECK_FUNCS([poll setsid memcpy snprintf vsnprintf strerror_r strlcpy strlcat strcasestr inet_ntop setgroups initgroups ctime_r mkstemp mallinfo])
AC_C_FUNC_MMAP_PRIVATE
AC_FUNC_FSEEKO
dnl Check if anon maps are available, check if we can determine the page size
AC_C_FUNC_MMAP_PRIVATE
AC_C_FUNC_PAGESIZE
AC_ARG_ENABLE([mempool],[ --disable-mempool disable memory pools], enable_mempool=$enableval, enable_mempool="yes")
if test "$enable_mempool" = "yes"; then
if test "$ac_cv_c_mmap_private" != "yes"; then
AC_MSG_NOTICE([****** mempool support disabled (mmap not available or not usable)])
else
AC_CHECK_FUNC([getpagesize], [
if test "$ac_cv_c_can_get_pagesize" != "yes"; then
AC_MSG_NOTICE([****** mempool support disabled (pagesize cannot be determined)])
else
AC_C_FUNC_MMAP_ANONYMOUS
if test "$ac_cv_c_mmap_anonymous" = "no"; then
AC_MSG_NOTICE([****** mempool support disabled (anonymous mmap not available)])
else
AC_DEFINE([USE_MPOOL],1,[enable memory pools])
fi
], [AC_MSG_NOTICE([****** mempool support disabled (getpagesize not available)])])
fi
fi
fi

@ -181,7 +181,7 @@ blobGetFilename(const blob *b)
int
blobAddData(blob *b, const unsigned char *data, size_t len)
{
#ifdef HAVE_GETPAGESIZE
#if HAVE_CLI_GETPAGESIZE
static int pagesize;
int growth;
#endif
@ -210,9 +210,9 @@ blobAddData(blob *b, const unsigned char *data, size_t len)
* size of a blob before you start adding data, use blobGrow() that's
* the most optimum
*/
#ifdef HAVE_GETPAGESIZE
#if HAVE_CLI_GETPAGESIZE
if(pagesize == 0) {
pagesize = getpagesize();
pagesize = cli_getpagesize();
if(pagesize == 0)
pagesize = 4096;
}

@ -41,7 +41,9 @@
#include <string.h>
#endif
#include <limits.h>
#if HAVE_STRINGS_H
#include <strings.h>
#endif
#include <zlib.h>
#include "scanners.h"
@ -514,8 +516,8 @@ static int is_parse_hdr(int desc, cli_ctx *ctx, struct IS_CABSTUFF *c) {
return CL_EREAD; /* hdr must be within bounds, it's k to hard fail here */
}
} else {
#if HAVE_MMAP
int psz = getpagesize();
#if HAVE_MMAP && HAVE_CLI_GETPAGESIZE
int psz = cli_getpagesize();
off_t mp_hdr = (c->hdr / psz) * psz;
mp_hdrsz = c->hdrsz + c->hdr - mp_hdr;
if((map = mmap(NULL, mp_hdrsz, PROT_READ, MAP_PRIVATE, desc, mp_hdr))==MAP_FAILED) {
@ -524,7 +526,7 @@ static int is_parse_hdr(int desc, cli_ctx *ctx, struct IS_CABSTUFF *c) {
}
hdr = map + c->hdr - mp_hdr;
#else
cli_warnmsg("is_parse_hdr: hdr too big and mmap unavailable\n");
cli_warnmsg("is_parse_hdr: hdr too big and mmap is not usable\n");
return CL_CLEAN
#endif
}
@ -716,7 +718,12 @@ static int is_extract_cab(int desc, cli_ctx *ctx, uint64_t off, uint64_t size, u
close(ofd);
return CL_EOPEN;
}
if(fseeko(in, off, SEEK_SET)) {
#if HAVE_FSEEKO
if(fseeko(in, (off_t)off, SEEK_SET))
#else
if(fseek(in, (long)off, SEEK_SET))
#endif
{
cli_dbgmsg("is_extract_cab: fseek failed\n");
fclose(in);
return CL_ESEEK;

@ -349,7 +349,7 @@ struct MP *mpool_create() {
struct MP mp, *mpool_p;
unsigned int sz;
memset(&mp, 0, sizeof(mp));
mp.psize = getpagesize();
mp.psize = cli_getpagesize();
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));

@ -365,6 +365,17 @@ void cli_dbgmsg_internal(const char *str, ...) __attribute__((format(printf, 1,
void cli_dbgmsg_internal(const char *str, ...);
#endif
#if HAVE_SYSCONF_SC_PAGESIZE
static inline int cli_getpagesize() { return sysconf(_SC_PAGESIZE); }
#define HAVE_CLI_GETPAGESIZE 1
#else
#if HAVE_GETPAGESIZE
static inline int cli_getpagesize() { return getpagesize(); }
#define HAVE_CLI_GETPAGESIZE 1
#endif
#define HAVE_CLI_GETPAGESIZE 0
#endif
void *cli_malloc(size_t nmemb);
void *cli_calloc(size_t nmemb, size_t size);
void *cli_realloc(void *ptr, size_t size);

@ -100,3 +100,32 @@ AC_DEFUN([AC_C_FUNC_MMAP_ANONYMOUS],
AC_DEFINE_UNQUOTED([ANONYMOUS_MAP],[$ac_cv_c_mmap_anonymous],[mmap flag for anonymous maps])
fi
])
AC_DEFUN([AC_C_FUNC_PAGESIZE],
[
ac_cv_c_can_get_pagesize="no"
AC_CACHE_CHECK([for sysconf(_SC_PAGESIZE)], [ac_cv_c_sysconf_sc_pagesize], [
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <sys/types.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif]], [[int x = sysconf(_SC_PAGESIZE);]])],
[ac_cv_c_sysconf_sc_pagesize=yes], [ac_cv_c_sysconf_sc_pagesize=no])
])
if test "$ac_cv_c_sysconf_sc_pagesize" = "yes"; then
AC_DEFINE([HAVE_SYSCONF_SC_PAGESIZE], 1, [Define to 1 if sysconf(_SC_PAGESIZE) is available])
ac_cv_c_can_get_pagesize="yes"
fi
AC_CACHE_CHECK([for getpagesize()], [ac_cv_c_getpagesize], [
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#if HAVE_UNISTD_H
#include <unistd.h>
#endif]], [[int x = getpagesize();]])],
[ac_cv_c_getpagesize=yes], [ac_cv_c_getpagesize=no])
])
if test "$ac_cv_c_getpagesize" = "yes"; then
AC_DEFINE([HAVE_GETPAGESIZE], 1, [Define to 1 if getpagesize() is available])
ac_cv_c_can_get_pagesize="yes"
fi
])

Loading…
Cancel
Save