Skip to content

Commit

Permalink
Avoid flexible arrays on unsupported platforms via a macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
kareem-wolfssl committed May 15, 2024
1 parent c73e433 commit d4da6f8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions wolfssl/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions wolfssl/wolfcrypt/wc_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d4da6f8

Please sign in to comment.