Merge pull request #3487 from ejohnstown/sbf

Scan-Build Fixes
This commit is contained in:
David Garske
2020-11-13 09:24:17 -08:00
committed by GitHub
8 changed files with 77 additions and 39 deletions

View File

@@ -2340,7 +2340,7 @@ WOLFSSL_API void wolfSSL_flush_sessions(WOLFSSL_CTX*, long);
\brief This function associates the client session with the server id. \brief This function associates the client session with the server id.
If the newSession flag is on, an existing session wont be reused. If the newSession flag is on, an existing session wont be reused.
\return SSL_SUCCESS returned if the finction executed without error. \return SSL_SUCCESS returned if the function executed without error.
\return BAD_FUNC_ARG returned if the WOLFSSL struct or id parameter \return BAD_FUNC_ARG returned if the WOLFSSL struct or id parameter
is NULL or if len is not greater than zero. is NULL or if len is not greater than zero.
@@ -2361,7 +2361,7 @@ WOLFSSL_API void wolfSSL_flush_sessions(WOLFSSL_CTX*, long);
int ret = wolfSSL_SetServerID(ssl, id, len, newSession); int ret = wolfSSL_SetServerID(ssl, id, len, newSession);
if(ret){ if (ret == WOLFSSL_SUCCESS) {
// The Id was successfully set // The Id was successfully set
} }
\endcode \endcode

View File

