changeset: 6382:5530e9fb17d9
user: Kevin McCarthy <[email protected]>
date: Wed Dec 31 20:35:38 2014 -0800
link: http://dev.mutt.org/hg/mutt/rev/5530e9fb17d9
Fix segfault of extract-keys (^K) under gpgme. (closes #3698)
This patch is based on the patch by Ben Price, which relocated the
safe_fclose (&in) after its use by keydata in pgp_gpgme_extract_keys.
Thank you for the patch!
In addition, this patch:
* removes spurious (debug?) output when the extract keys is finished.
* adds a gpgme_data_release() call to free the keydata.
diffs (53 lines):
diff -r 9a75aa4bd69e -r 5530e9fb17d9 crypt-gpgme.c
--- a/crypt-gpgme.c Tue Aug 12 14:33:17 2014 -0700
+++ b/crypt-gpgme.c Wed Dec 31 20:35:38 2014 -0800
@@ -2093,35 +2093,34 @@
return rv;
}
-/* TODO: looks like this won't work and we'll have to fully parse the
- * message file. GPGME makes life hard yet again. */
void pgp_gpgme_invoke_import (const char *fname)
{
gpgme_data_t keydata;
gpgme_error_t err;
FILE* in;
FILE* out;
- long outlen;
if (!(in = safe_fopen (fname, "r")))
return;
+ /* Note that the stream, "in", needs to be kept open while the keydata
+ * is used.
+ */
if ((err = gpgme_data_new_from_stream (&keydata, in)) != GPG_ERR_NO_ERROR)
{
- dprint (1, (debugfile, "error converting key file into data object\n"));
+ safe_fclose (&in);
+ mutt_error (_("error allocating data object: %s\n"), gpgme_strerror (err));
+ mutt_sleep (1);
return;
}
+
+ if (pgp_gpgme_extract_keys (keydata, &out, 0))
+ {
+ mutt_error (_("Error extracting key data!\n"));
+ mutt_sleep (1);
+ }
+ gpgme_data_release (keydata);
safe_fclose (&in);
-
- if (!pgp_gpgme_extract_keys (keydata, &out, 0))
- {
- /* display import results */
- outlen = ftell (out);
- fseek (out, 0, SEEK_SET);
- mutt_copy_bytes (out, stdout, outlen);
- safe_fclose (&out);
- }
- else
- printf (_("Error extracting key data!\n"));
+ safe_fclose (&out);
}