diff --git a/ChangeLog b/ChangeLog index 914445101..1d995c8a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -193,6 +193,10 @@ Features errors on use of deprecated functions. Bugfix + * Fix compile errors with PLATFORM_NO_STD_FUNCTIONS. + * Fix compile error with PLATFORM_EXIT_ALT (thanks to Rafał Przywara). + * Fix bug in entropy.c when THREADING_C is also enabled that caused + entropy_free() to crash (thanks to Rafał Przywara). * Fix memory leak when gcm_setkey() and ccm_setkey() are used more than once on the same context. * Fix bug in ssl_mail_client when password is longer that username (found @@ -285,8 +289,6 @@ Features ciphersuite/certificate. Bugfix - * Fix bug in entropy.c when THREADING_C is also enabled that caused - entropy_free() to crash (found and fixed by ptahpeteh). * Stack buffer overflow if ctr_drbg_update() is called with too large add_len (found by Jean-Philippe Aumasson) (not triggerable remotely). * Possible buffer overflow of length at most POLARSSL_MEMORY_ALIGN_MULTIPLE diff --git a/include/mbedtls/platform.h b/include/mbedtls/platform.h index aa97d8d40..b71a09cf9 100644 --- a/include/mbedtls/platform.h +++ b/include/mbedtls/platform.h @@ -80,6 +80,8 @@ extern "C" { #define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO #define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO #else +/* For size_t */ +#include extern void * (*mbedtls_calloc)( size_t n, size_t size ); extern void (*mbedtls_free)( void *ptr ); @@ -103,6 +105,8 @@ int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ), * The function pointers for fprintf */ #if defined(MBEDTLS_PLATFORM_FPRINTF_ALT) +/* We need FILE * */ +#include extern int (*mbedtls_fprintf)( FILE *stream, const char *format, ... ); /** diff --git a/library/platform.c b/library/platform.c index e9ab3024e..123267a8a 100644 --- a/library/platform.c +++ b/library/platform.c @@ -73,7 +73,7 @@ static int platform_snprintf_uninit( char * s, size_t n, { ((void) s); ((void) n); - ((void) format) + ((void) format); return( 0 ); } @@ -149,13 +149,12 @@ int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... static void platform_exit_uninit( int status ) { ((void) status); - return( 0 ); } #define MBEDTLS_PLATFORM_STD_EXIT platform_exit_uninit #endif /* !MBEDTLS_PLATFORM_STD_EXIT */ -int (*mbedtls_exit)( int status ) = MBEDTLS_PLATFORM_STD_EXIT; +void (*mbedtls_exit)( int status ) = MBEDTLS_PLATFORM_STD_EXIT; int mbedtls_platform_set_exit( void (*exit_func)( int status ) ) { diff --git a/scripts/config.pl b/scripts/config.pl index 7d6c4ea05..2685b4ec3 100755 --- a/scripts/config.pl +++ b/scripts/config.pl @@ -35,6 +35,11 @@ MBEDTLS_PKCS11_C _ALT\s*$ ); +# Things that should be enabled in "full" even if they match @excluded +my @non_excluded = qw( +PLATFORM_[A-Z0-9]+_ALT +); + my $config_file = "include/mbedtls/config.h"; # get -f option @@ -75,6 +80,7 @@ my @config_lines = <$config_read>; close $config_read; my $exclude_re = join '|', @excluded; +my $no_exclude_re = join '|', @non_excluded; open my $config_write, '>', $config_file or die "write $config_file: $!\n"; @@ -85,10 +91,12 @@ for my $line (@config_lines) { $done = 1; } - if (!$done && $line =~ m!^//\s?#define! && $line !~ /$exclude_re/) { + if (!$done && $line =~ m!^//\s?#define! && + ( $line !~ /$exclude_re/ || $line =~ /$no_exclude_re/ ) ) { $line =~ s!^//\s?!!; } - if (!$done && $line =~ m!^\s?#define! && $line =~ /$exclude_re/) { + if (!$done && $line =~ m!^\s?#define! && + ! ( $line !~ /$exclude_re/ || $line =~ /$no_exclude_re/ ) ) { $line =~ s!^!//!; } } elsif ($action eq "unset") { diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 85eac010e..e4da7b659 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -152,6 +152,14 @@ scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C scripts/config.pl unset MBEDTLS_FS_IO CC=gcc CFLAGS='-Werror -O0' make +# catch compile bugs in _uninit functions +msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s +cleanup +cp "$CONFIG_H" "$CONFIG_BAK" +scripts/config.pl full +scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS +CC=gcc CFLAGS='-Werror -O0' make + msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s cleanup cp "$CONFIG_H" "$CONFIG_BAK"