Correct return value from wolfSSL_BIO_BASE64_write()

This commit is contained in:
Tesfa Mael
2019-10-11 14:52:53 -07:00
parent cd934a95a4
commit ccc500e13f
2 changed files with 13 additions and 9 deletions

View File

@ -274,7 +274,7 @@ static int wolfSSL_BIO_BASE64_write(WOLFSSL_BIO* bio, const void* data,
}
if (ret != WOLFSSL_FATAL_ERROR) {
ret = (int)*outLen;
ret = (int) inLen;
XMEMCPY(out, tmp, *outLen);
}
@ -427,6 +427,7 @@ static int wolfSSL_BIO_MEMORY_write(WOLFSSL_BIO* bio, const void* data,
int wolfSSL_BIO_write(WOLFSSL_BIO* bio, const void* data, int len)
{
int ret = 0;
int retB64 = 0;
WOLFSSL_BIO* front = bio;
void* frmt = NULL;
word32 frmtSz = 0;
@ -494,8 +495,8 @@ int wolfSSL_BIO_write(WOLFSSL_BIO* bio, const void* data, int len)
if (ret >= 0) {
/* change so that data is formated buffer */
ret = wolfSSL_BIO_BASE64_write(bio, data, (word32)len,
(byte*)frmt, &frmtSz);
retB64 = wolfSSL_BIO_BASE64_write(bio, data, (word32)len,
(byte*)frmt, &frmtSz);
data = frmt;
len = frmtSz;
}
@ -541,7 +542,10 @@ int wolfSSL_BIO_write(WOLFSSL_BIO* bio, const void* data, int len)
(const char*)data, 0, 0, ret);
}
return ret;
if (retB64 != 0)
return retB64;
else
return ret;
}

View File

@ -22982,7 +22982,7 @@ static void test_wolfSSL_BIO_write(void)
AssertNotNull(bio = BIO_push(bio64, BIO_new(BIO_s_mem())));
/* now should convert to base64 then write to memory */
AssertIntEQ(BIO_write(bio, msg, sizeof(msg)), 25);
AssertIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
BIO_flush(bio);
/* test BIO chain */
@ -22997,7 +22997,7 @@ static void test_wolfSSL_BIO_write(void)
AssertIntEQ(XMEMCMP(out, expected, sz), 0);
/* write then read should return the same message */
AssertIntEQ(BIO_write(bio, msg, sizeof(msg)), 25);
AssertIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
sz = sizeof(out);
XMEMSET(out, 0, sz);
AssertIntEQ(BIO_read(bio, out, sz), 16);
@ -23005,7 +23005,7 @@ static void test_wolfSSL_BIO_write(void)
/* now try encoding with no line ending */
BIO_set_flags(bio64, BIO_FLAG_BASE64_NO_NL);
AssertIntEQ(BIO_write(bio, msg, sizeof(msg)), 24);
AssertIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
BIO_flush(bio);
sz = sizeof(out);
XMEMSET(out, 0, sz);
@ -23019,8 +23019,8 @@ static void test_wolfSSL_BIO_write(void)
AssertNotNull(bio = BIO_push(BIO_new(BIO_f_base64()), bio64));
AssertNotNull(BIO_push(bio64, BIO_new(BIO_s_mem())));
/* now should convert to base64(x2) when stored and then decode with read */
AssertIntEQ(BIO_write(bio, msg, sizeof(msg)), 37);
/* now should convert to base64 when stored and then decode with read */
AssertIntEQ(BIO_write(bio, msg, sizeof(msg)), 25);
BIO_flush(bio);
sz = sizeof(out);
XMEMSET(out, 0, sz);