]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
In OSSL_PARAM_set_BN(), make sure that the data_size field is at least 1
authorRichard Levitte <levitte@openssl.org>
Tue, 10 Jan 2023 11:22:39 +0000 (12:22 +0100)
committerRichard Levitte <levitte@openssl.org>
Wed, 11 Jan 2023 22:38:13 +0000 (23:38 +0100)
This way, we guarantee that a zero is represented with one byte of data
that's set to zero.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20013)

crypto/params.c

index 4c5a6f53341ce9086aa5b869dd1d398f1d3bdb49..f75cfe69cfdc89ae2ddf54038a92ec3444381859 100644 (file)
@@ -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)