Peer review feedback.

This commit is contained in:
David Garske
2021-04-08 08:06:45 -07:00
parent 4747ba9ccb
commit f298bb9f22

View File

@ -329,6 +329,7 @@ static int wolfSSL_BIO_BASE64_write(WOLFSSL_BIO* bio, const void* data,
} }
if (sz == 0) { if (sz == 0) {
*outLen = 0;
return 0; /* nothing to do */ return 0; /* nothing to do */
} }
@ -338,18 +339,19 @@ static int wolfSSL_BIO_BASE64_write(WOLFSSL_BIO* bio, const void* data,
if (*out == NULL) { if (*out == NULL) {
WOLFSSL_MSG("Memory error"); WOLFSSL_MSG("Memory error");
return WOLFSSL_FATAL_ERROR; return WOLFSSL_FATAL_ERROR;
} }
tmp = *out; tmp = *out;
} }
else { else {
if (sz > *outLen) { if (sz > *outLen) {
/* use existing buffer as input */ /* use existing buffer as input */
*out = (byte*)XREALLOC(*out, sz, heap, DYNAMIC_TYPE_TMP_BUFFER); tmp = (byte*)XREALLOC(*out, sz, heap, DYNAMIC_TYPE_TMP_BUFFER);
if (*out == NULL) { if (tmp == NULL) {
WOLFSSL_MSG("Memory error"); /* out is free'd by caller */
return WOLFSSL_FATAL_ERROR; WOLFSSL_MSG("Realloc memory error");
} return WOLFSSL_FATAL_ERROR;
}
*out = tmp;
} }
data = *out; data = *out;
inLen = *outLen; inLen = *outLen;
@ -357,22 +359,24 @@ static int wolfSSL_BIO_BASE64_write(WOLFSSL_BIO* bio, const void* data,
tmp = (byte*)XMALLOC(sz, heap, DYNAMIC_TYPE_TMP_BUFFER); tmp = (byte*)XMALLOC(sz, heap, DYNAMIC_TYPE_TMP_BUFFER);
} }
*outLen = sz; ret = inLen; /* For successful encode return inLen */
ret = inLen; /* For successful Encode return inLen */
if (bio->flags & WOLFSSL_BIO_FLAG_BASE64_NO_NL) { if (bio->flags & WOLFSSL_BIO_FLAG_BASE64_NO_NL) {
if (Base64_Encode_NoNl((const byte*)data, inLen, if (Base64_Encode_NoNl((const byte*)data, inLen,
tmp, outLen) < 0) { tmp, &sz) < 0) {
ret = WOLFSSL_FATAL_ERROR; ret = WOLFSSL_FATAL_ERROR;
} }
} }
else { else {
if (Base64_Encode((const byte*)data, inLen, if (Base64_Encode((const byte*)data, inLen,
tmp, outLen) < 0) { tmp, &sz) < 0) {
ret = WOLFSSL_FATAL_ERROR; ret = WOLFSSL_FATAL_ERROR;
} }
} }
if (ret >= 0) {
*outLen = sz;
}
/* free temp */ /* if temp used, copy and free */
if (tmp != *out) { if (tmp != *out) {
XMEMCPY(*out, tmp, *outLen); XMEMCPY(*out, tmp, *outLen);
XFREE(tmp, heap, DYNAMIC_TYPE_TMP_BUFFER); XFREE(tmp, heap, DYNAMIC_TYPE_TMP_BUFFER);