Add error handling to wolfSSL_BIO_get_len (#4385)

This commit is contained in:
Eric Blankenhorn 2021-09-09 17:15:30 -05:00 committed by GitHub
parent 934b0ab572
commit 649aa9c95f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -1552,12 +1552,18 @@ int wolfSSL_BIO_get_len(WOLFSSL_BIO *bio)
WOLFSSL_ENTER("wolfSSL_BIO_get_len");
if ((len = wolfSSL_BIO_pending(bio)) > 0) {
if (bio == NULL) {
WOLFSSL_MSG("WOLFSSL_BIO was null");
len = BAD_FUNC_ARG;
}
else if ((len = wolfSSL_BIO_pending(bio)) > 0) {
}
#ifndef NO_FILESYSTEM
else if (bio->type == WOLFSSL_BIO_FILE) {
if (wolfSSL_BIO_get_fp(bio, &file) != WOLFSSL_SUCCESS)
len = BAD_FUNC_ARG;
if (file == NULL)
len = WOLFSSL_BAD_FILE;
if (len == 0) {
curr = XFTELL(file);
if (curr < 0) {

View File

@ -46438,15 +46438,22 @@ static void test_wolfSSL_RSA_print(void)
static void test_wolfSSL_BIO_get_len(void)
{
#if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
BIO *bio;
BIO *bio = NULL;
const char txt[] = "Some example text to push to the BIO.";
printf(testingFmt, "wolfSSL_BIO_get_len");
AssertIntEQ(wolfSSL_BIO_get_len(bio), BAD_FUNC_ARG);
AssertNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
AssertIntEQ(wolfSSL_BIO_write(bio, txt, sizeof(txt)), sizeof(txt));
AssertIntEQ(wolfSSL_BIO_get_len(bio), sizeof(txt));
BIO_free(bio);
AssertNotNull(bio = BIO_new_fd(STDOUT_FILENO, BIO_NOCLOSE));
AssertIntEQ(wolfSSL_BIO_get_len(bio), WOLFSSL_BAD_FILE);
BIO_free(bio);
printf(resultFmt, passed);
#endif
}