From d4da6f84e2e8bc550868a918ce9087a7bc4de224 Mon Sep 17 00:00:00 2001 From: Kareem Date: Wed, 15 May 2024 11:45:30 -0700 Subject: [PATCH] Avoid flexible arrays on unsupported platforms via a macro. --- src/dtls.c | 2 +- wolfssl/internal.h | 6 +++--- wolfssl/wolfcrypt/wc_port.h | 9 +++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/dtls.c b/src/dtls.c index ba7760dc94..43cf61f775 100644 --- a/src/dtls.c +++ b/src/dtls.c @@ -1040,7 +1040,7 @@ typedef struct ConnectionID { #ifdef _MSC_VER #pragma warning(disable: 4200) #endif - byte id[]; + byte id[WOLFSSL_FLEXIBLE_ARRAY_SIZE]; } ConnectionID; typedef struct CIDInfo { diff --git a/wolfssl/internal.h b/wolfssl/internal.h index c2d412986a..3b41b9c98a 100644 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -3175,7 +3175,7 @@ typedef struct SignatureAlgorithms { #ifdef _MSC_VER #pragma warning(disable: 4200) #endif - byte hashSigAlgo[]; /* sig/algo to offer */ + byte hashSigAlgo[WOLFSSL_FLEXIBLE_ARRAY_SIZE]; /* sig/algo to offer */ } SignatureAlgorithms; WOLFSSL_LOCAL SignatureAlgorithms* TLSX_SignatureAlgorithms_New( @@ -3353,7 +3353,7 @@ typedef struct Cookie { #ifdef _MSC_VER #pragma warning(disable: 4200) #endif - byte data[]; + byte data[WOLFSSL_FLEXIBLE_ARRAY_SIZE]; } Cookie; WOLFSSL_LOCAL int TLSX_Cookie_Use(const WOLFSSL* ssl, const byte* data, @@ -5213,7 +5213,7 @@ typedef struct DtlsFragBucket { #ifdef _MSC_VER #pragma warning(disable: 4200) #endif - byte buf[]; + byte buf[WOLFSSL_FLEXIBLE_ARRAY_SIZE]; } DtlsFragBucket; typedef struct DtlsMsg { diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 878e31913f..4cc62accb0 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -1267,6 +1267,15 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void); #endif #endif +#if defined(__STRICT_ANSI__) + #define WOLFSSL_FLEXIBLE_ARRAY_SIZE 1 +#elif defined(__GNUC__) && !defined(__clang__) + #define WOLFSSL_FLEXIBLE_ARRAY_SIZE + /*!< \brief Value appropriate as a size for an array that will be allocated to a variable size. Built-in value usually works. */ +#else + #define WOLFSSL_FLEXIBLE_ARRAY_SIZE 0 +#endif + #ifdef __cplusplus } /* extern "C" */ #endif