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
pull/8424/head
David Garske 2025-02-06 16:21:42 -08:00 committed by GitHub
commit c668a4e5a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -1558,7 +1558,11 @@ static int wolfssl_read_der_bio(WOLFSSL_BIO* bio, unsigned char** out)
WOLFSSL_ERROR_MSG("Malloc failure");
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. */
int len = derLen - (int)sizeof(seq);
/* Copy the previously read data into the buffer. */

View File

@ -72663,10 +72663,15 @@ static int test_wolfSSL_d2i_PrivateKeys_bio(void)
#if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
{
const unsigned char seqOnly[] = { 0x30, 0x00, 0x00, 0x00, 0x00, 0x00 };
RSA* rsa = NULL;
/* Tests bad parameters */
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 = wolfSSL_RSA_new();
ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));