@@ -2451,7 +2451,7 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
#ifdef OPENSSL_EXTRA #ifdef OPENSSL_EXTRA
{ {
byte* rnd; byte* rnd = NULL;
byte* pt; byte* pt;
size_t size; size_t size;
@@ -2461,8 +2461,10 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
err_sys_ex(runWithErrors, "error getting server random buffer " err_sys_ex(runWithErrors, "error getting server random buffer "
"size"); "size");
} }
else {
rnd = (byte*)XMALLOC(size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
rnd = (byte*)XMALLOC(size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (rnd == NULL) { if (rnd == NULL) {
err_sys_ex(runWithErrors, "error creating server random buffer"); err_sys_ex(runWithErrors, "error creating server random buffer");
} }

View File

@@ -17312,7 +17312,7 @@ int SendCertificateRequest(WOLFSSL* ssl)
(void)i; (void)i;
if (IsEncryptionOn(ssl, 1)) { if (IsEncryptionOn(ssl, 1)) {
byte* input; byte* input = NULL;
int inputSz = i; /* build msg adds rec hdr */ int inputSz = i; /* build msg adds rec hdr */
int recordHeaderSz = RECORD_HEADER_SZ; int recordHeaderSz = RECORD_HEADER_SZ;
@@ -17320,6 +17320,11 @@ int SendCertificateRequest(WOLFSSL* ssl)
recordHeaderSz += DTLS_RECORD_EXTRA; recordHeaderSz += DTLS_RECORD_EXTRA;
inputSz -= recordHeaderSz; inputSz -= recordHeaderSz;
if (inputSz <= 0) {
WOLFSSL_MSG("Send Cert Req bad inputSz");
return BUFFER_E;
}
input = (byte*)XMALLOC(inputSz, ssl->heap, DYNAMIC_TYPE_IN_BUFFER); input = (byte*)XMALLOC(inputSz, ssl->heap, DYNAMIC_TYPE_IN_BUFFER);
if (input == NULL) if (input == NULL)
return MEMORY_E; return MEMORY_E;
@@ -26691,6 +26696,10 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
#endif /* WOLFSSL_ASYNC_CRYPT */ #endif /* WOLFSSL_ASYNC_CRYPT */
/* Final cleanup */ /* Final cleanup */
if (args->input != NULL) {
XFREE(args->input, ssl->heap, DYNAMIC_TYPE_IN_BUFFER);
args->input = NULL;
}
FreeSskeArgs(ssl, args); FreeSskeArgs(ssl, args);
FreeKeyExchange(ssl); FreeKeyExchange(ssl);

View File

@@ -10530,7 +10530,7 @@ int wolfSSL_SetServerID(WOLFSSL* ssl, const byte* id, int len, int newSession)
if (session) { if (session) {
if (SetSession(ssl, session) != WOLFSSL_SUCCESS) { if (SetSession(ssl, session) != WOLFSSL_SUCCESS) {
#ifdef HAVE_EXT_CACHE #ifdef HAVE_EXT_CACHE
wolfSSL_SESSION_free(session); FreeSession(session, 0);
#endif #endif
WOLFSSL_MSG("SetSession failed"); WOLFSSL_MSG("SetSession failed");
session = NULL; session = NULL;
@@ -10546,7 +10546,7 @@ int wolfSSL_SetServerID(WOLFSSL* ssl, const byte* id, int len, int newSession)
} }
#ifdef HAVE_EXT_CACHE #ifdef HAVE_EXT_CACHE
else else
wolfSSL_SESSION_free(session); FreeSession(session, 0);
#endif #endif
return WOLFSSL_SUCCESS; return WOLFSSL_SUCCESS;
@@ -13344,7 +13344,7 @@ int AddSession(WOLFSSL* ssl)
if (error == 0 && ssl->ctx->new_sess_cb != NULL) if (error == 0 && ssl->ctx->new_sess_cb != NULL)
ssl->ctx->new_sess_cb(ssl, session); ssl->ctx->new_sess_cb(ssl, session);
if (ssl->options.internalCacheOff) if (ssl->options.internalCacheOff)
wolfSSL_SESSION_free(session); FreeSession(session, 0);
#endif #endif
return error; return error;
@@ -19854,7 +19854,7 @@ WOLFSSL_SESSION* wolfSSL_SESSION_dup(WOLFSSL_SESSION* session)
#endif /* HAVE_EXT_CACHE */ #endif /* HAVE_EXT_CACHE */
} }
void wolfSSL_SESSION_free(WOLFSSL_SESSION* session) void FreeSession(WOLFSSL_SESSION* session, int isAlloced)
{ {
if (session == NULL) if (session == NULL)
return; return;
@@ -19878,7 +19878,7 @@ void wolfSSL_SESSION_free(WOLFSSL_SESSION* session)
wc_UnLockMutex(&session->refMutex); wc_UnLockMutex(&session->refMutex);
#endif #endif
#if defined(HAVE_EXT_CACHE) || defined(OPENSSL_EXTRA) #if defined(HAVE_EXT_CACHE) || defined(OPENSSL_EXTRA)
if (session->isAlloced) { if (isAlloced) {
#ifdef HAVE_SESSION_TICKET #ifdef HAVE_SESSION_TICKET
if (session->isDynamic) if (session->isDynamic)
XFREE(session->ticket, NULL, DYNAMIC_TYPE_SESSION_TICK); XFREE(session->ticket, NULL, DYNAMIC_TYPE_SESSION_TICK);
@@ -19888,9 +19888,22 @@ void wolfSSL_SESSION_free(WOLFSSL_SESSION* session)
#else #else
/* No need to free since cache is static */ /* No need to free since cache is static */
(void)session; (void)session;
(void)isAlloced;
#endif #endif
} }
void wolfSSL_SESSION_free(WOLFSSL_SESSION* session)
{
if (session == NULL)
return;
#if defined(HAVE_EXT_CACHE) || defined(OPENSSL_EXTRA)
FreeSession(session, session->isAlloced);
#else
FreeSession(session, 0);
#endif #endif
}
#endif /* OPENSSL_EXTRA || HAVE_EXT_CACHE */
/* helper function that takes in a protocol version struct and returns string */ /* helper function that takes in a protocol version struct and returns string */
@@ -28041,8 +28054,10 @@ WOLFSSL_SESSION* wolfSSL_d2i_SSL_SESSION(WOLFSSL_SESSION** sess,
*p += idx; *p += idx;
end: end:
if (ret != 0 && (sess == NULL || *sess != s)) if (ret != 0 && (sess == NULL || *sess != s)) {
wolfSSL_SESSION_free(s); wolfSSL_SESSION_free(s);
s = NULL;
}
#endif #endif
return s; return s;
} }
@@ -29875,8 +29890,14 @@ int wolfSSL_DH_generate_key(WOLFSSL_DH* dh)
} else { } else {
privSz = pubSz; privSz = pubSz;
} }
pub = (unsigned char*)XMALLOC(pubSz, NULL, DYNAMIC_TYPE_PUBLIC_KEY); if (pubSz > 0) {
priv = (unsigned char*)XMALLOC(privSz, NULL, DYNAMIC_TYPE_PRIVATE_KEY); pub = (unsigned char*)XMALLOC(pubSz,
NULL, DYNAMIC_TYPE_PUBLIC_KEY);
}
if (privSz > 0) {
priv = (unsigned char*)XMALLOC(privSz,
NULL, DYNAMIC_TYPE_PRIVATE_KEY);
}
if (pub == NULL || priv == NULL) { if (pub == NULL || priv == NULL) {
WOLFSSL_MSG("Unable to malloc memory"); WOLFSSL_MSG("Unable to malloc memory");
} }

View File

@@ -3203,9 +3203,9 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, mp_int* em, mp_int* mm,
{ {
#ifdef WOLFSSL_SP_SMALL #ifdef WOLFSSL_SP_SMALL
sp_digit* d = NULL; sp_digit* d = NULL;
sp_digit* a; sp_digit* a = NULL;
sp_digit* m; sp_digit* m = NULL;
sp_digit* r; sp_digit* r = NULL;
sp_digit* norm; sp_digit* norm;
sp_digit e[1] = {0}; sp_digit e[1] = {0};
sp_digit mp; sp_digit mp;
@@ -7090,9 +7090,9 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, mp_int* em, mp_int* mm,
{ {
#ifdef WOLFSSL_SP_SMALL #ifdef WOLFSSL_SP_SMALL
sp_digit* d = NULL; sp_digit* d = NULL;
sp_digit* a; sp_digit* a = NULL;
sp_digit* m; sp_digit* m = NULL;
sp_digit* r; sp_digit* r = NULL;
sp_digit* norm; sp_digit* norm;
sp_digit e[1] = {0}; sp_digit e[1] = {0};
sp_digit mp; sp_digit mp;
@@ -11144,9 +11144,9 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, mp_int* em, mp_int* mm,
{ {
#ifdef WOLFSSL_SP_SMALL #ifdef WOLFSSL_SP_SMALL
sp_digit* d = NULL; sp_digit* d = NULL;
sp_digit* a; sp_digit* a = NULL;
sp_digit* m; sp_digit* m = NULL;
sp_digit* r; sp_digit* r = NULL;
sp_digit* norm; sp_digit* norm;
sp_digit e[1] = {0}; sp_digit e[1] = {0};
sp_digit mp; sp_digit mp;

View File

@@ -2843,9 +2843,9 @@ int sp_RsaPublic_2048(const byte* in, word32 inLen, mp_int* em, mp_int* mm,
{ {
#ifdef WOLFSSL_SP_SMALL #ifdef WOLFSSL_SP_SMALL
sp_digit* d = NULL; sp_digit* d = NULL;
sp_digit* a; sp_digit* a = NULL;
sp_digit* m; sp_digit* m = NULL;
sp_digit* r; sp_digit* r = NULL;
sp_digit* norm; sp_digit* norm;
sp_digit e[1] = {0}; sp_digit e[1] = {0};
sp_digit mp; sp_digit mp;
@@ -7005,9 +7005,9 @@ int sp_RsaPublic_3072(const byte* in, word32 inLen, mp_int* em, mp_int* mm,
{ {
#ifdef WOLFSSL_SP_SMALL #ifdef WOLFSSL_SP_SMALL
sp_digit* d = NULL; sp_digit* d = NULL;
sp_digit* a; sp_digit* a = NULL;
sp_digit* m; sp_digit* m = NULL;
sp_digit* r; sp_digit* r = NULL;
sp_digit* norm; sp_digit* norm;
sp_digit e[1] = {0}; sp_digit e[1] = {0};
sp_digit mp; sp_digit mp;
@@ -11403,9 +11403,9 @@ int sp_RsaPublic_4096(const byte* in, word32 inLen, mp_int* em, mp_int* mm,
{ {
#ifdef WOLFSSL_SP_SMALL #ifdef WOLFSSL_SP_SMALL
sp_digit* d = NULL; sp_digit* d = NULL;
sp_digit* a; sp_digit* a = NULL;
sp_digit* m; sp_digit* m = NULL;
sp_digit* r; sp_digit* r = NULL;
sp_digit* norm; sp_digit* norm;
sp_digit e[1] = {0}; sp_digit e[1] = {0};
sp_digit mp; sp_digit mp;

View File

@@ -927,6 +927,9 @@ static int sp_div(sp_int* a, sp_int* d, sp_int* r, sp_int* rem)
d = sd; d = sd;
} }
if (d->used < 0)
err = MP_VAL;
tr->used = sa->used - d->used + 1; tr->used = sa->used - d->used + 1;
sp_clear(tr); sp_clear(tr);
tr->used = sa->used - d->used + 1; tr->used = sa->used - d->used + 1;
@@ -2318,9 +2321,11 @@ int sp_prime_is_prime_ex(sp_int* a, int t, int* result, WC_RNG* rng)
if (a == NULL || result == NULL || rng == NULL) if (a == NULL || result == NULL || rng == NULL)
err = MP_VAL; err = MP_VAL;
if (sp_isone(a)) { if (err == MP_OKAY) {
*result = MP_NO; if (sp_isone(a)) {
return MP_OKAY; *result = MP_NO;
return MP_OKAY;
}
} }
if (err == MP_OKAY && a->used == 1) { if (err == MP_OKAY && a->used == 1) {
@@ -2407,7 +2412,8 @@ int sp_prime_is_prime_ex(sp_int* a, int t, int* result, WC_RNG* rng)
(void)t; (void)t;
#endif /* !WC_NO_RNG */ #endif /* !WC_NO_RNG */
*result = ret; if (result != NULL)
*result = ret;
return err; return err;
} }

View File

@@ -3221,14 +3221,14 @@ struct WOLFSSL_SESSION {
}; };
WOLFSSL_LOCAL WOLFSSL_LOCAL WOLFSSL_SESSION* GetSession(WOLFSSL*, byte*, byte);
WOLFSSL_SESSION* GetSession(WOLFSSL*, byte*, byte); WOLFSSL_LOCAL int SetSession(WOLFSSL*, WOLFSSL_SESSION*);
WOLFSSL_LOCAL WOLFSSL_LOCAL void FreeSession(WOLFSSL_SESSION*, int);
int SetSession(WOLFSSL*, WOLFSSL_SESSION*);
typedef int (*hmacfp) (WOLFSSL*, byte*, const byte*, word32, int, int, int, int); typedef int (*hmacfp) (WOLFSSL*, byte*, const byte*, word32, int, int, int, int);
#ifndef NO_CLIENT_CACHE #ifndef NO_CLIENT_CACHE
WOLFSSL_LOCAL
WOLFSSL_SESSION* GetSessionClient(WOLFSSL*, const byte*, int); WOLFSSL_SESSION* GetSessionClient(WOLFSSL*, const byte*, int);
#endif #endif