# HG changeset patch
# User Michael Elkins <[email protected]>
# Date 1382235081 0
# Branch HEAD
# Node ID 9dc236a24e7cfe905deb8637223bf69d06945876
# Parent  84acf5f0ce9245ccbe0ed2bed5ee9c71174fe9b9
Ensure that at least one signature was generated to catch the case where 
$pgp_sign_as is unset and no default key is specified in ~/.gnupg/gpg.conf

closes #3658

diff --git a/crypt-gpgme.c b/crypt-gpgme.c
--- a/crypt-gpgme.c
+++ b/crypt-gpgme.c
@@ -818,6 +818,7 @@
   char buf[100];
   gpgme_ctx_t ctx;
   gpgme_data_t message, signature;
+  gpgme_sign_result_t sigres;
 
   convert_to_7bit (a); /* Signed data _must_ be in 7-bit format. */
 
@@ -859,6 +860,17 @@
       mutt_error (_("error signing data: %s\n"), gpgme_strerror (err));
       return NULL;
     }
+  /* Check for zero signatures generated.  This can occur when $pgp_sign_as is
+   * unset and there is no default key specified in ~/.gnupg/gpg.conf
+   */
+  sigres = gpgme_op_sign_result (ctx);
+  if (!sigres->signatures)
+  {
+      gpgme_data_release (signature);
+      gpgme_release (ctx);
+      mutt_error (_("$pgp_sign_as unset and no default key specified in 
~/.gnupg/gpg.conf"));
+      return NULL;
+  }
 
   sigfile = data_object_to_tempfile (signature, NULL);
   gpgme_data_release (signature);

Reply via email to