Pull the NULL check for cmsbio into the switch
authortb <tb@openbsd.org>
Tue, 22 Aug 2023 08:59:44 +0000 (08:59 +0000)
committertb <tb@openbsd.org>
Tue, 22 Aug 2023 08:59:44 +0000 (08:59 +0000)
ok jsing

lib/libcrypto/cms/cms_lib.c

index 9f8e13d..fc89943 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: cms_lib.c,v 1.20 2023/08/22 08:44:15 tb Exp $ */
+/* $OpenBSD: cms_lib.c,v 1.21 2023/08/22 08:59:44 tb Exp $ */
 /*
  * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  * project.
@@ -152,35 +152,31 @@ CMS_dataInit(CMS_ContentInfo *cms, BIO *icont)
                CMSerror(CMS_R_NO_CONTENT);
                goto err;
        }
-       switch (OBJ_obj2nid(cms->contentType)) {
 
+       switch (OBJ_obj2nid(cms->contentType)) {
        case NID_pkcs7_data:
                return cont;
-
        case NID_pkcs7_signed:
-               cmsbio = cms_SignedData_init_bio(cms);
+               if ((cmsbio = cms_SignedData_init_bio(cms)) == NULL)
+                       goto err;
                break;
-
        case NID_pkcs7_digest:
-               cmsbio = cms_DigestedData_init_bio(cms);
+               if ((cmsbio = cms_DigestedData_init_bio(cms)) == NULL)
+                       goto err;
                break;
-
        case NID_pkcs7_encrypted:
-               cmsbio = cms_EncryptedData_init_bio(cms);
+               if ((cmsbio = cms_EncryptedData_init_bio(cms)) == NULL)
+                       goto err;
                break;
-
        case NID_pkcs7_enveloped:
-               cmsbio = cms_EnvelopedData_init_bio(cms);
+               if ((cmsbio = cms_EnvelopedData_init_bio(cms)) == NULL)
+                       goto err;
                break;
-
        default:
                CMSerror(CMS_R_UNSUPPORTED_TYPE);
                goto err;
        }
 
-       if (cmsbio == NULL)
-               goto err;
-
        return BIO_push(cmsbio, cont);
 
  err: