Missed a mention of RT
[oweals/openssl.git] / crypto / rsa / rsa_meth.c
index b0b38ccfa3c8aeb45140778aa747e19bda76f354..ef0dc9751f240758ee80b6bc99f302dde14521d8 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <string.h>
 #include "rsa_locl.h"
+#include <openssl/err.h>
 
 RSA_METHOD *RSA_meth_new(const char *name, int flags)
 {
@@ -16,6 +17,11 @@ RSA_METHOD *RSA_meth_new(const char *name, int flags)
 
     if (meth != NULL) {
         meth->name = OPENSSL_strdup(name);
+        if (meth->name == NULL) {
+            OPENSSL_free(meth);
+            RSAerr(RSA_F_RSA_METH_NEW, ERR_R_MALLOC_FAILURE);
+            return NULL;
+        }
         meth->flags = flags;
     }
 
@@ -25,8 +31,7 @@ RSA_METHOD *RSA_meth_new(const char *name, int flags)
 void RSA_meth_free(RSA_METHOD *meth)
 {
     if (meth != NULL) {
-        if (meth->name != NULL)
-            OPENSSL_free(meth->name);
+        OPENSSL_free(meth->name);
         OPENSSL_free(meth);
     }
 }
@@ -40,6 +45,11 @@ RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth)
     if (ret != NULL) {
         memcpy(ret, meth, sizeof(*meth));
         ret->name = OPENSSL_strdup(meth->name);
+        if (ret->name == NULL) {
+            OPENSSL_free(ret);
+            RSAerr(RSA_F_RSA_METH_DUP, ERR_R_MALLOC_FAILURE);
+            return NULL;
+        }
     }
 
     return ret;
@@ -52,10 +62,18 @@ const char *RSA_meth_get0_name(const RSA_METHOD *meth)
 
 int RSA_meth_set1_name(RSA_METHOD *meth, const char *name)
 {
+    char *tmpname;
+
+    tmpname = OPENSSL_strdup(name);
+    if (tmpname == NULL) {
+        RSAerr(RSA_F_RSA_METH_SET1_NAME, ERR_R_MALLOC_FAILURE);
+        return 0;
+    }
+
     OPENSSL_free(meth->name);
-    meth->name = OPENSSL_strdup(name);
+    meth->name = tmpname;
 
-    return meth->name != NULL;
+    return 1;
 }
 
 int RSA_meth_get_flags(RSA_METHOD *meth)