mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-02 20:24:39 +02:00
Added some bad argument checks on compatibility functions BIO_new_mem_buf
and PEM_read_bio_PrivateKey
.
This commit is contained in:
11
src/ssl.c
11
src/ssl.c
@@ -11599,12 +11599,15 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
|
||||
WOLFSSL_BIO* wolfSSL_BIO_new_mem_buf(void* buf, int len)
|
||||
{
|
||||
WOLFSSL_BIO* bio = NULL;
|
||||
if (buf == NULL)
|
||||
|
||||
if (buf == NULL || len < 0) {
|
||||
return bio;
|
||||
}
|
||||
|
||||
bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
|
||||
if (bio == NULL)
|
||||
if (bio == NULL) {
|
||||
return bio;
|
||||
}
|
||||
|
||||
bio->memLen = bio->wrSz = len;
|
||||
bio->mem = (byte*)XMALLOC(len, 0, DYNAMIC_TYPE_OPENSSL);
|
||||
@@ -27389,6 +27392,10 @@ WOLFSSL_EVP_PKEY* wolfSSL_PEM_read_bio_PrivateKey(WOLFSSL_BIO* bio,
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_PEM_read_bio_PrivateKey");
|
||||
|
||||
if (bio == NULL) {
|
||||
return pkey;
|
||||
}
|
||||
|
||||
if ((ret = wolfSSL_BIO_pending(bio)) > 0) {
|
||||
memSz = ret;
|
||||
mem = (char*)XMALLOC(memSz, bio->heap, DYNAMIC_TYPE_OPENSSL);
|
||||
|
10
tests/api.c
10
tests/api.c
@@ -15712,7 +15712,10 @@ static void test_wolfSSL_PEM_PrivateKey(void)
|
||||
AssertIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
|
||||
WOLFSSL_SUCCESS);
|
||||
|
||||
/* test of creating new EVP_PKEY */
|
||||
/* test creating new EVP_PKEY with bad arg */
|
||||
AssertNull((pkey2 = PEM_read_bio_PrivateKey(NULL, NULL, NULL, NULL)));
|
||||
|
||||
/* test creating new EVP_PKEY with good args */
|
||||
AssertNotNull((pkey2 = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
|
||||
AssertIntEQ((int)XMEMCMP(pkey->pkey.ptr, pkey2->pkey.ptr, pkey->pkey_sz),0);
|
||||
|
||||
@@ -17518,6 +17521,11 @@ static void test_wolfSSL_BIO_gets(void)
|
||||
|
||||
printf(testingFmt, "wolfSSL_X509_BIO_gets()");
|
||||
|
||||
/* try with bad args */
|
||||
AssertNull(bio = BIO_new_mem_buf(NULL, sizeof(msg)));
|
||||
AssertNull(bio = BIO_new_mem_buf((void*)msg, -1));
|
||||
|
||||
/* try with real msg */
|
||||
AssertNotNull(bio = BIO_new_mem_buf((void*)msg, sizeof(msg)));
|
||||
XMEMSET(buffer, 0, bufferSz);
|
||||
AssertNotNull(BIO_push(bio, BIO_new(BIO_s_bio())));
|
||||
|
Reference in New Issue
Block a user