Skip to content

Commit 23c60b7

Browse files
authored
Merge pull request #6530 from SparkiDev/tests_api_expect_5
Test api.c: change more tests to use Expect instead of Assert
2 parents 17bc833 + 578f56e commit 23c60b7

9 files changed

Lines changed: 10672 additions & 16921 deletions

File tree

src/bio.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,9 +2069,15 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio)
20692069

20702070
bio->ip = (char*)XMALLOC((port - str) + 1, /* +1 for null char */
20712071
bio->heap, DYNAMIC_TYPE_OPENSSL);
2072-
XMEMCPY(bio->ip, str, port - str);
2073-
bio->ip[port - str] = '\0';
2074-
bio->type = WOLFSSL_BIO_SOCKET;
2072+
if (bio->ip != NULL) {
2073+
XMEMCPY(bio->ip, str, port - str);
2074+
bio->ip[port - str] = '\0';
2075+
bio->type = WOLFSSL_BIO_SOCKET;
2076+
}
2077+
else {
2078+
BIO_free(bio);
2079+
bio = NULL;
2080+
}
20752081
}
20762082
return bio;
20772083
}

src/internal.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,7 +2154,12 @@ int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method, void* heap)
21542154
XMEMSET(ctx, 0, sizeof(WOLFSSL_CTX));
21552155

21562156
ctx->method = method;
2157-
ctx->heap = ctx; /* defaults to self */
2157+
if (heap == NULL) {
2158+
ctx->heap = ctx; /* defaults to self */
2159+
}
2160+
else {
2161+
ctx->heap = heap; /* wolfSSL_CTX_load_static_memory sets */
2162+
}
21582163
ctx->timeout = WOLFSSL_SESSION_TIMEOUT;
21592164

21602165
#ifdef WOLFSSL_DTLS
@@ -13598,6 +13603,12 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1359813603
if (ret == 0) {
1359913604
ret = ProcessPeerCertCheckKey(ssl, args);
1360013605
}
13606+
else if (ret == ASN_PARSE_E || ret == BUFFER_E ||
13607+
ret == MEMORY_E) {
13608+
WOLFSSL_MSG(
13609+
"Got Peer cert ASN PARSE_E, BUFFER E, MEMORY_E");
13610+
ERROR_OUT(ret, exit_ppc);
13611+
}
1360113612

