]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
apps/cms.c: add missing error messages in various error cases
authorDr. David von Oheimb <dev@ddvo.net>
Sun, 13 Apr 2025 07:58:06 +0000 (09:58 +0200)
committerDr. David von Oheimb <dev@ddvo.net>
Wed, 14 May 2025 06:43:20 +0000 (08:43 +0200)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/27368)

apps/cms.c

index 6f19414880c905daa7d7647551504b2ccca02749..346fb7bce4c221a073cefe3f370d07d48d477a19 100644 (file)
@@ -1093,8 +1093,10 @@ int cms_main(int argc, char **argv)
             }
             flags |= CMS_PARTIAL;
             cms = CMS_sign_ex(NULL, NULL, other, in, flags, libctx, app_get0_propq());
-            if (cms == NULL)
+            if (cms == NULL) {
+                BIO_puts(bio_err, "CMS SignedData Creation Error\n");
                 goto end;
+            }
             if (econtent_type != NULL)
                 CMS_set1_eContentType(cms, econtent_type);
 
@@ -1132,30 +1134,38 @@ int cms_main(int argc, char **argv)
                 }
             }
             si = CMS_add1_signer(cms, signer, key, sign_md, tflags);
-            if (si == NULL)
+            if (si == NULL) {
+                BIO_printf(bio_err, "Error adding SignerInfo with key from %s\n", keyfile);
                 goto end;
+            }
+
             if (kparam != NULL) {
-                EVP_PKEY_CTX *pctx;
-                pctx = CMS_SignerInfo_get0_pkey_ctx(si);
+                EVP_PKEY_CTX *pctx = CMS_SignerInfo_get0_pkey_ctx(si);
+
                 if (!cms_set_pkey_param(pctx, kparam->param))
                     goto end;
             }
-            if (rr != NULL && !CMS_add1_ReceiptRequest(si, rr))
+            if (rr != NULL && !CMS_add1_ReceiptRequest(si, rr)) {
+                BIO_puts(bio_err, "Error adding CMS ReceiptRequest\n");
                 goto end;
+            }
             X509_free(signer);
             signer = NULL;
             EVP_PKEY_free(key);
             key = NULL;
         }
         /* If not streaming or resigning finalize structure */
-        if (operation == SMIME_SIGN && digestbin != NULL
-            && (flags & CMS_STREAM) == 0) {
-            /* Use pre-computed digest instead of content */
-            if (!CMS_final_digest(cms, digestbin, digestlen, NULL, flags))
-                goto end;
-        } else if (operation == SMIME_SIGN && (flags & CMS_STREAM) == 0) {
-            if (!CMS_final(cms, in, NULL, flags))
+        if (operation == SMIME_SIGN && (flags & CMS_STREAM) == 0) {
+            int res;
+
+            if (digestbin != NULL) /* Use pre-computed digest instead of content */
+                res = CMS_final_digest(cms, digestbin, digestlen, NULL, flags);
+            else
+                res = CMS_final(cms, in, NULL, flags);
+            if (!res) {
+                BIO_puts(bio_err, "Error finalizing CMS structure\n");
                 goto end;
+            }
         }
     }