add null checks for function arguments that return BAD_FUNC_ARG

update function comment
This commit is contained in:
Ruby Martin
2025-08-06 15:06:31 -06:00
parent f5a4b13391
commit 9e3f726b0e
2 changed files with 22 additions and 1 deletions

View File

@@ -604,6 +604,9 @@ int IsAtLeastTLSv1_3(const ProtocolVersion pv)
int IsEncryptionOn(const WOLFSSL* ssl, int isSend) int IsEncryptionOn(const WOLFSSL* ssl, int isSend)
{ {
if (ssl == NULL) {
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_DTLS #ifdef WOLFSSL_DTLS
/* For DTLS, epoch 0 is always not encrypted. */ /* For DTLS, epoch 0 is always not encrypted. */
if (ssl->options.dtls && !isSend) { if (ssl->options.dtls && !isSend) {
@@ -10847,12 +10850,16 @@ static int SendHandshakeMsg(WOLFSSL* ssl, byte* input, word32 inputSz,
#endif /* !WOLFSSL_NO_TLS12 */ #endif /* !WOLFSSL_NO_TLS12 */
/* return bytes received, -1 on error */ /* return bytes received, WOLFSSL_FATAL_ERROR on error,
* or BAD_FUNC_ARG if ssl is null */
static int wolfSSLReceive(WOLFSSL* ssl, byte* buf, word32 sz) static int wolfSSLReceive(WOLFSSL* ssl, byte* buf, word32 sz)
{ {
int recvd; int recvd;
int retryLimit = WOLFSSL_MODE_AUTO_RETRY_ATTEMPTS; int retryLimit = WOLFSSL_MODE_AUTO_RETRY_ATTEMPTS;
if (ssl == NULL) {
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_QUIC #ifdef WOLFSSL_QUIC
if (WOLFSSL_IS_QUIC(ssl)) { if (WOLFSSL_IS_QUIC(ssl)) {
/* QUIC only "reads" from data provided by the application /* QUIC only "reads" from data provided by the application
@@ -11012,6 +11019,11 @@ int SendBuffered(WOLFSSL* ssl)
{ {
int retryLimit = WOLFSSL_MODE_AUTO_RETRY_ATTEMPTS; int retryLimit = WOLFSSL_MODE_AUTO_RETRY_ATTEMPTS;
if (ssl == NULL) {
WOLFSSL_MSG("ssl is null");
return BAD_FUNC_ARG;
}
if (ssl->CBIOSend == NULL && !WOLFSSL_IS_QUIC(ssl)) { if (ssl->CBIOSend == NULL && !WOLFSSL_IS_QUIC(ssl)) {
WOLFSSL_MSG("Your IO Send callback is null, please set"); WOLFSSL_MSG("Your IO Send callback is null, please set");
return SOCKET_ERROR_E; return SOCKET_ERROR_E;
@@ -11382,6 +11394,10 @@ int CheckAvailableSize(WOLFSSL *ssl, int size)
int MsgCheckEncryption(WOLFSSL* ssl, byte type, byte encrypted) int MsgCheckEncryption(WOLFSSL* ssl, byte type, byte encrypted)
{ {
if (ssl == NULL) {
WOLFSSL_MSG("ssl is null");
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_QUIC #ifdef WOLFSSL_QUIC
/* QUIC protects messages outside of the TLS scope */ /* QUIC protects messages outside of the TLS scope */
if (WOLFSSL_IS_QUIC(ssl) && IsAtLeastTLSv1_3(ssl->version)) if (WOLFSSL_IS_QUIC(ssl) && IsAtLeastTLSv1_3(ssl->version))

View File

@@ -715,6 +715,11 @@ int SizeASN_Items(const ASNItem* asn, ASNSetData *data, int count, int* encSz)
WOLFSSL_ENTER("SizeASN_Items"); WOLFSSL_ENTER("SizeASN_Items");
#endif #endif
if (asn == NULL || data == NULL || count <= 0 || encSz == NULL) {
WOLFSSL_MSG("bad arguments in SizeASN_Items");
return BAD_FUNC_ARG;
}
for (i = count - 1; i >= 0; i--) { for (i = count - 1; i >= 0; i--) {
/* Skip this ASN.1 item when encoding. */ /* Skip this ASN.1 item when encoding. */
if (data[i].noOut) { if (data[i].noOut) {