From 614624790d167e0ebff23b52edafc20f4cd26534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Mon, 5 Oct 2015 12:16:06 +0100 Subject: [PATCH 1/4] Fix compile error in net.c with musl libc fixes #278 --- ChangeLog | 8 +++++++- library/net.c | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 44f440819..5a8f63c7d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ mbed TLS ChangeLog (Sorted per branch, date) -= mbed TLS 1.3.13 reladsed 2015-09-17 += mbed TLS 1.3.14 released 2015-10-xx + +Bugfix + * Fix compile error in net.c with musl libc. Found and patch provided by + zhasha (#278). + += mbed TLS 1.3.13 released 2015-09-17 Security * Fix possible client-side NULL pointer dereference (read) when the client diff --git a/library/net.c b/library/net.c index 1fb68842e..dcbe480e2 100644 --- a/library/net.c +++ b/library/net.c @@ -428,7 +428,7 @@ int net_accept( int bind_fd, int *client_fd, void *client_ip ) #endif #if defined(__socklen_t_defined) || defined(_SOCKLEN_T) || \ - defined(_SOCKLEN_T_DECLARED) + defined(_SOCKLEN_T_DECLARED) || defined(__DEFINED_socklen_t) socklen_t n = (socklen_t) sizeof( client_addr ); #else int n = (int) sizeof( client_addr ); From ded3ae500b52265803f10142d9cdfed1d7aa227d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Mon, 5 Oct 2015 12:12:39 +0100 Subject: [PATCH 2/4] Add missing warning in doc Found by Nicholas Wilson fixes #288 --- include/polarssl/config.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/polarssl/config.h b/include/polarssl/config.h index 422c8be95..21aa9fa6a 100644 --- a/include/polarssl/config.h +++ b/include/polarssl/config.h @@ -1157,6 +1157,8 @@ * If set, the X509 parser will not break-off when parsing an X509 certificate * and encountering an unknown critical extension. * + * \warning Depending on your PKI use, enabling this can be a security risk! + * * Uncomment to prevent an error. */ //#define POLARSSL_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION From 20607bb0fa279d2c0118caffd61988930219bb62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Mon, 5 Oct 2015 11:40:01 +0100 Subject: [PATCH 3/4] Fix macroization of inline in C++ When compiling as C++, MSVC complains about our macroization of a keyword. Stop doing that as we know inline is always available in C++ --- ChangeLog | 1 + include/polarssl/cipher.h | 6 ++---- include/polarssl/compat-1.2.h | 9 +++------ include/polarssl/md.h | 9 +++------ include/polarssl/pkcs11.h | 6 ++---- include/polarssl/ssl.h | 9 +++------ library/ecp.c | 9 +++------ library/ecp_curves.c | 6 ++---- 8 files changed, 19 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5a8f63c7d..8dac7a494 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ mbed TLS ChangeLog (Sorted per branch, date) Bugfix * Fix compile error in net.c with musl libc. Found and patch provided by zhasha (#278). + * Fix macroization of 'inline' keywork when building as C++. (#279) = mbed TLS 1.3.13 released 2015-09-17 diff --git a/include/polarssl/cipher.h b/include/polarssl/cipher.h index 00c42c1d4..f4be4ab3d 100644 --- a/include/polarssl/cipher.h +++ b/include/polarssl/cipher.h @@ -47,10 +47,8 @@ #define POLARSSL_CIPHER_MODE_STREAM #endif -#if defined(_MSC_VER) && !defined(inline) -#define inline _inline -#else -#if defined(__ARMCC_VERSION) && !defined(inline) +#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ + !defined(inline) && !defined(__cplusplus) #define inline __inline #endif /* __ARMCC_VERSION */ #endif /*_MSC_VER */ diff --git a/include/polarssl/compat-1.2.h b/include/polarssl/compat-1.2.h index d694015e4..37df5412f 100644 --- a/include/polarssl/compat-1.2.h +++ b/include/polarssl/compat-1.2.h @@ -41,13 +41,10 @@ // Comment out to disable prototype change warnings #define SHOW_PROTOTYPE_CHANGE_WARNINGS -#if defined(_MSC_VER) && !defined(inline) -#define inline _inline -#else -#if defined(__ARMCC_VERSION) && !defined(inline) +#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ + !defined(inline) && !defined(__cplusplus) #define inline __inline -#endif /* __ARMCC_VERSION */ -#endif /* _MSC_VER */ +#endif #if defined(_MSC_VER) // MSVC does not support #warning diff --git a/include/polarssl/md.h b/include/polarssl/md.h index 303aee820..fc7482a4b 100644 --- a/include/polarssl/md.h +++ b/include/polarssl/md.h @@ -28,13 +28,10 @@ #include -#if defined(_MSC_VER) && !defined(inline) -#define inline _inline -#else -#if defined(__ARMCC_VERSION) && !defined(inline) +#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ + !defined(inline) && !defined(__cplusplus) #define inline __inline -#endif /* __ARMCC_VERSION */ -#endif /*_MSC_VER */ +#endif #define POLARSSL_ERR_MD_FEATURE_UNAVAILABLE -0x5080 /**< The selected feature is not available. */ #define POLARSSL_ERR_MD_BAD_INPUT_DATA -0x5100 /**< Bad input parameters to function. */ diff --git a/include/polarssl/pkcs11.h b/include/polarssl/pkcs11.h index 18c3370fc..80be23faf 100644 --- a/include/polarssl/pkcs11.h +++ b/include/polarssl/pkcs11.h @@ -38,10 +38,8 @@ #include -#if defined(_MSC_VER) && !defined(inline) -#define inline _inline -#else -#if defined(__ARMCC_VERSION) && !defined(inline) +#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ + !defined(inline) && !defined(__cplusplus) #define inline __inline #endif /* __ARMCC_VERSION */ #endif /*_MSC_VER */ diff --git a/include/polarssl/ssl.h b/include/polarssl/ssl.h index 1f9f8be63..3b67d3860 100644 --- a/include/polarssl/ssl.h +++ b/include/polarssl/ssl.h @@ -97,13 +97,10 @@ #define POLARSSL_KEY_EXCHANGE__SOME__ECDHE_ENABLED #endif -#if defined(_MSC_VER) && !defined(inline) -#define inline _inline -#else -#if defined(__ARMCC_VERSION) && !defined(inline) +#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ + !defined(inline) && !defined(__cplusplus) #define inline __inline -#endif /* __ARMCC_VERSION */ -#endif /*_MSC_VER */ +#endif /* * SSL Error codes diff --git a/library/ecp.c b/library/ecp.c index adef09ea8..796452baf 100644 --- a/library/ecp.c +++ b/library/ecp.c @@ -68,13 +68,10 @@ #define strcasecmp _stricmp #endif -#if defined(_MSC_VER) && !defined(inline) -#define inline _inline -#else -#if defined(__ARMCC_VERSION) && !defined(inline) +#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ + !defined(inline) && !defined(__cplusplus) #define inline __inline -#endif /* __ARMCC_VERSION */ -#endif /*_MSC_VER */ +#endif /* Implementation that should never be optimized out by the compiler */ static void polarssl_zeroize( void *v, size_t n ) { diff --git a/library/ecp_curves.c b/library/ecp_curves.c index 3786356c3..7d26cb5b2 100644 --- a/library/ecp_curves.c +++ b/library/ecp_curves.c @@ -32,10 +32,8 @@ #include -#if defined(_MSC_VER) && !defined(inline) -#define inline _inline -#else -#if defined(__ARMCC_VERSION) && !defined(inline) +#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ + !defined(inline) && !defined(__cplusplus) #define inline __inline #endif /* __ARMCC_VERSION */ #endif /*_MSC_VER */ From cf1db3cf1c0ad995837c475e268754211059af27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Mon, 5 Oct 2015 14:57:01 +0100 Subject: [PATCH 4/4] Fix spurious #endif from previous cherry-pick --- include/polarssl/cipher.h | 3 +-- include/polarssl/pkcs11.h | 3 +-- library/ecp_curves.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/include/polarssl/cipher.h b/include/polarssl/cipher.h index f4be4ab3d..bde1d4706 100644 --- a/include/polarssl/cipher.h +++ b/include/polarssl/cipher.h @@ -50,8 +50,7 @@ #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ !defined(inline) && !defined(__cplusplus) #define inline __inline -#endif /* __ARMCC_VERSION */ -#endif /*_MSC_VER */ +#endif #define POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE -0x6080 /**< The selected feature is not available. */ #define POLARSSL_ERR_CIPHER_BAD_INPUT_DATA -0x6100 /**< Bad input parameters to function. */ diff --git a/include/polarssl/pkcs11.h b/include/polarssl/pkcs11.h index 80be23faf..4ca4a4cdf 100644 --- a/include/polarssl/pkcs11.h +++ b/include/polarssl/pkcs11.h @@ -41,8 +41,7 @@ #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ !defined(inline) && !defined(__cplusplus) #define inline __inline -#endif /* __ARMCC_VERSION */ -#endif /*_MSC_VER */ +#endif #ifdef __cplusplus extern "C" { diff --git a/library/ecp_curves.c b/library/ecp_curves.c index 7d26cb5b2..f5afe44b5 100644 --- a/library/ecp_curves.c +++ b/library/ecp_curves.c @@ -35,8 +35,7 @@ #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ !defined(inline) && !defined(__cplusplus) #define inline __inline -#endif /* __ARMCC_VERSION */ -#endif /*_MSC_VER */ +#endif /* * Conversion macros for embedded constants: