From bef22ce53428befb105b342fed2d8d76213793e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Sat, 14 Apr 2007 16:19:09 +0200 Subject: Define XINE_PACKED also in attributes.h for frontends. --- src/xine-utils/attributes.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/xine-utils/attributes.h b/src/xine-utils/attributes.h index 27c6fc5bc..649c1aa43 100644 --- a/src/xine-utils/attributes.h +++ b/src/xine-utils/attributes.h @@ -69,4 +69,10 @@ # define XINE_FORMAT_PRINTF_ARG(fmt) #endif +#ifdef SUPPORT_ATTRIBUTE_PACKED +# define XINE_PACKED __attribute__((packed)) +#else +# define XINE_PACKED +#endif + #endif /* ATTRIBUTE_H_ */ -- cgit v1.2.3 From 9c7b147a1878bd2c9290bb3377f41bc4a27ddccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Sat, 14 Apr 2007 16:27:55 +0200 Subject: Cleanup CPPFLAGS, remove LIBFFMPEG_CPPFLAGS as ffmpeg's configure takes care of it. --- configure.ac | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index f003d22c8..5920e2ea1 100644 --- a/configure.ac +++ b/configure.ac @@ -374,9 +374,6 @@ use internal ffmpeg. *********************************************************************]) else AC_MSG_RESULT([using included ffmpeg]) - LIBFFMPEG_CPPFLAGS="-DHAVE_AV_CONFIG_H -DRUNTIME_CPUDETECT -DXINE_MPEG_ENCODER -D_ISOC9X_SOURCE -DCONFIG_DECODERS" - AC_CHECK_TYPES(int_fast8_t, [], [LIBFFMPEG_CPPFLAGS="$LIBFFMPEG_CPPFLAGS -DEMULATE_FAST_INT"]) - AC_SUBST([LIBFFMPEG_CPPFLAGS]) fi AM_CONDITIONAL(HAVE_FFMPEG, test "x$with_external_ffmpeg" = "xyes") @@ -2560,13 +2557,14 @@ esac AC_SUBST([NOUNDEF]) dnl Common cflags for all platforms -CFLAGS="-D_REENTRANT -D_FILE_OFFSET_BITS=64 -DXINE_COMPILE \$(MULTIPASS_CFLAGS) $warnflags $CFLAGS" -DEBUG_CFLAGS="-D_REENTRANT -D_FILE_OFFSET_BITS=64 -DXINE_COMPILE $DEBUG_CFLAGS" +CPPFLAGS="-D_REENTRANT -D_FILE_OFFSET_BITS=64 -DXINE_COMPILE $CPPFLAGS" +CFLAGS="\$(MULTIPASS_CFLAGS) $warnflags $CFLAGS" +DEBUG_CFLAGS="$warnflags $DEBUG_CFLAGS" if test "x$enable_debug" = "xyes"; then - CFLAGS="$CFLAGS -DDEBUG" + CPPFLAGS="$CPPFLAGS -DDEBUG" else - CFLAGS="$CFLAGS -DNDEBUG" + CPPFLAGS="$CPPFLAGS -DNDEBUG" fi dnl --------------------------------------------- -- cgit v1.2.3 From b10d5cccee5d2945b1924a732a9b7d9d79d91b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Sat, 14 Apr 2007 17:12:05 +0200 Subject: Add a xine_xcalloc function to wrap around calloc(), to improve security from now on. --- src/xine-utils/utils.c | 21 +++++++++++++++++++++ src/xine-utils/xineutils.h | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c index fa0c11dbe..63c2e2f09 100644 --- a/src/xine-utils/utils.c +++ b/src/xine-utils/utils.c @@ -256,6 +256,27 @@ void *xine_xmalloc(size_t size) { return ptr; } +/** + * @brief Wrapper around calloc() function. + * @param nmemb Number of elements to allocate + * @param size Size of each element to allocate + * + * This is a simple wrapper around calloc(), the only thing + * it does more than calloc() is outputting an error if + * the calloc fails (returning NULL). + */ +void *xine_xcalloc(size_t nmemb, size_t size) { + void *ptr; + + if((ptr = calloc(nmemb, size)) == NULL) { + fprintf(stderr, "%s: calloc() failed: %s.\n", + __XINE_FUNCTION__, strerror(errno)); + return NULL; + } + + return ptr; +} + void *xine_xmalloc_aligned(size_t alignment, size_t size, void **base) { char *ptr; diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h index 03c5f689a..20c3cb2dc 100644 --- a/src/xine-utils/xineutils.h +++ b/src/xine-utils/xineutils.h @@ -630,6 +630,12 @@ void *xine_xmalloc(size_t size) XINE_PROTECTED; void *xine_xmalloc(size_t size) __attribute__ ((__malloc__)) XINE_PROTECTED; #endif +#if !defined(__GNUC__) || __GNUC__ < 3 +void *xine_xcalloc(size_t nmemb, size_t size) XINE_PROTECTED; +#else +void *xine_xcalloc(size_t nmemb, size_t size) __attribute__ ((__malloc__)) XINE_PROTECTED; +#endif + /* * Same as above, but memory is aligned to 'alignement'. * **base is used to return pointer to un-aligned memory, use -- cgit v1.2.3 From d8728d7219ceb91d9bddda4064d91f83558b44b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Sat, 14 Apr 2007 17:25:54 +0200 Subject: Check for __malloc__ attribute during configure stage, avoid conditional in xineutils.h for it, instead use XINE_MALLOC. --- configure.ac | 2 ++ doc/Doxyfile.in | 2 +- m4/attributes.m4 | 20 ++++++++++++++++++++ src/xine-utils/attributes.h | 6 ++++++ src/xine-utils/xineutils.h | 12 ++---------- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index 5920e2ea1..1ccd1005b 100644 --- a/configure.ac +++ b/configure.ac @@ -2127,6 +2127,8 @@ CC_ATTRIBUTE_PACKED( AC_DEFINE([XINE_PACKED], [], [Dummy mark a structure as being packed])] ) +CC_ATTRIBUTE_MALLOC + CC_ATTRIBUTE_VISIBILITY([protected], [visibility_export="protected"], [CC_ATTRIBUTE_VISIBILITY([default], [visibility_export="default"])] ) diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in index 09e016c5b..59f04af46 100644 --- a/doc/Doxyfile.in +++ b/doc/Doxyfile.in @@ -796,7 +796,7 @@ INCLUDE_FILE_PATTERNS = # instead of the = operator. PREDEFINED = XINE_COMPILE XINE_PACKED= ATTR_ALIGN(x)= -PREDEFINED += XINE_PROTECTED= +PREDEFINED += XINE_PROTECTED= XINE_MALLOC= # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded. diff --git a/m4/attributes.m4 b/m4/attributes.m4 index c46715d0e..23b5f2ee4 100644 --- a/m4/attributes.m4 +++ b/m4/attributes.m4 @@ -342,3 +342,23 @@ AC_DEFUN([CC_ATTRIBUTE_PACKED], [ ifelse([$2], , [:], [$2]) fi ]) + +AC_DEFUN([CC_ATTRIBUTE_MALLOC], [ + AC_REQUIRE([CC_CHECK_WERROR]) + AC_CACHE_CHECK([if $CC supports __attribute__((__malloc__))], + [cc_cv_attribute_malloc], + [ac_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $cc_cv_werror" + AC_COMPILE_IFELSE([void *fooalloc(int size) __attribute__((__malloc__));], + [cc_cv_attribute_malloc=yes], + [cc_cv_attribute_malloc=no]) + CFLAGS="$ac_save_CFLAGS" + ]) + + if test x$cc_cv_attribute_malloc = xyes; then + AC_DEFINE([SUPPORT_ATTRIBUTE_MALLOC], 1, [Define this if the compiler supports __attribute__((__malloc__))]) + ifelse([$1], , [:], [$1]) + else + ifelse([$2], , [:], [$2]) + fi +]) diff --git a/src/xine-utils/attributes.h b/src/xine-utils/attributes.h index 649c1aa43..e257a48dd 100644 --- a/src/xine-utils/attributes.h +++ b/src/xine-utils/attributes.h @@ -75,4 +75,10 @@ # define XINE_PACKED #endif +#ifdef SUPPORT_ATTRIBUTE_MALLOC +# define XINE_MALLOC __attributes__((__malloc__)) +#else +# define XINE_MALLOC +#endif + #endif /* ATTRIBUTE_H_ */ diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h index 20c3cb2dc..0be29ff63 100644 --- a/src/xine-utils/xineutils.h +++ b/src/xine-utils/xineutils.h @@ -624,17 +624,9 @@ void xine_profiler_print_results (void) XINE_PROTECTED; * Allocate and clean memory size_t 'size', then return the pointer * to the allocated memory. */ -#if !defined(__GNUC__) || __GNUC__ < 3 -void *xine_xmalloc(size_t size) XINE_PROTECTED; -#else -void *xine_xmalloc(size_t size) __attribute__ ((__malloc__)) XINE_PROTECTED; -#endif +void *xine_xmalloc(size_t size) XINE_MALLOC XINE_PROTECTED; -#if !defined(__GNUC__) || __GNUC__ < 3 -void *xine_xcalloc(size_t nmemb, size_t size) XINE_PROTECTED; -#else -void *xine_xcalloc(size_t nmemb, size_t size) __attribute__ ((__malloc__)) XINE_PROTECTED; -#endif +void *xine_xcalloc(size_t nmemb, size_t size) XINE_MALLOC XINE_PROTECTED; /* * Same as above, but memory is aligned to 'alignement'. -- cgit v1.2.3 From abd68bd5e0a4dd2c6b417b8fbfbbbeeccb69f00f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Sat, 14 Apr 2007 17:28:24 +0200 Subject: Add use of xine_xcalloc to the TODO list. --- TODO | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TODO b/TODO index 7b41e27cf..1745fa97a 100644 --- a/TODO +++ b/TODO @@ -6,6 +6,8 @@ For 1.3 series For 1.2 series ============== +- Security-Related: start using xine_xcalloc rather than xine_xmalloc when + the number of elements is not a build-time constant. - mimetype-based demuxer selection, solves the effects of shoutcast's bug; - Doxygen API documentation for both internal and public functions; - removal of (deprecated) software deinterlacers from video output plugins; -- cgit v1.2.3 From ddfc67a5df8a1e0d18559372d6fbc25ae94935e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Sat, 14 Apr 2007 17:30:22 +0200 Subject: Add ChangeLog entries for the XDG Base Directory Specification changes. --- ChangeLog | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChangeLog b/ChangeLog index da07f05ad..8c88c57aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,10 @@ xine-lib (1.1.90) (Unreleased) to separate from xine's own code. * Save plugins' cache in the defined cache home directory as per XDG Base Directory Specification. + * Use XDG-defined cache home directory for cddb cache. + * Use XDG-defined cache home directory for win32codecs fake registry. + * Use XDG-defined data directories to look up fonts files both while using + FreeType2 and the standard bitmap fonts for OSD. xine-lib (1.1.6) [UNRELEASED] * Split the DirectFB plugin into X11 and non-X versions. -- cgit v1.2.3 From 5f701693bfa7357ec08114c03963f6f5e9ef1836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Sat, 14 Apr 2007 17:33:05 +0200 Subject: Fix typo injected at savetime. --- src/xine-utils/attributes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xine-utils/attributes.h b/src/xine-utils/attributes.h index e257a48dd..80bcadd7f 100644 --- a/src/xine-utils/attributes.h +++ b/src/xine-utils/attributes.h @@ -76,7 +76,7 @@ #endif #ifdef SUPPORT_ATTRIBUTE_MALLOC -# define XINE_MALLOC __attributes__((__malloc__)) +# define XINE_MALLOC __attribute__((__malloc__)) #else # define XINE_MALLOC #endif -- cgit v1.2.3 From dc36f8d045cf4f723c44766f44c92e1810e37f4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Sat, 14 Apr 2007 17:52:39 +0200 Subject: Mark string arrays as arrays of constant pointers, and do the same for memcpy structures. When array of constant pointers are used for register enum configurations, this creates more warnings because of pointer mismatches; I'd consider casting them, but not yet. In the memcpy_method array, mark the parts that are constant at build time as const so to try reducing the overhead. --- src/input/input_dvd.c | 4 ++-- src/input/input_mms.c | 14 +++++++------- src/input/vcd/xineplug_inp_vcd.c | 4 ++-- src/libsputext/xine_sputext_decoder.c | 2 +- src/video_out/deinterlace.h | 2 +- src/video_out/video_out_directfb.c | 4 ++-- src/xine-engine/xine.c | 4 ++-- src/xine-utils/memcpy.c | 6 +++--- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/input/input_dvd.c b/src/input/input_dvd.c index 23a0aad64..ac09e934b 100644 --- a/src/input/input_dvd.c +++ b/src/input/input_dvd.c @@ -158,7 +158,7 @@ # define lseek64 lseek #endif -static const char *dvdnav_menu_table[] = { +static const char *const dvdnav_menu_table[] = { NULL, NULL, "Title", @@ -1791,7 +1791,7 @@ static void *init_class (xine_t *xine, void *data) { { /* we have found libdvdcss, enable the specific config options */ char *raw_device; - static const char *decrypt_modes[] = { "key", "disc", "title", NULL }; + static const char *const decrypt_modes[] = { "key", "disc", "title", NULL }; int mode; raw_device = config->register_filename(config, "media.dvd.raw_device", diff --git a/src/input/input_mms.c b/src/input/input_mms.c index 05c0b168b..739d81a59 100644 --- a/src/input/input_mms.c +++ b/src/input/input_mms.c @@ -59,15 +59,15 @@ static const uint32_t mms_bandwidths[]={14400,19200,28800,33600,34430,57600, 115200,262200,393216,524300,1544000,10485800}; -static const char * mms_bandwidth_strs[]={"14.4 Kbps (Modem)", "19.2 Kbps (Modem)", - "28.8 Kbps (Modem)", "33.6 Kbps (Modem)", - "34.4 Kbps (Modem)", "57.6 Kbps (Modem)", - "115.2 Kbps (ISDN)", "262.2 Kbps (Cable/DSL)", - "393.2 Kbps (Cable/DSL)","524.3 Kbps (Cable/DSL)", - "1.5 Mbps (T1)", "10.5 Mbps (LAN)", NULL}; +static const char *const mms_bandwidth_strs[]={"14.4 Kbps (Modem)", "19.2 Kbps (Modem)", + "28.8 Kbps (Modem)", "33.6 Kbps (Modem)", + "34.4 Kbps (Modem)", "57.6 Kbps (Modem)", + "115.2 Kbps (ISDN)", "262.2 Kbps (Cable/DSL)", + "393.2 Kbps (Cable/DSL)","524.3 Kbps (Cable/DSL)", + "1.5 Mbps (T1)", "10.5 Mbps (LAN)", NULL}; /* connection methods */ -static const char *mms_protocol_strs[]={"auto", "TCP", "HTTP", NULL}; +static const char *const mms_protocol_strs[]={"auto", "TCP", "HTTP", NULL}; typedef struct { input_plugin_t input_plugin; diff --git a/src/input/vcd/xineplug_inp_vcd.c b/src/input/vcd/xineplug_inp_vcd.c index a15899f2d..b234be6d1 100644 --- a/src/input/vcd/xineplug_inp_vcd.c +++ b/src/input/vcd/xineplug_inp_vcd.c @@ -1807,13 +1807,13 @@ vcd_init (xine_t *xine, void *data) /*Note: these labels have to be listed in the same order as the enumeration vcdplayer_autoplay_t in vcdplayer.h. */ - static const char *autoplay_modes[] = + static const char *const autoplay_modes[] = { "MPEG track", "entry", "segment", "playback-control item", NULL }; /*Note: these labels have to be listed in the same order as the enumeration vcdplayer_slider_length_t in vcdplayer.h. */ - static const char *length_reporting_modes[] = + static const char *const length_reporting_modes[] = { "auto", "track", "entry", NULL }; my_vcd.player.default_autoplay = diff --git a/src/libsputext/xine_sputext_decoder.c b/src/libsputext/xine_sputext_decoder.c index e8ef631ca..d4dd103ec 100644 --- a/src/libsputext/xine_sputext_decoder.c +++ b/src/libsputext/xine_sputext_decoder.c @@ -925,7 +925,7 @@ static void update_src_encoding(void *class_gen, xine_cfg_entry_t *entry) static void *init_spu_decoder_plugin (xine_t *xine, void *data) { - static const char *subtitle_size_strings[] = { + static const char *const subtitle_size_strings[] = { "tiny", "small", "normal", "large", "very large", "huge", NULL }; sputext_class_t *this ; diff --git a/src/video_out/deinterlace.h b/src/video_out/deinterlace.h index a9904b42a..6f398fcbd 100644 --- a/src/video_out/deinterlace.h +++ b/src/video_out/deinterlace.h @@ -41,7 +41,7 @@ void deinterlace_yuv( uint8_t *pdst, uint8_t *psrc[], #define DEINTERLACE_ONEFIELDXV 5 #define DEINTERLACE_LINEARBLEND 6 -static const char *deinterlace_methods[] = { +static const char *const deinterlace_methods[] = { "none", "bob", "weave", diff --git a/src/video_out/video_out_directfb.c b/src/video_out/video_out_directfb.c index efbb30f2d..a374c56de 100644 --- a/src/video_out/video_out_directfb.c +++ b/src/video_out/video_out_directfb.c @@ -1333,8 +1333,8 @@ static void update_config_cb (void *data, xine_cfg_entry_t *entry) { static void init_config (directfb_driver_t *this) { config_values_t *config = this->xine->config; - static const char *buffermode_enum[] = {"single", "double", "triple", 0}; - static const char *fieldparity_enum[] = {"none", "top", "bottom", 0}; + static const char *const buffermode_enum[] = {"single", "double", "triple", 0}; + static const char *const fieldparity_enum[] = {"none", "top", "bottom", 0}; this->buffermode = config->register_enum (config, "video.device.directfb_buffermode", this->buffermode, (char**)buffermode_enum, diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index 402aaec66..6661ea102 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -1539,8 +1539,8 @@ static void config_save_cb (void *this_gen, xine_cfg_entry_t *entry) { } void xine_init (xine_t *this) { - static const char *demux_strategies[] = {"default", "reverse", "content", - "extension", NULL}; + static const char *const demux_strategies[] = {"default", "reverse", "content", + "extension", NULL}; /* First of all, initialise libxdg-basedir as it's used by plugins. */ this->basedir_handle = xdgAllocHandle(); diff --git a/src/xine-utils/memcpy.c b/src/xine-utils/memcpy.c index 539f4c8dd..67645081e 100644 --- a/src/xine-utils/memcpy.c +++ b/src/xine-utils/memcpy.c @@ -383,8 +383,8 @@ static void *linux_kernel_memcpy(void *to, const void *from, size_t len) { #endif /* ARCH_X86 */ static struct { - char *name; - void *(* function)(void *to, const void *from, size_t len); + char *const name; + void *(*const function)(void *to, const void *from, size_t len); uint64_t time; /* This type could be used for non-MSC build too! */ @@ -461,7 +461,7 @@ void xine_probe_fast_memcpy(xine_t *xine) char *buf1, *buf2; int i, j, best; int config_flags = -1; - static const char *memcpy_methods[] = { + static const char *const memcpy_methods[] = { "probe", "libc", #if (defined(ARCH_X86) || defined(ARCH_X86_64)) && !defined(_MSC_VER) "kernel", "mmx", "mmxext", "sse", -- cgit v1.2.3