From c2ae89148343750e420b72ef1b709ebbc16e47b8 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Tue, 10 Jan 2023 12:22:39 +0100 Subject: [PATCH] In OSSL_PARAM_set_BN(), make sure that the data_size field is at least 1 This way, we guarantee that a zero is represented with one byte of data that's set to zero. Reviewed-by: Paul Dale Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/20013) --- crypto/params.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crypto/params.c b/crypto/params.c index 4c5a6f53341..f75cfe69cfd 100644 --- a/crypto/params.c +++ b/crypto/params.c @@ -1068,6 +1068,9 @@ int OSSL_PARAM_set_BN(OSSL_PARAM *p, const BIGNUM *val) /* We add 1 byte for signed numbers, to make space for a sign extension */ if (p->data_type == OSSL_PARAM_INTEGER) bytes++; + /* We make sure that at least one byte is used, so zero is properly set */ + if (bytes == 0) + bytes++; p->return_size = bytes; if (p->data == NULL) -- 2.47.3