From 305d8668ca724982c50fe4e05315c48a20cc33e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Wed, 22 Dec 2021 12:13:23 +0100 Subject: core: Detect bad passphrase error on certificate import * src/import.c (gpgme_op_import_result): Check fpr for NULL. (parse_error): New. (import_status_handler): Handle error status line. * doc/gpgme.texi (gpgme_import_status_t): Mention that fpr can be NULL. * tests/gpg/t-import.c (check_result): Check fpr for NULL. * tests/run-threaded.c (delete_impres): Check fpr for NULL. -- When importing an encrypted certificate a wrong passphrase may be entered. In this case gpgsm emits a status line with a bad passphrase error and an "invalid object" error. To make it possible for callers to handle a wrong passphrase error more gracefully, an import status with bad passphrase error is added to the import result for each status line with bad passphrase error. GnuPG-bug-id: 5713 --- tests/gpg/t-import.c | 9 +++++---- tests/run-threaded.c | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/gpg/t-import.c b/tests/gpg/t-import.c index 159e5652..1f7fdbc3 100644 --- a/tests/gpg/t-import.c +++ b/tests/gpg/t-import.c @@ -149,16 +149,17 @@ check_result (gpgme_import_result_t result, const char *fpr, int secret) exit (1); } } - if (strcmp (fpr, result->imports->fpr)) + if (!result->imports->fpr || strcmp (fpr, result->imports->fpr)) { fprintf (stderr, "Unexpected fingerprint %s\n", - result->imports->fpr); + result->imports->fpr ? result->imports->fpr : "null"); exit (1); } - if (result->imports->next && strcmp (fpr, result->imports->next->fpr)) + if (result->imports->next + && (!result->imports->next->fpr || strcmp (fpr, result->imports->next->fpr))) { fprintf (stderr, "Unexpected fingerprint on second status %s\n", - result->imports->next->fpr); + result->imports->next->fpr ? result->imports->next->fpr : "null"); exit (1); } if (result->imports->result != 0) diff --git a/tests/run-threaded.c b/tests/run-threaded.c index c0e033bb..634b6811 100644 --- a/tests/run-threaded.c +++ b/tests/run-threaded.c @@ -517,7 +517,8 @@ delete_impres (gpgme_import_result_t r, gpgme_protocol_t proto) for (st=r->imports; st; st = st->next) { - delete_fpr (st->fpr, proto); + if (st->fpr) + delete_fpr (st->fpr, proto); } } -- cgit v1.2.3