Skip to contentSkip to conversation

Ensure using const variables with EVP_PKEY_get0_*

PATCH In review Arne Schwabe 3 participants 3 messages Apr 8, 2021 – Apr 18, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Ensure using const variables with EVP_PKEY_get0_*

These functions return const pointers in OpenSSL 3.0.0alpha14, so our pointers should be also const to avoid casting the const away.

---
 src/openvpn/ssl_openssl.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
src/openvpn/ssl_openssl.c +2 -3
index cb8ac7727..a9bc342b0 100644
@@ -1248,12 +1248,11 @@ static int
 tls_ctx_use_external_rsa_key(struct tls_root_ctx *ctx, EVP_PKEY *pkey)
 {
     RSA *rsa = NULL;
-    RSA *pub_rsa;
     RSA_METHOD *rsa_meth;
 
     ASSERT(NULL != ctx);
 
-    pub_rsa = EVP_PKEY_get0_RSA(pkey);
+    const RSA *pub_rsa = EVP_PKEY_get0_RSA(pkey);
     ASSERT(NULL != pub_rsa);
 
     /* allocate custom RSA method object */
@@ -2031,7 +2030,7 @@ print_cert_details(X509 *cert, char *buf, size_t buflen)
 #ifndef OPENSSL_NO_EC
     if (typeid == EVP_PKEY_EC && EVP_PKEY_get0_EC_KEY(pkey) != NULL)
     {
-        EC_KEY *ec = EVP_PKEY_get0_EC_KEY(pkey);
+        const EC_KEY *ec = EVP_PKEY_get0_EC_KEY(pkey);
         const EC_GROUP *group = EC_KEY_get0_group(ec);
 
         int nid = EC_GROUP_get_curve_name(group);
Signature · 1 line
2.31.1
Acked-by on v1 1/1
#1 lore raw

Hi,

Quoted 4 lines · Arne Schwabe

These functions return const pointers in OpenSSL 3.0.0alpha14, so our pointers should be also const to avoid casting the const away.

Trivial change. No behaviour is expected to be modified by this.

This change improves implicit code documentation (thanks to the OpenSSL devs).

Compiled tested against various LibreSSL/OpenSSL versions and none complained about the const.

Signature · 1 line
Antonio Quartulli
#2 lore raw
In reply to Arne Schwabe

Your patch has been applied to the master branch.

I have not tested this any further, but glance-at-code looks good.

commit 6fc292d2ed008a53061ce953dea6ff1e692e6723

Author: Arne Schwabe
Date:   Thu Apr 8 15:36:26 2021 +0200
     Ensure using const variables with EVP_PKEY_get0_*

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg22081.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering