Skip to content

Commit

Permalink
Merge pull request #8371 from lealem47/fix-norealloc-crash
Browse files Browse the repository at this point in the history
Fix for WOLFSSL_NO_REALLOC build crash
  • Loading branch information
dgarske authored Jan 24, 2025
2 parents fee2364 + eda9871 commit f1e06e1
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2778,9 +2778,11 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio)
#ifdef WOLFSSL_NO_REALLOC
tmp = b->ip;
b->ip = (char*)XMALLOC(newLen+1, b->heap, DYNAMIC_TYPE_OPENSSL);
XMEMCPY(b->ip, tmp, newLen);
XFREE(tmp, b->heap, DYNAMIC_TYPE_OPENSSL);
tmp = NULL;
if (b->ip != NULL && tmp != NULL) {
XMEMCPY(b->ip, tmp, newLen);
XFREE(tmp, b->heap, DYNAMIC_TYPE_OPENSSL);
tmp = NULL;
}
#else
b->ip = (char*)XREALLOC(b->ip, newLen + 1, b->heap,
DYNAMIC_TYPE_OPENSSL);
Expand Down
2 changes: 1 addition & 1 deletion src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ static char* expandValue(WOLFSSL_CONF *conf, const char* section,
#ifdef WOLFSSL_NO_REALLOC
newRet = (char*)XMALLOC(strLen + 1, NULL,
DYNAMIC_TYPE_OPENSSL);
if (newRet != NULL) {
if (newRet != NULL && ret != NULL) {
XMEMCPY(newRet, ret, (strLen - valueLen) + 1);
XFREE(ret, NULL, DYNAMIC_TYPE_OPENSSL);
ret = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -39407,7 +39407,7 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
#ifdef WOLFSSL_NO_REALLOC
tmp = (byte*)XMALLOC(sizeof(InternalTicket), ssl->heap,
DYNAMIC_TYPE_TLSX);
if (tmp != NULL)
if (tmp != NULL && psk->identity != NULL)
{
XMEMCPY(tmp, psk->identity, psk->identityLen);
XFREE(psk->identity, ssl->heap, DYNAMIC_TYPE_TLSX);
Expand Down
2 changes: 1 addition & 1 deletion src/pk.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ static int der_to_enc_pem_alloc(unsigned char* der, int derSz,
#ifdef WOLFSSL_NO_REALLOC
tmpBuf = (byte*)XMALLOC((size_t)(derSz + blockSz), heap,
DYNAMIC_TYPE_TMP_BUFFER);
if (tmpBuf != NULL)
if (tmpBuf != NULL && der != NULL)
{
XMEMCPY(tmpBuf, der, (size_t)(derSz));
XFREE(der, heap, DYNAMIC_TYPE_TMP_BUFFER);
Expand Down
4 changes: 2 additions & 2 deletions src/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -24809,7 +24809,7 @@ int wolfSSL_BUF_MEM_grow_ex(WOLFSSL_BUF_MEM* buf, size_t len,

#ifdef WOLFSSL_NO_REALLOC
tmp = (char*)XMALLOC(mx, NULL, DYNAMIC_TYPE_OPENSSL);
if (tmp != NULL) {
if (tmp != NULL && buf->data != NULL) {
XMEMCPY(tmp, buf->data, len_int);
XFREE(buf->data, NULL, DYNAMIC_TYPE_OPENSSL);
buf->data = NULL;
Expand Down Expand Up @@ -24862,7 +24862,7 @@ int wolfSSL_BUF_MEM_resize(WOLFSSL_BUF_MEM* buf, size_t len)
/* We want to shrink the internal buffer */
#ifdef WOLFSSL_NO_REALLOC
tmp = (char*)XMALLOC(mx, NULL, DYNAMIC_TYPE_OPENSSL);
if (tmp != NULL )
if (tmp != NULL && buf->data != NULL)
{
XMEMCPY(tmp, buf->data, len);
XFREE(buf->data,NULL,DYNAMIC_TYPE_OPENSSL);
Expand Down
2 changes: 1 addition & 1 deletion src/ssl_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ static int wolfssl_asn1_bit_string_grow(WOLFSSL_ASN1_BIT_STRING* bitStr,

#ifdef WOLFSSL_NO_REALLOC
tmp = (byte*)XMALLOC((size_t)len, NULL, DYNAMIC_TYPE_OPENSSL);
if (tmp != NULL) {
if (tmp != NULL && bitStr->data != NULL) {
XMEMCPY(tmp, bitStr->data, bitStr->length);
XFREE(bitStr->data, NULL, DYNAMIC_TYPE_OPENSSL);
bitStr->data = NULL;
Expand Down

0 comments on commit f1e06e1

Please sign in to comment.