Fix a memory leak in ossl_method_store_add()
authorMatt Caswell <matt@openssl.org>
Thu, 2 Jun 2022 10:14:32 +0000 (11:14 +0100)
committerMatt Caswell <matt@openssl.org>
Thu, 9 Jun 2022 10:37:31 +0000 (11:37 +0100)
If the call to ossl_prop_defn_set() fails then the OSSL_PROPERTY_LIST
we just created will leak.

Found as a result of:
https://github.com/openssl/openssl/pull/18355#issuecomment-1139499881

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18458)

crypto/property/property.c

index d209f2c79dbfdd376c543fe404f3db7503d5bb6e..fb48022a8f057a7ed2cb375f7cd2054905b1138e 100644 (file)
@@ -304,7 +304,11 @@ int ossl_method_store_add(OSSL_METHOD_STORE *store, const OSSL_PROVIDER *prov,
         impl->properties = ossl_parse_property(store->ctx, properties);
         if (impl->properties == NULL)
             goto err;
-        ossl_prop_defn_set(store->ctx, properties, impl->properties);
+        if (!ossl_prop_defn_set(store->ctx, properties, impl->properties)) {
+            ossl_property_free(impl->properties);
+            impl->properties = NULL;
+            goto err;
+        }
     }
 
     alg = ossl_method_store_retrieve(store, nid);