mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-07-05 13:10:52 +02:00
Merge pull request #10216 from ColtonWilley/add-null-checks-public-api
Add missing NULL checks in public API functions
This commit is contained in:
@@ -14575,8 +14575,14 @@ void* wolfSSL_GetHKDFExtractCtx(WOLFSSL* ssl)
|
||||
}
|
||||
else if (a->type == WOLFSSL_GEN_DNS || a->type == WOLFSSL_GEN_EMAIL ||
|
||||
a->type == WOLFSSL_GEN_URI) {
|
||||
bufSz = (int)XSTRLEN((const char*)a->obj);
|
||||
XMEMCPY(buf, a->obj, min((word32)bufSz, (word32)bufLen));
|
||||
size_t objLen = XSTRLEN((const char*)a->obj);
|
||||
if (objLen >= (size_t)bufLen) {
|
||||
bufSz = bufLen - 1;
|
||||
}
|
||||
else {
|
||||
bufSz = (int)objLen;
|
||||
}
|
||||
XMEMCPY(buf, a->obj, (size_t)bufSz);
|
||||
}
|
||||
else if ((bufSz = wolfssl_obj2txt_numeric(buf, bufLen, a)) > 0) {
|
||||
if ((desc = oid_translate_num_to_str(buf))) {
|
||||
@@ -17529,7 +17535,7 @@ int wolfSSL_CTX_set_alpn_protos(WOLFSSL_CTX *ctx, const unsigned char *p,
|
||||
unsigned int p_len)
|
||||
{
|
||||
WOLFSSL_ENTER("wolfSSL_CTX_set_alpn_protos");
|
||||
if (ctx == NULL)
|
||||
if (ctx == NULL || p == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
if (ctx->alpn_cli_protos != NULL) {
|
||||
XFREE((void*)ctx->alpn_cli_protos, ctx->heap, DYNAMIC_TYPE_OPENSSL);
|
||||
@@ -17583,7 +17589,7 @@ int wolfSSL_set_alpn_protos(WOLFSSL* ssl,
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_set_alpn_protos");
|
||||
|
||||
if (ssl == NULL || p_len <= 1) {
|
||||
if (ssl == NULL || p_len <= 1 || p == NULL) {
|
||||
#if defined(WOLFSSL_ERROR_CODE_OPENSSL)
|
||||
/* 0 on success in OpenSSL, non-0 on failure in OpenSSL
|
||||
* the function reverses the return value convention.
|
||||
|
||||
+26
-6
@@ -4159,6 +4159,10 @@ int wolfSSL_CTX_use_PrivateKey_Id(WOLFSSL_CTX* ctx, const unsigned char* id,
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_CTX_use_PrivateKey_Id");
|
||||
|
||||
if (ctx == NULL || id == NULL || sz < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Dispose of old private key and allocate and copy in id. */
|
||||
FreeDer(&ctx->privateKey);
|
||||
if (AllocCopyDer(&ctx->privateKey, id, (word32)sz, PRIVATEKEY_TYPE,
|
||||
@@ -4227,10 +4231,16 @@ int wolfSSL_CTX_use_PrivateKey_Label(WOLFSSL_CTX* ctx, const char* label,
|
||||
int devId)
|
||||
{
|
||||
int ret = 1;
|
||||
word32 sz = (word32)XSTRLEN(label) + 1;
|
||||
word32 sz;
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_CTX_use_PrivateKey_Label");
|
||||
|
||||
if (ctx == NULL || label == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sz = (word32)XSTRLEN(label) + 1;
|
||||
|
||||
/* Dispose of old private key and allocate and copy in label. */
|
||||
FreeDer(&ctx->privateKey);
|
||||
if (AllocCopyDer(&ctx->privateKey, (const byte*)label, (word32)sz,
|
||||
@@ -4268,7 +4278,7 @@ int wolfSSL_CTX_use_AltPrivateKey_Id(WOLFSSL_CTX* ctx, const unsigned char* id,
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_CTX_use_AltPrivateKey_Id");
|
||||
|
||||
if ((ctx == NULL) || (id == NULL)) {
|
||||
if ((ctx == NULL) || (id == NULL) || (sz < 0)) {
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
@@ -4280,7 +4290,7 @@ int wolfSSL_CTX_use_AltPrivateKey_Id(WOLFSSL_CTX* ctx, const unsigned char* id,
|
||||
}
|
||||
}
|
||||
if (ret == 1) {
|
||||
XMEMCPY(ctx->altPrivateKey->buffer, id, sz);
|
||||
XMEMCPY(ctx->altPrivateKey->buffer, id, (word32)sz);
|
||||
ctx->altPrivateKeyId = 1;
|
||||
if (devId != INVALID_DEVID) {
|
||||
ctx->altPrivateKeyDevId = devId;
|
||||
@@ -4561,6 +4571,10 @@ int wolfSSL_use_PrivateKey_Id(WOLFSSL* ssl, const unsigned char* id,
|
||||
{
|
||||
int ret = 1;
|
||||
|
||||
if (ssl == NULL || id == NULL || sz < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Dispose of old private key if owned and allocate and copy in id. */
|
||||
if (ssl->buffers.weOwnKey) {
|
||||
FreeDer(&ssl->buffers.key);
|
||||
@@ -4629,7 +4643,13 @@ int wolfSSL_use_PrivateKey_Id_ex(WOLFSSL* ssl, const unsigned char* id,
|
||||
int wolfSSL_use_PrivateKey_Label(WOLFSSL* ssl, const char* label, int devId)
|
||||
{
|
||||
int ret = 1;
|
||||
word32 sz = (word32)XSTRLEN(label) + 1;
|
||||
word32 sz;
|
||||
|
||||
if (ssl == NULL || label == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sz = (word32)XSTRLEN(label) + 1;
|
||||
|
||||
/* Dispose of old private key if owned and allocate and copy in label. */
|
||||
if (ssl->buffers.weOwnKey) {
|
||||
@@ -4672,7 +4692,7 @@ int wolfSSL_use_AltPrivateKey_Id(WOLFSSL* ssl, const unsigned char* id, long sz,
|
||||
{
|
||||
int ret = 1;
|
||||
|
||||
if ((ssl == NULL) || (id == NULL)) {
|
||||
if ((ssl == NULL) || (id == NULL) || (sz < 0)) {
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
@@ -4689,7 +4709,7 @@ int wolfSSL_use_AltPrivateKey_Id(WOLFSSL* ssl, const unsigned char* id, long sz,
|
||||
}
|
||||
}
|
||||
if (ret == 1) {
|
||||
XMEMCPY(ssl->buffers.altKey->buffer, id, sz);
|
||||
XMEMCPY(ssl->buffers.altKey->buffer, id, (word32)sz);
|
||||
ssl->buffers.weOwnAltKey = 1;
|
||||
ssl->buffers.altKeyId = 1;
|
||||
if (devId != INVALID_DEVID) {
|
||||
|
||||
+14
-2
@@ -430,10 +430,16 @@ int wolfSSL_memsave_session_cache(void* mem, int sz)
|
||||
{
|
||||
int i;
|
||||
cache_header_t cache_header;
|
||||
SessionRow* row = (SessionRow*)((byte*)mem + sizeof(cache_header));
|
||||
SessionRow* row;
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_memsave_session_cache");
|
||||
|
||||
if (mem == NULL) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
row = (SessionRow*)((byte*)mem + sizeof(cache_header));
|
||||
|
||||
if (sz < wolfSSL_get_session_cache_memsize()) {
|
||||
WOLFSSL_MSG("Memory buffer too small");
|
||||
return BUFFER_E;
|
||||
@@ -520,10 +526,16 @@ int wolfSSL_memrestore_session_cache(const void* mem, int sz)
|
||||
{
|
||||
int i;
|
||||
cache_header_t cache_header;
|
||||
SessionRow* row = (SessionRow*)((byte*)mem + sizeof(cache_header));
|
||||
SessionRow* row;
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_memrestore_session_cache");
|
||||
|
||||
if (mem == NULL) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
row = (SessionRow*)((byte*)mem + sizeof(cache_header));
|
||||
|
||||
if (sz < wolfSSL_get_session_cache_memsize()) {
|
||||
WOLFSSL_MSG("Memory buffer too small");
|
||||
return BUFFER_E;
|
||||
|
||||
+2
-2
@@ -3279,8 +3279,8 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509V3_EXT_nconf(WOLFSSL_CONF *conf,
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_X509V3_EXT_nconf");
|
||||
|
||||
if (value == NULL) {
|
||||
WOLFSSL_MSG("value NULL parameter");
|
||||
if (value == NULL || sName == NULL) {
|
||||
WOLFSSL_MSG("NULL parameter");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -1020,6 +1020,7 @@ int test_wolfSSL_X509V3_EXT_nconf(void)
|
||||
ExpectNull(X509V3_EXT_nconf(NULL, NULL, ext_names[0], NULL));
|
||||
ExpectNull(X509V3_EXT_nconf_nid(NULL, NULL, ext_nids[0], NULL));
|
||||
ExpectNull(X509V3_EXT_nconf(NULL, NULL, "", ext_values[0]));
|
||||
ExpectNull(X509V3_EXT_nconf(NULL, NULL, NULL, ext_values[0]));
|
||||
ExpectNull(X509V3_EXT_nconf_nid(NULL, NULL, 0, ext_values[0]));
|
||||
|
||||
/* conf and ctx ignored. */
|
||||
|
||||
@@ -378,6 +378,8 @@ int wc_SrpSetParams(Srp* srp, const byte* N, word32 nSz,
|
||||
if (srp->salt) {
|
||||
ForceZero(srp->salt, srp->saltSz);
|
||||
XFREE(srp->salt, srp->heap, DYNAMIC_TYPE_SRP);
|
||||
srp->salt = NULL;
|
||||
srp->saltSz = 0;
|
||||
}
|
||||
|
||||
srp->salt = (byte*)XMALLOC(saltSz, srp->heap, DYNAMIC_TYPE_SRP);
|
||||
|
||||
Reference in New Issue
Block a user