@@ -6455,7 +6455,7 @@ int InitSSL_Suites(WOLFSSL* ssl)
64556455 WOLFSSL_SUCCESS return value on success */
64566456int 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
0 commit comments