- remove insane heap walk and kernel loading code; clean up style and calling conventions
[openssl.git] / crypto / dsa / dsa_meth.c
index 237f555c083948d9f9eeeb790fefc1c144b53c2a..1d27ceae1ce11ee0735cb3687f9863f2296cdb59 100644 (file)
@@ -1,3 +1,12 @@
+/*
+ * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License").  You may not use
+ * this file except in compliance with the License.  You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
 /*
  * Licensed under the OpenSSL licenses, (the "License");
  * you may not use this file except in compliance with the License.
@@ -8,6 +17,7 @@
 
 #include "dsa_locl.h"
 #include <string.h>
+#include <openssl/err.h>
 
 DSA_METHOD *DSA_meth_new(const char *name, int flags)
 {
@@ -15,6 +25,11 @@ DSA_METHOD *DSA_meth_new(const char *name, int flags)
 
     if (dsam != NULL) {
         dsam->name = OPENSSL_strdup(name);
+        if (dsam->name == NULL) {
+            OPENSSL_free(dsam);
+            DSAerr(DSA_F_DSA_METH_NEW, ERR_R_MALLOC_FAILURE);
+            return NULL;
+        }
         dsam->flags = flags;
     }
 
@@ -24,8 +39,7 @@ DSA_METHOD *DSA_meth_new(const char *name, int flags)
 void DSA_meth_free(DSA_METHOD *dsam)
 {
     if (dsam != NULL) {
-        if (dsam->name != NULL)
-            OPENSSL_free(dsam->name);
+        OPENSSL_free(dsam->name);
         OPENSSL_free(dsam);
     }
 }
@@ -39,6 +53,11 @@ DSA_METHOD *DSA_meth_dup(const DSA_METHOD *dsam)
     if (ret != NULL) {
         memcpy(ret, dsam, sizeof(*dsam));
         ret->name = OPENSSL_strdup(dsam->name);
+        if (ret->name == NULL) {
+            OPENSSL_free(ret);
+            DSAerr(DSA_F_DSA_METH_DUP, ERR_R_MALLOC_FAILURE);
+            return NULL;
+        }
     }
 
     return ret;
@@ -51,10 +70,18 @@ const char *DSA_meth_get0_name(const DSA_METHOD *dsam)
 
 int DSA_meth_set1_name(DSA_METHOD *dsam, const char *name)
 {
+    char *tmpname;
+
+    tmpname = OPENSSL_strdup(name);
+    if (tmpname == NULL) {
+        DSAerr(DSA_F_DSA_METH_SET1_NAME, ERR_R_MALLOC_FAILURE);
+        return 0;
+    }
+
     OPENSSL_free(dsam->name);
-    dsam->name = OPENSSL_strdup(name);
+    dsam->name = tmpname;
 
-    return dsam->name != NULL;
+    return 1;
 }
 
 int DSA_meth_get_flags(DSA_METHOD *dsam)
@@ -68,12 +95,12 @@ int DSA_meth_set_flags(DSA_METHOD *dsam, int flags)
     return 1;
 }
 
-void *DSA_meth_get_app_data(const DSA_METHOD *dsam)
+void *DSA_meth_get0_app_data(const DSA_METHOD *dsam)
 {
     return dsam->app_data;
 }
 
-int DSA_meth_set_app_data(DSA_METHOD *dsam, void *app_data)
+int DSA_meth_set0_app_data(DSA_METHOD *dsam, void *app_data)
 {
     dsam->app_data = app_data;
     return 1;