Skip to content

Commit 5a5a8c9

Browse files
Merge pull request #6841 from julek-wolfssl/fix-all-scr
Fixes for bugs exposed with SCR
2 parents c26ad8d + 858c66d commit 5a5a8c9

4 files changed

Lines changed: 36 additions & 60 deletions

File tree

.github/workflows/os-check.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
--enable-opensslextra --enable-sessioncerts
2020
CPPFLAGS=''-DWOLFSSL_DTLS_NO_HVR_ON_RESUME -DHAVE_EXT_CACHE
2121
-DWOLFSSL_TICKET_HAVE_ID -DHAVE_EX_DATA -DSESSION_CACHE_DYNAMIC_MEM'' ',
22+
'--enable-all --enable-secure-renegotiation',
23+
'--enable-all --enable-haproxy --enable-quic',
2224
]
2325
name: make check
2426
runs-on: ${{ matrix.os }}

src/internal.c

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6455,7 +6455,7 @@ int InitSSL_Suites(WOLFSSL* ssl)
64556455
WOLFSSL_SUCCESS return value on success */
64566456
int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
64576457
{
6458-
int ret;
6458+
int ret = WOLFSSL_SUCCESS; /* set default ret */
64596459
byte newSSL;
64606460

64616461
WOLFSSL_ENTER("SetSSL_CTX");
@@ -6475,38 +6475,35 @@ int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
64756475
if (!newSSL) {
64766476
WOLFSSL_MSG("freeing old ctx to decrement reference count. Switching ctx.");
64776477
wolfSSL_CTX_free(ssl->ctx);
6478-
#if defined(WOLFSSL_HAPROXY)
6479-
wolfSSL_CTX_free(ssl->initial_ctx);
6480-
#endif
64816478
}
64826479

64836480
/* increment CTX reference count */
6484-
wolfSSL_RefInc(&ctx->ref, &ret);
6481+
ret = wolfSSL_CTX_up_ref(ctx);
64856482
#ifdef WOLFSSL_REFCNT_ERROR_RETURN
6486-
if (ret < 0) {
6483+
if (ret != WOLFSSL_SUCCESS) {
64876484
return ret;
64886485
}
64896486
#else
64906487
(void)ret;
64916488
#endif
6492-
ret = WOLFSSL_SUCCESS; /* set default ret */
64936489

64946490
ssl->ctx = ctx; /* only for passing to calls, options could change */
64956491
/* Don't change version on a SSL object that has already started a
64966492
* handshake */
64976493
#if defined(WOLFSSL_HAPROXY)
6498-
ret = wolfSSL_CTX_up_ref(ctx);
6499-
if (ret == WOLFSSL_SUCCESS) {
6500-
ssl->initial_ctx = ctx; /* Save access to session key materials */
6501-
}
6502-
else {
6503-
#ifdef WOLFSSL_REFCNT_ERROR_RETURN
6504-
return ret;
6505-
#else
6506-
(void)ret;
6507-
#endif
6494+
if (ssl->initial_ctx == NULL) {
6495+
ret = wolfSSL_CTX_up_ref(ctx);
6496+
if (ret == WOLFSSL_SUCCESS) {
6497+
ssl->initial_ctx = ctx; /* Save access to session key materials */
6498+
}
6499+
else {
6500+
#ifdef WOLFSSL_REFCNT_ERROR_RETURN
6501+
return ret;
6502+
#else
6503+
(void)ret;
6504+
#endif
6505+
}
65086506
}
6509-
65106507
#endif
65116508
if (!ssl->msgsReceived.got_client_hello &&
65126509
!ssl->msgsReceived.got_server_hello)
@@ -7185,13 +7182,7 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
71857182
#endif
71867183
#if defined(WOLFSSL_SCTP) || defined(WOLFSSL_DTLS_MTU)
71877184
ssl->dtlsMtuSz = ctx->dtlsMtuSz;
7188-
ssl->dtls_expected_rx = ssl->dtlsMtuSz;
7189-
#else
7190-
ssl->dtls_expected_rx = MAX_MTU;
71917185
#endif
7192-
/* Add some bytes so that we can operate with slight difference
7193-
* in set MTU size on each peer */
7194-
ssl->dtls_expected_rx += DTLS_MTU_ADDITIONAL_READ_BUFFER;
71957186
ssl->dtls_timeout_init = DTLS_TIMEOUT_INIT;
71967187
ssl->dtls_timeout_max = DTLS_TIMEOUT_MAX;
71977188
ssl->dtls_timeout = ssl->dtls_timeout_init;
@@ -8244,6 +8235,10 @@ void SSL_ResourceFree(WOLFSSL* ssl)
82448235
#ifdef WOLFSSL_QUIC
82458236
wolfSSL_quic_free(ssl);
82468237
#endif
8238+
#if defined(WOLFSSL_HAPROXY)
8239+
wolfSSL_CTX_free(ssl->initial_ctx);
8240+
ssl->initial_ctx = NULL;
8241+
#endif
82478242
}
82488243

82498244
/* Free any handshake resources no longer needed */
@@ -10598,26 +10593,20 @@ int CheckAvailableSize(WOLFSSL *ssl, int size)
1059810593

1059910594
#ifdef WOLFSSL_DTLS
1060010595
if (ssl->options.dtls) {
10601-
if (size + ssl->buffers.outputBuffer.length >
1060210596
#if defined(WOLFSSL_SCTP) || defined(WOLFSSL_DTLS_MTU)
10603-
ssl->dtlsMtuSz
10597+
word32 mtu = (word32)ssl->dtlsMtuSz;
1060410598
#else
10605-
ssl->dtls_expected_rx
10599+
word32 mtu = MAX_MTU;
1060610600
#endif
10607-
) {
10601+
if ((word32)size + ssl->buffers.outputBuffer.length > mtu) {
1060810602
int ret;
1060910603
WOLFSSL_MSG("CheckAvailableSize() flushing buffer "
1061010604
"to make room for new message");
1061110605
if ((ret = SendBuffered(ssl)) != 0) {
1061210606
return ret;
1061310607
}
1061410608
}
10615-
if (size > (int)
10616-
#if defined(WOLFSSL_SCTP) || defined(WOLFSSL_DTLS_MTU)
10617-
ssl->dtlsMtuSz
10618-
#else
10619-
ssl->dtls_expected_rx
10620-
#endif
10609+
if ((word32)size > mtu
1062110610
#ifdef WOLFSSL_DTLS13
1062210611
/* DTLS1.3 uses the output buffer to store the full message and deal
1062310612
with fragmentation later in dtls13HandshakeSend() */
@@ -19853,10 +19842,16 @@ static int GetInputData(WOLFSSL *ssl, word32 size)
1985319842
inSz = (int)(size - usedLength); /* from last partial read */
1985419843

1985519844
#ifdef WOLFSSL_DTLS
19856-
if (ssl->options.dtls) {
19857-
if (size < ssl->dtls_expected_rx)
19858-
dtlsExtra = (int)(ssl->dtls_expected_rx - size);
19859-
inSz = ssl->dtls_expected_rx;
19845+
if (ssl->options.dtls && IsDtlsNotSctpMode(ssl)) {
19846+
/* Add DTLS_MTU_ADDITIONAL_READ_BUFFER bytes so that we can operate with
19847+
* slight difference in set MTU size on each peer */
19848+
#ifdef WOLFSSL_DTLS_MTU
19849+
inSz = (word32)ssl->dtlsMtuSz + DTLS_MTU_ADDITIONAL_READ_BUFFER;
19850+
#else
19851+
inSz = MAX_MTU + DTLS_MTU_ADDITIONAL_READ_BUFFER;
19852+
#endif
19853+
if (size < (word32)inSz)
19854+
dtlsExtra = (int)(inSz - size);
1986019855
}
1986119856
#endif
1986219857

src/ssl.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3338,22 +3338,6 @@ static int wolfSSL_read_internal(WOLFSSL* ssl, void* data, int sz, int peek)
33383338
errno = 0;
33393339
#endif
33403340

3341-
#ifdef WOLFSSL_DTLS
3342-
if (ssl->options.dtls) {
3343-
ssl->dtls_expected_rx = max(sz + DTLS_MTU_ADDITIONAL_READ_BUFFER,
3344-
MAX_MTU);
3345-
#ifdef WOLFSSL_SCTP
3346-
if (ssl->options.dtlsSctp)
3347-
#endif
3348-
#if defined(WOLFSSL_SCTP) || defined(WOLFSSL_DTLS_MTU)
3349-
/* Add some bytes so that we can operate with slight difference
3350-
* in set MTU size on each peer */
3351-
ssl->dtls_expected_rx = max(ssl->dtls_expected_rx,
3352-
ssl->dtlsMtuSz + (word32)DTLS_MTU_ADDITIONAL_READ_BUFFER);
3353-
#endif
3354-
}
3355-
#endif
3356-
33573341
ret = ReceiveData(ssl, (byte*)data, sz, peek);
33583342

33593343
#ifdef HAVE_WRITE_DUP
@@ -30246,12 +30230,8 @@ WOLFSSL_CTX* wolfSSL_set_SSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
3024630230
#else
3024730231
(void)ret;
3024830232
#endif
30249-
if (ssl->ctx) {
30233+
if (ssl->ctx != NULL)
3025030234
wolfSSL_CTX_free(ssl->ctx);
30251-
#if defined(WOLFSSL_HAPROXY)
30252-
wolfSSL_CTX_free(ssl->initial_ctx);
30253-
#endif
30254-
}
3025530235
ssl->ctx = ctx;
3025630236

3025730237
#ifndef NO_CERTS

wolfssl/internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5567,7 +5567,6 @@ struct WOLFSSL {
55675567
DtlsMsg* dtls_tx_msg;
55685568
DtlsMsg* dtls_rx_msg_list;
55695569
void* IOCB_CookieCtx; /* gen cookie ctx */
5570-
word32 dtls_expected_rx;
55715570
#ifdef WOLFSSL_SESSION_EXPORT
55725571
wc_dtls_export dtls_export; /* export function for session */
55735572
#endif

0 commit comments

Comments
 (0)