From b756626a3732869875c50f150bddacfbcac5a7ab Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Tue, 28 Apr 2020 17:45:53 +0100 Subject: [PATCH] Allow OSSL_PARAM_get_octet_string() to pass a NULL buffer We may just want to know the number of octets so allow passing a NULL buffer. Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/11635) --- crypto/params.c | 5 ++++- doc/man3/OSSL_PARAM_int.pod | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/crypto/params.c b/crypto/params.c index 32161d0533..06ae1bc44f 100644 --- a/crypto/params.c +++ b/crypto/params.c @@ -780,7 +780,7 @@ static int get_string_internal(const OSSL_PARAM *p, void **val, size_t max_len, { size_t sz; - if (val == NULL || p == NULL || p->data_type != type) + if ((val == NULL && used_len == NULL) || p == NULL || p->data_type != type) return 0; sz = p->data_size; @@ -793,6 +793,9 @@ static int get_string_internal(const OSSL_PARAM *p, void **val, size_t max_len, if (p->data == NULL) return 0; + if (val == NULL) + return 1; + if (*val == NULL) { char *const q = OPENSSL_malloc(sz); diff --git a/doc/man3/OSSL_PARAM_int.pod b/doc/man3/OSSL_PARAM_int.pod index 9126906883..09215184a7 100644 --- a/doc/man3/OSSL_PARAM_int.pod +++ b/doc/man3/OSSL_PARAM_int.pod @@ -233,7 +233,9 @@ OSSL_PARAM_get_octet_string() retrieves an OCTET string from the parameter pointed to by B

. The OCTETs are either stored into B<*val> with a length limit of B or, in the case when B<*val> is B, memory is allocated and -B is ignored. +B is ignored. B<*used_len> is populated with the number of OCTETs +stored. If B is NULL then the OCTETS are not stored, but B<*used_len> is +still populated. If memory is allocated by this function, it must be freed by the caller. OSSL_PARAM_set_octet_string() sets an OCTET string from the parameter -- 2.25.1