mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-30 10:47:28 +02:00
Merge pull request #8426 from SparkiDev/read_der_bio_small_data_fix
Read DER BIO: fix for when BIO data is less than seq buffer size
This commit is contained in:
6
src/pk.c
6
src/pk.c
@ -1558,7 +1558,11 @@ static int wolfssl_read_der_bio(WOLFSSL_BIO* bio, unsigned char** out)
|
|||||||
WOLFSSL_ERROR_MSG("Malloc failure");
|
WOLFSSL_ERROR_MSG("Malloc failure");
|
||||||
err = 1;
|
err = 1;
|
||||||
}
|
}
|
||||||
if (!err) {
|
if ((!err) && (derLen <= (int)sizeof(seq))) {
|
||||||
|
/* Copy the previously read data into the buffer. */
|
||||||
|
XMEMCPY(der, seq, derLen);
|
||||||
|
}
|
||||||
|
else if (!err) {
|
||||||
/* Calculate the unread amount. */
|
/* Calculate the unread amount. */
|
||||||
int len = derLen - (int)sizeof(seq);
|
int len = derLen - (int)sizeof(seq);
|
||||||
/* Copy the previously read data into the buffer. */
|
/* Copy the previously read data into the buffer. */
|
||||||
|
@ -72663,10 +72663,15 @@ static int test_wolfSSL_d2i_PrivateKeys_bio(void)
|
|||||||
|
|
||||||
#if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
|
#if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
|
||||||
{
|
{
|
||||||
|
const unsigned char seqOnly[] = { 0x30, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
RSA* rsa = NULL;
|
RSA* rsa = NULL;
|
||||||
/* Tests bad parameters */
|
/* Tests bad parameters */
|
||||||
ExpectNull(d2i_RSAPrivateKey_bio(NULL, NULL));
|
ExpectNull(d2i_RSAPrivateKey_bio(NULL, NULL));
|
||||||
|
|
||||||
|
/* Test using bad data. */
|
||||||
|
ExpectIntGT(BIO_write(bio, seqOnly, sizeof(seqOnly)), 0);
|
||||||
|
ExpectNull(d2i_RSAPrivateKey_bio(bio, NULL));
|
||||||
|
|
||||||
/* RSA not set yet, expecting to fail*/
|
/* RSA not set yet, expecting to fail*/
|
||||||
rsa = wolfSSL_RSA_new();
|
rsa = wolfSSL_RSA_new();
|
||||||
ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
|
ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
|
||||||
|
Reference in New Issue
Block a user