Skip to content

Commit

Permalink
wolfssl/wolfcrypt/types.h: add static_assert() definitions;
Browse files Browse the repository at this point in the history
wolfssl/internal.h: add DTLS13_HANDSHAKE_HEADER_SZ;

src/tls13.c: in EchHashHelloInner(), use falseHeader[DTLS13_HANDSHAKE_HEADER_SZ] to fix buffer overrun;

src/dtls13.c: add static assert for DTLS13_HANDSHAKE_HEADER_SZ.
  • Loading branch information
douzzer committed Sep 19, 2024
1 parent 263cb5b commit fbbb2b8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/dtls13.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ typedef struct Dtls13HandshakeHeader {
byte fragmentLength[3];
} Dtls13HandshakeHeader;

static_assert(sizeof(Dtls13HandshakeHeader) == DTLS13_HANDSHAKE_HEADER_SZ);

/**
* struct Dtls13Recordplaintextheader: represent header of unprotected DTLSv1.3
* record
Expand Down
4 changes: 4 additions & 0 deletions src/tls13.c
Original file line number Diff line number Diff line change
Expand Up @@ -4165,7 +4165,11 @@ static int EchHashHelloInner(WOLFSSL* ssl, WOLFSSL_ECH* ech)
{
int ret;
HS_Hashes* tmpHashes;
#ifdef WOLFSSL_DTLS13
byte falseHeader[DTLS13_HANDSHAKE_HEADER_SZ];
#else
byte falseHeader[HANDSHAKE_HEADER_SZ];
#endif

if (ssl == NULL || ech == NULL)
return BAD_FUNC_ARG;
Expand Down
1 change: 1 addition & 0 deletions wolfssl/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,7 @@ enum Misc {
#endif

HANDSHAKE_HEADER_SZ = 4, /* type + length(3) */
DTLS13_HANDSHAKE_HEADER_SZ = 12, /* sizeof(Dtls13HandshakeHeader) */
RECORD_HEADER_SZ = 5, /* type + version + len(2) */
CERT_HEADER_SZ = 3, /* always 3 bytes */
REQ_HEADER_SZ = 2, /* cert request header sz */
Expand Down
18 changes: 18 additions & 0 deletions wolfssl/wolfcrypt/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,24 @@ typedef struct w64wrapper {
#define PRAGMA_DIAG_POP /* null expansion */
#endif

#define WC_CPP_CAT_(a, b) a ## b
#define WC_CPP_CAT(a, b) WC_CPP_CAT_(a, b)
#ifndef static_assert
#if !defined(__cplusplus) && !defined(__STRICT_ANSI__) && \
!defined(WOLF_C89) && ((defined(__GNUC__) && \
__GNUC__ >= 5) || defined(__clang__))
#define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
#define static_assert(expr, ...) \
__static_assert(expr, ##__VA_ARGS__, #expr)
#elif defined(__STRICT_ANSI__) || defined(WOLF_C89)
#define static_assert(expr) \
struct WC_CPP_CAT(dummy_struct_, __LINE__)
#else
#define static_assert(...) \
struct WC_CPP_CAT(wc_dummy_struct_L, __LINE__)
#endif
#endif

#ifndef SAVE_VECTOR_REGISTERS
#define SAVE_VECTOR_REGISTERS(...) WC_DO_NOTHING
#endif
Expand Down

0 comments on commit fbbb2b8

Please sign in to comment.