Browse code

OpenSSL: force meth->name as non-const when we free() it

We are in control of meth->name (we string_alloc() it in RSA_meth_new())
so we know that we can free() it when it's no longer needed. Yet we have
to force the value to be non-const to avoid a compiler warning -- due to
the fact that OpenSSL defines the value as a const char*, regardless of
its origin.

Acked-by: Steffan Karger <steffan.karger@fox-it.com>
Message-Id: <20170612134330.20971-9-logout@free.fr>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg14798.html

Signed-off-by: Gert Doering <gert@greenie.muc.de>

Emmanuel Deloget authored on 2017/06/12 22:43:30
Showing 1 changed files
... ...
@@ -349,7 +349,13 @@ RSA_meth_free(RSA_METHOD *meth)
349 349
 {
350 350
     if (meth)
351 351
     {
352
-        free(meth->name);
352
+        /* OpenSSL defines meth->name to be a const pointer, yet we
353
+         * feed it with an allocated string (from RSA_meth_new()).
354
+         * Thus we are allowed to free it here. In order to avoid a
355
+         * "passing 'const char *' to parameter of type 'void *' discards
356
+         * qualifiers" warning, we force the pointer to be a non-const value.
357
+         */
358
+        free((char *)meth->name);
353 359
         free(meth);
354 360
     }
355 361
 }