From 77e982579ccadb20ee865337ada9579ac41164e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Tue, 14 Nov 2023 13:48:48 +0100 Subject: [PATCH] core: Preserve more specific existing failure code * src/decrypt.c (_gpgme_decrypt_status_handler): Ignore received failure code if we already have a specific failure code. * src/encrypt.c (_gpgme_encrypt_status_handler): Ditto. * src/export.c (export_status_handler): Ditto. * src/genkey.c (genkey_status_handler): Ditto. * src/keylist.c (keylist_status_handler): Ditto. * src/keysign.c (keysign_status_handler): Ditto. * src/passwd.c (passwd_status_handler): Ditto. * src/revsig.c (revsig_status_handler): Ditto. * src/setexpire.c (setexpire_status_handler): Ditto. * src/sign.c (_gpgme_sign_status_handler): Ditto. * src/tofupolicy.c (tofu_policy_status_handler): Ditto. * src/verify.c (_gpgme_verify_status_handler): Ditto. -- Usually, a process emits at most one failure code. But some operations like the creation of an encrypted archive involve multiple chained processes, so that multiple failure codes can be received. We want to keep the first specific failure code we received. Further failure codes are only parsed if we received just an unspecific "general error" so far. GnuPG-bug-id: 6575 --- src/decrypt.c | 4 +++- src/encrypt.c | 4 +++- src/export.c | 4 +++- src/genkey.c | 4 +++- src/keylist.c | 4 +++- src/keysign.c | 4 +++- src/passwd.c | 4 +++- src/revsig.c | 4 +++- src/setexpire.c | 4 +++- src/sign.c | 4 +++- src/tofupolicy.c | 4 +++- src/verify.c | 4 +++- 12 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/decrypt.c b/src/decrypt.c index 896a873f..e5d2f7c7 100644 --- a/src/decrypt.c +++ b/src/decrypt.c @@ -377,7 +377,9 @@ _gpgme_decrypt_status_handler (void *priv, gpgme_status_code_t code, switch (code) { case GPGME_STATUS_FAILURE: - opd->failure_code = _gpgme_parse_failure (args); + if (!opd->failure_code + || gpg_err_code (opd->failure_code) == GPG_ERR_GENERAL) + opd->failure_code = _gpgme_parse_failure (args); break; case GPGME_STATUS_EOF: diff --git a/src/encrypt.c b/src/encrypt.c index c5f668ea..241748cd 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -126,7 +126,9 @@ _gpgme_encrypt_status_handler (void *priv, gpgme_status_code_t code, switch (code) { case GPGME_STATUS_FAILURE: - opd->failure_code = _gpgme_parse_failure (args); + if (!opd->failure_code + || gpg_err_code (opd->failure_code) == GPG_ERR_GENERAL) + opd->failure_code = _gpgme_parse_failure (args); break; case GPGME_STATUS_EOF: diff --git a/src/export.c b/src/export.c index d5137866..090db8b5 100644 --- a/src/export.c +++ b/src/export.c @@ -116,7 +116,9 @@ export_status_handler (void *priv, gpgme_status_code_t code, char *args) break; case GPGME_STATUS_FAILURE: - opd->failure_code = _gpgme_parse_failure (args); + if (!opd->failure_code + || gpg_err_code (opd->failure_code) == GPG_ERR_GENERAL) + opd->failure_code = _gpgme_parse_failure (args); break; default: diff --git a/src/genkey.c b/src/genkey.c index 77576b18..89e1d985 100644 --- a/src/genkey.c +++ b/src/genkey.c @@ -172,7 +172,9 @@ genkey_status_handler (void *priv, gpgme_status_code_t code, char *args) break; case GPGME_STATUS_FAILURE: - opd->failure_code = _gpgme_parse_failure (args); + if (!opd->failure_code + || gpg_err_code (opd->failure_code) == GPG_ERR_GENERAL) + opd->failure_code = _gpgme_parse_failure (args); break; case GPGME_STATUS_EOF: diff --git a/src/keylist.c b/src/keylist.c index 2f6ae824..1d8c8184 100644 --- a/src/keylist.c +++ b/src/keylist.c @@ -150,7 +150,9 @@ keylist_status_handler (void *priv, gpgme_status_code_t code, char *args) break; case GPGME_STATUS_FAILURE: - opd->failure_code = _gpgme_parse_failure (args); + if (!opd->failure_code + || gpg_err_code (opd->failure_code) == GPG_ERR_GENERAL) + opd->failure_code = _gpgme_parse_failure (args); if (opd->failure_code && !strcmp (args, "option-parser") && gpg_err_code (opd->failure_code) == GPG_ERR_GENERAL) err = gpg_error (GPG_ERR_INV_ENGINE); diff --git a/src/keysign.c b/src/keysign.c index 44ab5ff2..1a3c8a54 100644 --- a/src/keysign.c +++ b/src/keysign.c @@ -113,7 +113,9 @@ keysign_status_handler (void *priv, gpgme_status_code_t code, char *args) break; case GPGME_STATUS_FAILURE: - opd->failure_code = _gpgme_parse_failure (args); + if (!opd->failure_code + || gpg_err_code (opd->failure_code) == GPG_ERR_GENERAL) + opd->failure_code = _gpgme_parse_failure (args); break; case GPGME_STATUS_EOF: diff --git a/src/passwd.c b/src/passwd.c index 0ba8c08d..b29b29c7 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -97,7 +97,9 @@ passwd_status_handler (void *priv, gpgme_status_code_t code, char *args) break; case GPGME_STATUS_FAILURE: - opd->failure_code = _gpgme_parse_failure (args); + if (!opd->failure_code + || gpg_err_code (opd->failure_code) == GPG_ERR_GENERAL) + opd->failure_code = _gpgme_parse_failure (args); break; case GPGME_STATUS_EOF: diff --git a/src/revsig.c b/src/revsig.c index 8c61f730..1d0276a8 100644 --- a/src/revsig.c +++ b/src/revsig.c @@ -101,7 +101,9 @@ revsig_status_handler (void *priv, gpgme_status_code_t code, char *args) break; case GPGME_STATUS_FAILURE: - opd->failure_code = _gpgme_parse_failure (args); + if (!opd->failure_code + || gpg_err_code (opd->failure_code) == GPG_ERR_GENERAL) + opd->failure_code = _gpgme_parse_failure (args); break; case GPGME_STATUS_EOF: diff --git a/src/setexpire.c b/src/setexpire.c index 5161499a..ed09f5f9 100644 --- a/src/setexpire.c +++ b/src/setexpire.c @@ -96,7 +96,9 @@ setexpire_status_handler (void *priv, gpgme_status_code_t code, char *args) break; case GPGME_STATUS_FAILURE: - opd->failure_code = _gpgme_parse_failure (args); + if (!opd->failure_code + || gpg_err_code (opd->failure_code) == GPG_ERR_GENERAL) + opd->failure_code = _gpgme_parse_failure (args); break; case GPGME_STATUS_EOF: diff --git a/src/sign.c b/src/sign.c index 51f581ca..1563c1dd 100644 --- a/src/sign.c +++ b/src/sign.c @@ -363,7 +363,9 @@ _gpgme_sign_status_handler (void *priv, gpgme_status_code_t code, char *args) break; case GPGME_STATUS_FAILURE: - opd->failure_code = _gpgme_parse_failure (args); + if (!opd->failure_code + || gpg_err_code (opd->failure_code) == GPG_ERR_GENERAL) + opd->failure_code = _gpgme_parse_failure (args); break; case GPGME_STATUS_EOF: diff --git a/src/tofupolicy.c b/src/tofupolicy.c index 79593186..24aaf285 100644 --- a/src/tofupolicy.c +++ b/src/tofupolicy.c @@ -97,7 +97,9 @@ tofu_policy_status_handler (void *priv, gpgme_status_code_t code, char *args) break; case GPGME_STATUS_FAILURE: - opd->failure_code = _gpgme_parse_failure (args); + if (!opd->failure_code + || gpg_err_code (opd->failure_code) == GPG_ERR_GENERAL) + opd->failure_code = _gpgme_parse_failure (args); break; case GPGME_STATUS_EOF: diff --git a/src/verify.c b/src/verify.c index 3ae94c65..8d87cad3 100644 --- a/src/verify.c +++ b/src/verify.c @@ -1055,7 +1055,9 @@ _gpgme_verify_status_handler (void *priv, gpgme_status_code_t code, char *args) return parse_error (sig, args, !!sig ); case GPGME_STATUS_FAILURE: - opd->failure_code = _gpgme_parse_failure (args); + if (!opd->failure_code + || gpg_err_code (opd->failure_code) == GPG_ERR_GENERAL) + opd->failure_code = _gpgme_parse_failure (args); break; case GPGME_STATUS_EOF: