From: Kevin McCarthy Date: Thu, 1 Jan 2015 04:35:38 +0000 (-0800) Subject: Fix segfault of extract-keys (^K) under gpgme. (closes #3698) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d740d5b9eae56f656953019a6e9f83b0e82b3a84;p=neomutt 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. --- diff --git a/crypt-gpgme.c b/crypt-gpgme.c index 8cbe7ff40..cc22c9435 100644 --- a/crypt-gpgme.c +++ b/crypt-gpgme.c @@ -2093,35 +2093,34 @@ int pgp_gpgme_check_traditional (FILE *fp, BODY *b, int tagged_only) 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; } - safe_fclose (&in); - if (!pgp_gpgme_extract_keys (keydata, &out, 0)) + 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); + mutt_error (_("Error extracting key data!\n")); + mutt_sleep (1); } - else - printf (_("Error extracting key data!\n")); + gpgme_data_release (keydata); + safe_fclose (&in); + safe_fclose (&out); }