Swap to using _longjmp/_setjmp instead of longjmp/setjmp
[oweals/openssl.git] / crypto / store / str_lib.c
index 227b797b5949477d9a62346a810d74a984b1b8eb..c2e6b8e8d1f31c0e7c4eabf3a25d0d7eeab2f6ae 100644 (file)
@@ -109,7 +109,7 @@ STORE *STORE_new_method(const STORE_METHOD *method)
         return NULL;
     }
 
-    ret = (STORE *)OPENSSL_malloc(sizeof(STORE));
+    ret = OPENSSL_malloc(sizeof(*ret));
     if (ret == NULL) {
         STOREerr(STORE_F_STORE_NEW_METHOD, ERR_R_MALLOC_FAILURE);
         return NULL;
@@ -251,8 +251,7 @@ X509 *STORE_get_certificate(STORE *s, OPENSSL_ITEM attributes[],
                  STORE_R_FAILED_GETTING_CERTIFICATE);
         return 0;
     }
-    CRYPTO_add(&object->data.x509.certificate->references, 1,
-               CRYPTO_LOCK_X509);
+    X509_up_ref(object->data.x509.certificate);
 #ifdef REF_PRINT
     REF_PRINT("X509", data);
 #endif
@@ -267,16 +266,16 @@ int STORE_store_certificate(STORE *s, X509 *data, OPENSSL_ITEM attributes[],
     STORE_OBJECT *object;
     int i;
 
-    check_store(s, STORE_F_STORE_CERTIFICATE,
+    check_store(s, STORE_F_STORE_STORE_CERTIFICATE,
                 store_object, STORE_R_NO_STORE_OBJECT_FUNCTION);
 
     object = STORE_OBJECT_new();
-    if (!object) {
+    if (object == NULL) {
         STOREerr(STORE_F_STORE_STORE_CERTIFICATE, ERR_R_MALLOC_FAILURE);
         return 0;
     }
 
-    CRYPTO_add(&data->references, 1, CRYPTO_LOCK_X509);
+    X509_up_ref(data);
 #ifdef REF_PRINT
     REF_PRINT("X509", data);
 #endif
@@ -378,8 +377,7 @@ X509 *STORE_list_certificate_next(STORE *s, void *handle)
                  STORE_R_FAILED_LISTING_CERTIFICATES);
         return 0;
     }
-    CRYPTO_add(&object->data.x509.certificate->references, 1,
-               CRYPTO_LOCK_X509);
+    X509_up_ref(object->data.x509.certificate);
 #ifdef REF_PRINT
     REF_PRINT("X509", data);
 #endif
@@ -473,12 +471,12 @@ int STORE_store_private_key(STORE *s, EVP_PKEY *data,
                 store_object, STORE_R_NO_STORE_OBJECT_FUNCTION);
 
     object = STORE_OBJECT_new();
-    if (!object) {
+    if (object == NULL) {
         STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY, ERR_R_MALLOC_FAILURE);
         return 0;
     }
     object->data.key = EVP_PKEY_new();
-    if (!object->data.key) {
+    if (object->data.key == NULL) {
         STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY, ERR_R_MALLOC_FAILURE);
         return 0;
     }
@@ -657,12 +655,12 @@ int STORE_store_public_key(STORE *s, EVP_PKEY *data,
                 store_object, STORE_R_NO_STORE_OBJECT_FUNCTION);
 
     object = STORE_OBJECT_new();
-    if (!object) {
+    if (object == NULL) {
         STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY, ERR_R_MALLOC_FAILURE);
         return 0;
     }
     object->data.key = EVP_PKEY_new();
-    if (!object->data.key) {
+    if (object->data.key == NULL) {
         STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY, ERR_R_MALLOC_FAILURE);
         return 0;
     }
@@ -821,7 +819,7 @@ X509_CRL *STORE_generate_crl(STORE *s, OPENSSL_ITEM attributes[],
         STOREerr(STORE_F_STORE_GENERATE_CRL, STORE_R_FAILED_GENERATING_CRL);
         return 0;
     }
-    CRYPTO_add(&object->data.crl->references, 1, CRYPTO_LOCK_X509_CRL);
+    X509_CRL_up_ref(object->data.crl);
 #ifdef REF_PRINT
     REF_PRINT("X509_CRL", data);
 #endif
@@ -845,7 +843,7 @@ X509_CRL *STORE_get_crl(STORE *s, OPENSSL_ITEM attributes[],
         STOREerr(STORE_F_STORE_GET_CRL, STORE_R_FAILED_GETTING_KEY);
         return 0;
     }
-    CRYPTO_add(&object->data.crl->references, 1, CRYPTO_LOCK_X509_CRL);
+    X509_CRL_up_ref(object->data.crl);
 #ifdef REF_PRINT
     REF_PRINT("X509_CRL", data);
 #endif
@@ -864,12 +862,12 @@ int STORE_store_crl(STORE *s, X509_CRL *data, OPENSSL_ITEM attributes[],
                 store_object, STORE_R_NO_STORE_OBJECT_FUNCTION);
 
     object = STORE_OBJECT_new();
-    if (!object) {
+    if (object == NULL) {
         STOREerr(STORE_F_STORE_STORE_CRL, ERR_R_MALLOC_FAILURE);
         return 0;
     }
 
-    CRYPTO_add(&data->references, 1, CRYPTO_LOCK_X509_CRL);
+    X509_CRL_up_ref(data);
 #ifdef REF_PRINT
     REF_PRINT("X509_CRL", data);
 #endif
@@ -950,7 +948,7 @@ X509_CRL *STORE_list_crl_next(STORE *s, void *handle)
         STOREerr(STORE_F_STORE_LIST_CRL_NEXT, STORE_R_FAILED_LISTING_KEYS);
         return 0;
     }
-    CRYPTO_add(&object->data.crl->references, 1, CRYPTO_LOCK_X509_CRL);
+    X509_CRL_up_ref(object->data.crl);
 #ifdef REF_PRINT
     REF_PRINT("X509_CRL", data);
 #endif
@@ -993,7 +991,7 @@ int STORE_store_number(STORE *s, BIGNUM *data, OPENSSL_ITEM attributes[],
                 store_object, STORE_R_NO_STORE_OBJECT_NUMBER_FUNCTION);
 
     object = STORE_OBJECT_new();
-    if (!object) {
+    if (object == NULL) {
         STOREerr(STORE_F_STORE_STORE_NUMBER, ERR_R_MALLOC_FAILURE);
         return 0;
     }
@@ -1077,7 +1075,7 @@ int STORE_store_arbitrary(STORE *s, BUF_MEM *data, OPENSSL_ITEM attributes[],
                 store_object, STORE_R_NO_STORE_OBJECT_ARBITRARY_FUNCTION);
 
     object = STORE_OBJECT_new();
-    if (!object) {
+    if (object == NULL) {
         STOREerr(STORE_F_STORE_STORE_ARBITRARY, ERR_R_MALLOC_FAILURE);
         return 0;
     }
@@ -1156,9 +1154,7 @@ int STORE_delete_arbitrary(STORE *s, OPENSSL_ITEM attributes[],
 
 STORE_OBJECT *STORE_OBJECT_new(void)
 {
-    STORE_OBJECT *object = OPENSSL_malloc(sizeof(STORE_OBJECT));
-    if (object)
-        memset(object, 0, sizeof(STORE_OBJECT));
+    STORE_OBJECT *object = OPENSSL_zalloc(sizeof(*object));
     return object;
 }
 
@@ -1187,8 +1183,6 @@ void STORE_OBJECT_free(STORE_OBJECT *data)
     OPENSSL_free(data);
 }
 
-IMPLEMENT_STACK_OF(STORE_OBJECT*)
-
 struct STORE_attr_info_st {
     unsigned char set[(STORE_ATTR_TYPE_NUM + 8) / 8];
     union {
@@ -1208,7 +1202,9 @@ struct STORE_attr_info_st {
 
 STORE_ATTR_INFO *STORE_ATTR_INFO_new(void)
 {
-    return (STORE_ATTR_INFO *)OPENSSL_malloc(sizeof(STORE_ATTR_INFO));
+    STORE_ATTR_INFO *p = OPENSSL_malloc(sizeof(*p));
+
+    return p;
 }
 
 static void STORE_ATTR_INFO_attr_free(STORE_ATTR_INFO *attrs,
@@ -1452,9 +1448,8 @@ struct attr_list_ctx_st {
 void *STORE_parse_attrs_start(OPENSSL_ITEM *attributes)
 {
     if (attributes) {
-        struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)
-            OPENSSL_malloc(sizeof(struct attr_list_ctx_st));
-        if (context)
+        struct attr_list_ctx_st *context = OPENSSL_malloc(sizeof(*context));
+        if (context != NULL)
             context->attributes = attributes;
         else
             STOREerr(STORE_F_STORE_PARSE_ATTRS_START, ERR_R_MALLOC_FAILURE);
@@ -1478,7 +1473,7 @@ STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle)
             case STORE_ATTR_FRIENDLYNAME:
             case STORE_ATTR_EMAIL:
             case STORE_ATTR_FILENAME:
-                if (!attrs)
+                if (attrs == NULL)
                     attrs = STORE_ATTR_INFO_new();
                 if (attrs == NULL) {
                     STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
@@ -1495,7 +1490,7 @@ STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle)
             case STORE_ATTR_SUBJECTKEYID:
             case STORE_ATTR_ISSUERSERIALHASH:
             case STORE_ATTR_CERTHASH:
-                if (!attrs)
+                if (attrs == NULL)
                     attrs = STORE_ATTR_INFO_new();
                 if (attrs == NULL) {
                     STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
@@ -1509,7 +1504,7 @@ STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle)
                 break;
             case STORE_ATTR_ISSUER:
             case STORE_ATTR_SUBJECT:
-                if (!attrs)
+                if (attrs == NULL)
                     attrs = STORE_ATTR_INFO_new();
                 if (attrs == NULL) {
                     STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
@@ -1521,7 +1516,7 @@ STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle)
                                           context->attributes->value);
                 break;
             case STORE_ATTR_SERIAL:
-                if (!attrs)
+                if (attrs == NULL)
                     attrs = STORE_ATTR_INFO_new();
                 if (attrs == NULL) {
                     STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,