From fff067577af897c6e4f4b7886aec56c4870ced56 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 2 Dec 2018 12:09:09 +0100 Subject: fix #5488 --- .gitignore | 13 +---- ChangeLog | 3 ++ configure.ac | 118 +++++++++++++++++++++++----------------------- src/include/extractor.h | 32 ++++++++----- src/main/Makefile.am | 4 +- src/main/test_extractor.c | 12 ++--- 6 files changed, 93 insertions(+), 89 deletions(-) diff --git a/.gitignore b/.gitignore index 48396d8..e508732 100644 --- a/.gitignore +++ b/.gitignore @@ -45,19 +45,8 @@ out po/Makefile po/Makefile.in po/POTFILES -po/de.gmo -po/fr.gmo -po/ga.gmo -po/it.gmo -po/nl.gmo -po/pl.gmo -po/ro.gmo -po/rw.gmo +po/*.gmo po/stamp-po -po/sr.gmo -po/sv.gmo -po/uk.gmo -po/vi.gmo src/Makefile src/Makefile.in src/common/.deps/ diff --git a/ChangeLog b/ChangeLog index 8f2a19c..4aa1a0d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +Sun Dec 2 12:05:33 CET 2018 + Fix #5488: do not export non-public functions from API. -CG + Sun Nov 18 11:19:28 CET 2018 Releasing GNU libextractor 1.8. -CG diff --git a/configure.ac b/configure.ac index 40a35c2..5b4422a 100644 --- a/configure.ac +++ b/configure.ac @@ -155,12 +155,9 @@ mingw*) EXT_LIB_PATH="-L$with_plibc/lib $EXT_LIB_PATH" plibc=1))]) - if test $plibc -ne 1; - then - AC_MSG_ERROR([libextractor requires PlibC]) - else - LIBS="$LIBS -lplibc" - fi + AS_IF([test $plibc -ne 1], + [AC_MSG_ERROR([libextractor requires PlibC])], + [LIBS="$LIBS -lplibc"]) AM_LDFLAGS="$AM_LDFLAGS -Wl,--export-all-symbols" AM_CONDITIONAL(HAVE_GNU_LD, true) @@ -211,10 +208,8 @@ AM_CONDITIONAL(MINGW, test "$build_os" = "mingw32") # use '-fno-strict-aliasing', but only if the compiler can take it -if gcc -fno-strict-aliasing -S -o /dev/null -xc /dev/null >/dev/null 2>&1; -then - AM_CFLAGS="-fno-strict-aliasing $AM_CFLAGS" -fi +AS_IF([gcc -fno-strict-aliasing -S -o /dev/null -xc /dev/null >/dev/null 2>&1], + [AM_CFLAGS="-fno-strict-aliasing $AM_CFLAGS"]) AM_CONDITIONAL(HAVE_CXX, test "x$HAVE_CXX" = "xyes") @@ -222,27 +217,47 @@ AM_CONDITIONAL(HAVE_CXX, test "x$HAVE_CXX" = "xyes") # Adam shostack suggests the following for Windows: # -D_FORTIFY_SOURCE=2 -fstack-protector-all AC_ARG_ENABLE(gcc-hardening, - AS_HELP_STRING(--enable-gcc-hardening, enable compiler security checks), -[if test x$enableval = xyes; then - AM_CFLAGS="$AM_CFLAGS -D_FORTIFY_SOURCE=2 -fstack-protector-all" - AM_CFLAGS="$AM_CFLAGS -fwrapv -fPIE -Wstack-protector" - AM_CFLAGS="$AM_CFLAGS --param ssp-buffer-size=1" - AM_LDFLAGS="$AM_LDFLAGS -pie" -fi]) + [AS_HELP_STRING(--enable-gcc-hardening, enable compiler security checks)], + [AS_IF([test x$enableval = xyes], + [AM_CFLAGS="$AM_CFLAGS -D_FORTIFY_SOURCE=2 -fstack-protector-all" + AM_CFLAGS="$AM_CFLAGS -fwrapv -fPIE -Wstack-protector" + AM_CFLAGS="$AM_CFLAGS --param ssp-buffer-size=1" + AM_LDFLAGS="$AM_LDFLAGS -pie"])]) # Linker hardening options # Currently these options are ELF specific - you can't use this with MacOSX AC_ARG_ENABLE(linker-hardening, - AS_HELP_STRING(--enable-linker-hardening, enable linker security fixups), -[if test x$enableval = xyes; then - AM_LDFLAGS="$AM_LDFLAGS -z relro -z now" -fi]) + [AS_HELP_STRING(--enable-linker-hardening, enable linker security fixups)], + [AS_IF([x$enableval = xyes], + [AM_LDFLAGS="$AM_LDFLAGS -z relro -z now"])]) + + +# Support for hiding non-public symbols +HIDDEN_VISIBILITY_CFLAGS="" +case "$host" in + *-*-mingw*) + dnl on mingw32 we do -fvisibility=hidden and __declspec(dllexport) + AC_DEFINE([_EXTRACTOR_EXTERN], [__attribute__((visibility("default"))) __declspec(dllexport) extern], + [defines how to decorate public symbols while building]) + HIDDEN_VISIBILITY_CFLAGS="-fvisibility=hidden" + ;; + *) + dnl on other compilers, check if we can do -fvisibility=hidden + AX_CHECK_LINK_FLAG([-fvisibility=hidden], + [AX_CHECK_COMPILE_FLAG([-fvisibility=hidden], + [AC_DEFINE([_EXTRACTOR_EXTERN], [__attribute__((visibility("default"))) extern], + [defines how to decorate public symbols while building]) + HIDDEN_VISIBILITY_CFLAGS="-fvisibility=hidden"])]) + ;; +esac +AC_SUBST(HIDDEN_VISIBILITY_CFLAGS) + # Checks for libraries. -AC_CHECK_HEADERS(langinfo.h) +AC_CHECK_HEADERS([langinfo.h]) # Check for libltdl header (#2999) ltdl=0 @@ -274,12 +289,9 @@ AC_ARG_WITH(ltdl, AC_CHECK_HEADERS(ltdl.h, AC_CHECK_LIB([ltdl], [lt_dlopenext], ltdl=1))]) -if test x$ltdl = x1 -then - AC_MSG_RESULT([libltdl found]) -else - AC_MSG_ERROR([libextractor requires libltdl (from GNU libtool), try installing libltdl-dev]) -fi +AS_IF([test x$ltdl = x1], + [AC_MSG_RESULT([libltdl found])], + [AC_MSG_ERROR([libextractor requires libltdl (from GNU libtool), try installing libltdl-dev])]) # check for apparmor AC_CHECK_LIB(apparmor, aa_change_profile, @@ -542,10 +554,8 @@ AC_LINK_IFELSE( LIBS="$SAVED_LIBS $SOCKET_LIBS" AC_LANG_POP(C) AC_MSG_RESULT([$sockets]) -if test "x$sockets" = "xno" -then - AC_MSG_ERROR([libextractor requires some kind of socket library]) -fi +AS_IF([test "x$sockets" = "xno"], + [AC_MSG_ERROR([libextractor requires some kind of socket library])]) AC_SUBST([SOCKET_LIBS],[$SOCKET_LIBS]) LE_LIB_LIBS=$LIBS @@ -574,22 +584,16 @@ AC_ARG_ENABLE(glib, esac], AC_MSG_RESULT(allowed)) -if test x$without_glib != xtrue -then - if test $with_gnu_ld = yes - then -# We need both GNU LD and GLIB here! - AM_CONDITIONAL(HAVE_GLIB,true) - AC_DEFINE(HAVE_GLIB, 1, [Have glib]) - else -# We may have GLIB, but without GNU LD we must not use it! - AM_CONDITIONAL(HAVE_GLIB,false) - AC_DEFINE(HAVE_GLIB, 0, [Have glib, but not GNU LD]) - fi -else - AM_CONDITIONAL(HAVE_GLIB,false) - AC_DEFINE(HAVE_GLIB, 0, [Have glib]) -fi +AS_IF([test x$without_glib != xtrue], + [AS_IF([test $with_gnu_ld = yes], + [# We need both GNU LD and GLIB here! + AM_CONDITIONAL(HAVE_GLIB,true) + AC_DEFINE(HAVE_GLIB, 1, [Have glib])], + [# We may have GLIB, but without GNU LD we must not use it! + AM_CONDITIONAL(HAVE_GLIB,false) + AC_DEFINE(HAVE_GLIB, 0, [Have glib, but not GNU LD])])], + [AM_CONDITIONAL(HAVE_GLIB,false) + AC_DEFINE(HAVE_GLIB, 0, [Have glib])]) # smf requires glib.h CFLAGS_OLD="$CFLAGS" @@ -609,13 +613,10 @@ AC_MSG_CHECKING(for gdk-pixbuf) PKG_CHECK_MODULES([GDK_PIXBUF], [gdk-pixbuf-2.0 >= 2.4], [have_gdk_pixbuf=yes], [have_gdk_pixbuf=no]) AM_CONDITIONAL(HAVE_GDK_PIXBUF, test x$have_gdk_pixbuf != xno) -if test $have_gdk_pixbuf != no -then - have_gdk_pixbuf=1 -else - have_gdk_pixbuf=0 - AC_MSG_NOTICE([Cannot find Gdk-pixbuf: Is pkg-config in path?]) -fi +AS_IF([test $have_gdk_pixbuf != no], + [have_gdk_pixbuf=1], + [have_gdk_pixbuf=0 + AC_MSG_NOTICE([Cannot find Gdk-pixbuf: Is pkg-config in path?])]) AC_DEFINE_UNQUOTED([HAVE_GDK_PIXBUF], [$have_gdk_pixbuf], [We have Gdk-pixbuf]) CFLAGS="$CFLAGS $GDK_PIXBUF_CFLAGS" @@ -670,9 +671,8 @@ AC_ARG_ENABLE(ffmpeg, esac], [ AC_MSG_RESULT(yes) ffmpeg_enabled=1]) -if test x$ffmpeg_enabled = x1 -then - ffmpeg_enabled=0 +AS_IF([test x$ffmpeg_enabled = x1], + [ffmpeg_enabled=0 new_ffmpeg=0 AC_CHECK_HEADERS([libavutil/avutil.h libavformat/avformat.h libavcodec/avcodec.h libavutil/frame.h], AC_CHECK_HEADERS([libavresample/avresample.h], @@ -683,7 +683,7 @@ then AC_CHECK_LIB(avcodec, avcodec_alloc_context3, ffmpeg_enabled=1)) AC_CHECK_HEADERS([libavutil/avutil.h ffmpeg/avutil.h libavformat/avformat.h ffmpeg/avformat.h libavcodec/avcodec.h ffmpeg/avcodec.h libswscale/swscale.h ffmpeg/swscale.h]) -fi + ]) AM_CONDITIONAL(HAVE_FFMPEG, test x$ffmpeg_enabled != x0) AM_CONDITIONAL(HAVE_FFMPEG_NEW, test x$new_ffmpeg != x0) diff --git a/src/include/extractor.h b/src/include/extractor.h index 37c9770..3e86868 100644 --- a/src/include/extractor.h +++ b/src/include/extractor.h @@ -35,10 +35,20 @@ extern "C" { * 0.2.6-1 => 0x00020601 * 4.5.2-0 => 0x04050200 */ -#define EXTRACTOR_VERSION 0x01080000 +#define EXTRACTOR_VERSION 0x01080001 #include +#ifndef _EXTRACTOR_EXTERN +#if defined(_WIN32) && defined(MHD_W32LIB) +#define _EXTRACTOR_EXTERN extern +#elif defined (_WIN32) && defined(MHD_W32DLL) +/* Define MHD_W32DLL when using MHD as W32 .DLL to speed up linker a little */ +#define _EXTRACTOR_EXTERN __declspec(dllimport) +#else +#define _EXTRACTOR_EXTERN extern +#endif +#endif /** * Options for how plugin execution should be done. @@ -402,7 +412,7 @@ enum EXTRACTOR_MetaType * translate using `dgettext ("libextractor", rval)` * @ingroup types */ -const char * +_EXTRACTOR_EXTERN const char * EXTRACTOR_metatype_to_string (enum EXTRACTOR_MetaType type); @@ -415,7 +425,7 @@ EXTRACTOR_metatype_to_string (enum EXTRACTOR_MetaType type); * translate using `dgettext ("libextractor", rval)` * @ingroup types */ -const char * +_EXTRACTOR_EXTERN const char * EXTRACTOR_metatype_to_description (enum EXTRACTOR_MetaType type); @@ -425,7 +435,7 @@ EXTRACTOR_metatype_to_description (enum EXTRACTOR_MetaType type); * @return highest legal metatype number for this version of libextractor * @ingroup types */ -enum EXTRACTOR_MetaType +_EXTRACTOR_EXTERN enum EXTRACTOR_MetaType EXTRACTOR_metatype_get_max (void); @@ -557,7 +567,7 @@ struct EXTRACTOR_PluginList; * @param flags options for all of the plugins loaded * @return the default set of plugins, NULL if no plugins were found */ -struct EXTRACTOR_PluginList * +_EXTRACTOR_EXTERN struct EXTRACTOR_PluginList * EXTRACTOR_plugin_add_defaults (enum EXTRACTOR_Options flags); @@ -570,7 +580,7 @@ EXTRACTOR_plugin_add_defaults (enum EXTRACTOR_Options flags); * @param flags options to use * @return the new list of libraries, equal to prev iff an error occured */ -struct EXTRACTOR_PluginList * +_EXTRACTOR_EXTERN struct EXTRACTOR_PluginList * EXTRACTOR_plugin_add (struct EXTRACTOR_PluginList * prev, const char *library, const char *options, @@ -592,7 +602,7 @@ EXTRACTOR_plugin_add (struct EXTRACTOR_PluginList * prev, * @return the new list of libraries, equal to prev iff an error occured * or if config was empty (or NULL). */ -struct EXTRACTOR_PluginList * +_EXTRACTOR_EXTERN struct EXTRACTOR_PluginList * EXTRACTOR_plugin_add_config (struct EXTRACTOR_PluginList *prev, const char *config, enum EXTRACTOR_Options flags); @@ -605,7 +615,7 @@ EXTRACTOR_plugin_add_config (struct EXTRACTOR_PluginList *prev, * @param library the name of the plugin to remove (short handle) * @return the reduced list, unchanged if the plugin was not loaded */ -struct EXTRACTOR_PluginList * +_EXTRACTOR_EXTERN struct EXTRACTOR_PluginList * EXTRACTOR_plugin_remove (struct EXTRACTOR_PluginList *prev, const char *library); @@ -615,7 +625,7 @@ EXTRACTOR_plugin_remove (struct EXTRACTOR_PluginList *prev, * * @param plugin the list of plugins */ -void +_EXTRACTOR_EXTERN void EXTRACTOR_plugin_remove_all (struct EXTRACTOR_PluginList *plugins); @@ -630,7 +640,7 @@ EXTRACTOR_plugin_remove_all (struct EXTRACTOR_PluginList *plugins); * @param proc function to call for each meta data item found * @param proc_cls cls argument to @a proc */ -void +_EXTRACTOR_EXTERN void EXTRACTOR_extract (struct EXTRACTOR_PluginList *plugins, const char *filename, const void *data, @@ -655,7 +665,7 @@ EXTRACTOR_extract (struct EXTRACTOR_PluginList *plugins, * @param data_len number of bytes in @a data * @return non-zero if printing failed, otherwise 0. */ -int +_EXTRACTOR_EXTERN int EXTRACTOR_meta_data_print (void *handle, const char *plugin_name, enum EXTRACTOR_MetaType type, diff --git a/src/main/Makefile.am b/src/main/Makefile.am index 56ac9e9..32f28bd 100644 --- a/src/main/Makefile.am +++ b/src/main/Makefile.am @@ -3,11 +3,13 @@ SUBDIRS = . AM_CPPFLAGS = -I$(top_srcdir)/src/include +AM_CFLAGS = $(HIDDEN_VISIBILITY_CFLAGS) + LIBS = \ @LE_LIBINTL@ @LE_LIB_LIBS@ if USE_COVERAGE - AM_CFLAGS = --coverage -O0 + AM_CFLAGS += --coverage -O0 XLIB = -lgcov endif diff --git a/src/main/test_extractor.c b/src/main/test_extractor.c index 52b1a59..8c15fca 100644 --- a/src/main/test_extractor.c +++ b/src/main/test_extractor.c @@ -36,7 +36,7 @@ #include #include - + /** * Signature of the extract method that each plugin @@ -44,7 +44,7 @@ * * @param ec extraction context provided to the plugin */ -void +_EXTRACTOR_EXTERN void EXTRACTOR_test_extract_method (struct EXTRACTOR_ExtractContext *ec) { void *dp; @@ -54,19 +54,19 @@ EXTRACTOR_test_extract_method (struct EXTRACTOR_ExtractContext *ec) if (4 != ec->read (ec->cls, &dp, 4)) { fprintf (stderr, "Reading at offset 0 failed\n"); - ABORT (); + ABORT (); } if (0 != strncmp ("test", dp, 4)) { fprintf (stderr, "Unexpected data at offset 0\n"); - ABORT (); + ABORT (); } if ( (1024 * 150 != ec->get_size (ec->cls)) && (UINT64_MAX != ec->get_size (ec->cls)) ) { fprintf (stderr, "Unexpected file size returned (expected 150k)\n"); - ABORT (); - } + ABORT (); + } if (1024 * 100 + 4 != ec->seek (ec->cls, 1024 * 100 + 4, SEEK_SET)) { fprintf (stderr, "Failure to seek (SEEK_SET)\n"); -- cgit v1.2.3