1360213613
if (ret == 0 && args->dCert->isCA == 0) {
1360313614
WOLFSSL_MSG("Chain cert is not a CA, not adding as one");
@@ -13882,8 +13893,9 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1388213893
args->fatal = 0;
1388313894
}
1388413895
}
13885-
else if (ret == ASN_PARSE_E || ret == BUFFER_E) {
13886-
WOLFSSL_MSG("Got Peer cert ASN PARSE or BUFFER ERROR");
13896+
else if (ret == ASN_PARSE_E || ret == BUFFER_E ||
13897+
ret == MEMORY_E) {
13898+
WOLFSSL_MSG("Got Peer cert ASN PARSE_E, BUFFER E, MEMORY_E");
1388713899
#if defined(WOLFSSL_EXTRA_ALERTS) || defined(OPENSSL_EXTRA) || \
1388813900
defined(OPENSSL_EXTRA_X509_SMALL)
1388913901
DoCertFatalAlert(ssl, ret);

src/ssl.c

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4446,12 +4446,14 @@ int wolfSSL_shutdown(WOLFSSL* ssl)
44464446
/* call wolfSSL_shutdown again for bidirectional shutdown */
44474447
if (ssl->options.sentNotify && !ssl->options.closeNotify) {
44484448
ret = ProcessReply(ssl);
4449-
if (ret == ZERO_RETURN) {
4449+
if ((ret == ZERO_RETURN) || (ret == SOCKET_ERROR_E)) {
44504450
/* simulate OpenSSL behavior */
44514451
ssl->options.shutdownDone = 1;
44524452
/* Clear error */
44534453
ssl->error = WOLFSSL_ERROR_NONE;
44544454
ret = WOLFSSL_SUCCESS;
4455+
} else if (ret == MEMORY_E) {
4456+
ret = WOLFSSL_FATAL_ERROR;
44554457
} else if (ssl->error == WOLFSSL_ERROR_NONE) {
44564458
ret = WOLFSSL_SHUTDOWN_NOT_DONE;
44574459
} else {
@@ -14479,6 +14481,10 @@ int wolfSSL_Cleanup(void)
1447914481
crypto_ex_cb_ctx_session = NULL;
1448014482
#endif
1448114483

14484+
#ifdef WOLFSSL_MEM_FAIL_COUNT
14485+
wc_MemFailCount_Free();
14486+
#endif
14487+
1448214488
return ret;
1448314489
}
1448414490

@@ -14777,7 +14783,7 @@ static int SessionTicketNoncePrealloc(byte** buf, byte* len, void *heap)
1477714783
if (*buf == NULL) {
1477814784
WOLFSSL_MSG("Failed to preallocate ticket nonce buffer");
1477914785
*len = 0;
14780-
return WOLFSSL_FAILURE;
14786+
return 1;
1478114787
}
1478214788

1478314789
*len = PREALLOC_SESSION_TICKET_NONCE_LEN;
@@ -15548,9 +15554,8 @@ int AddSessionToCache(WOLFSSL_CTX* ctx, WOLFSSL_SESSION* addSession,
1554815554
WOLFSSL_MSG("Hash session failed");
1554915555
#ifdef HAVE_SESSION_TICKET
1555015556
XFREE(ticBuff, NULL, DYNAMIC_TYPE_SESSION_TICK);
15551-
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_TICKE_NONCE_MALLOC)
15552-
if (preallocNonce != NULL)
15553-
XFREE(preallocNonce, addSession->heap, DYNAMIC_TYPE_SESSION_TICK);
15557+
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_TICKET_NONCE_MALLOC)
15558+
XFREE(preallocNonce, addSession->heap, DYNAMIC_TYPE_SESSION_TICK);
1555415559
#endif
1555515560
#endif
1555615561
return ret;
@@ -15560,9 +15565,8 @@ int AddSessionToCache(WOLFSSL_CTX* ctx, WOLFSSL_SESSION* addSession,
1556015565
if (SESSION_ROW_WR_LOCK(sessRow) != 0) {
1556115566
#ifdef HAVE_SESSION_TICKET
1556215567
XFREE(ticBuff, NULL, DYNAMIC_TYPE_SESSION_TICK);
15563-
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_TICKE_NONCE_MALLOC)
15564-
if (preallocNonce != NULL)
15565-
XFREE(preallocNonce, addSession->heap, DYNAMIC_TYPE_SESSION_TICK);
15568+
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_TICKET_NONCE_MALLOC)
15569+
XFREE(preallocNonce, addSession->heap, DYNAMIC_TYPE_SESSION_TICK);
1556615570
#endif
1556715571
#endif
1556815572
WOLFSSL_MSG("Session row lock failed");
@@ -15600,9 +15604,8 @@ int AddSessionToCache(WOLFSSL_CTX* ctx, WOLFSSL_SESSION* addSession,
1560015604
if (cacheSession == NULL) {
1560115605
#ifdef HAVE_SESSION_TICKET
1560215606
XFREE(ticBuff, NULL, DYNAMIC_TYPE_SESSION_TICK);
15603-
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_TICKE_NONCE_MALLOC)
15604-
if (preallocNonce != NULL)
15605-
XFREE(preallocNonce, addSession->heap, DYNAMIC_TYPE_SESSION_TICK);
15607+
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_TICKET_NONCE_MALLOC)
15608+
XFREE(preallocNonce, addSession->heap, DYNAMIC_TYPE_SESSION_TICK);
1560615609
#endif
1560715610
#endif
1560815611
SESSION_ROW_UNLOCK(sessRow);
@@ -15757,14 +15760,11 @@ int AddSessionToCache(WOLFSSL_CTX* ctx, WOLFSSL_SESSION* addSession,
1575715760
#ifdef HAVE_SESSION_TICKET
1575815761
if (ticBuff != NULL && !ticBuffUsed)
1575915762
XFREE(ticBuff, NULL, DYNAMIC_TYPE_SESSION_TICK);
15760-
if (cacheTicBuff != NULL)
15761-
XFREE(cacheTicBuff, NULL, DYNAMIC_TYPE_SESSION_TICK);
15763+
XFREE(cacheTicBuff, NULL, DYNAMIC_TYPE_SESSION_TICK);
1576215764
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_TICKET_NONCE_MALLOC) && \
1576315765
(!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
15764-
if (preallocNonce != NULL)
15765-
XFREE(preallocNonce, addSession->heap, DYNAMIC_TYPE_SESSION_TICK);
15766-
if (toFree != NULL)
15767-
XFREE(toFree, addSession->heap, DYNAMIC_TYPE_SESSION_TICK);
15766+
XFREE(preallocNonce, addSession->heap, DYNAMIC_TYPE_SESSION_TICK);
15767+
XFREE(toFree, addSession->heap, DYNAMIC_TYPE_SESSION_TICK);
1576815768
#endif /* WOLFSSL_TLS13 && WOLFSSL_TICKET_NONCE_MALLOC && FIPS_VERSION_GE(5,3)*/
1576915769
#endif
1577015770

@@ -16503,8 +16503,10 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
1650316503
{
1650416504
WOLFSSL_ENTER("wolfSSL_set_psk_use_session_callback");
1650516505

16506-
ssl->options.havePSK = 1;
16507-
ssl->options.session_psk_cb = cb;
16506+
if (ssl != NULL) {
16507+
ssl->options.havePSK = 1;
16508+
ssl->options.session_psk_cb = cb;
16509+
}
1650816510

1650916511
WOLFSSL_LEAVE("wolfSSL_set_psk_use_session_callback", WOLFSSL_SUCCESS);
1651016512
}
@@ -31030,7 +31032,8 @@ int wolfSSL_SESSION_get_ex_new_index(long ctx_l,void* ctx_ptr,
3103031032
}
3103131033
#endif
3103231034

31033-
#if defined(USE_WOLFSSL_MEMORY) && !defined(WOLFSSL_DEBUG_MEMORY)
31035+
#if defined(USE_WOLFSSL_MEMORY) && !defined(WOLFSSL_DEBUG_MEMORY) && \
31036+
!defined(WOLFSSL_STATIC_MEMORY)
3103431037
static wolfSSL_OSSL_Malloc_cb ossl_malloc = NULL;
3103531038
static wolfSSL_OSSL_Free_cb ossl_free = NULL;
3103631039
static wolfSSL_OSSL_Realloc_cb ossl_realloc = NULL;
@@ -31056,14 +31059,15 @@ static void* OSSL_Realloc(void *ptr, size_t size)
3105631059
else
3105731060
return NULL;
3105831061
}
31059-
#endif /* USE_WOLFSSL_MEMORY && !WOLFSSL_DEBUG_MEMORY */
31062+
#endif /* USE_WOLFSSL_MEMORY && !WOLFSSL_DEBUG_MEMORY &&
31063+
* !WOLFSSL_STATIC_MEMORY */
3106031064

3106131065
int wolfSSL_CRYPTO_set_mem_functions(
3106231066
wolfSSL_OSSL_Malloc_cb m,
3106331067
wolfSSL_OSSL_Realloc_cb r,
3106431068
wolfSSL_OSSL_Free_cb f)
3106531069
{
31066-
#ifdef USE_WOLFSSL_MEMORY
31070+
#if defined(USE_WOLFSSL_MEMORY) && !defined(WOLFSSL_STATIC_MEMORY)
3106731071
#ifdef WOLFSSL_DEBUG_MEMORY
3106831072
WOLFSSL_MSG("mem functions will receive function name instead of "
3106931073
"file name");
@@ -37777,6 +37781,9 @@ PKCS7* wolfSSL_SMIME_read_PKCS7(WOLFSSL_BIO* in,
3777737781
}
3777837782

3777937783
lineLen = wolfSSL_BIO_gets(in, section, remainLen);
37784+
if (lineLen < 0) {
37785+
goto error;
37786+
}
3778037787
while (XSTRNCMP(&section[sectionLen], boundary, boundLen) &&
3778137788
remainLen > 0) {
3778237789
canonLineLen = lineLen;

0 commit comments

Comments
 (0)