OSSL_PARAM_BLD and BIGNUM; ensure at least one byte is allocated

A zero BIGNUM contains zero bytes, while OSSL_PARAMs with an INTEGER (or
UNSIGNED INTEGER) data type are expected to have at least one data byte
allocated, containing a zero.  This wasn't handled correctly.

Fixes #20011

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20013)
This commit is contained in:
Richard Levitte 2023-01-10 08:27:44 +01:00
parent c2ae891483
commit c455f87aeb
1 changed files with 4 additions and 0 deletions

View File

@ -218,6 +218,10 @@ static int push_BN(OSSL_PARAM_BLD *bld, const char *key,
}
if (BN_get_flags(bn, BN_FLG_SECURE) == BN_FLG_SECURE)
secure = 1;
/* The BIGNUM is zero, we must transfer at least one byte */
if (sz == 0)
sz++;
}
pd = param_push(bld, key, sz, sz, type, secure);
if (pd == NULL)