diff options
author | Ingo Klöcker <[email protected]> | 2022-03-30 10:25:53 +0000 |
---|---|---|
committer | Ingo Klöcker <[email protected]> | 2022-03-31 16:39:19 +0000 |
commit | 7f089165e3ae42274e75e0e6fa1c45ca641f4023 (patch) | |
tree | 8ee2c9aa4e88a814ca3eb2d81a93c2d19e386466 /lang/qt/src/qgpgmerevokekeyjob.cpp | |
parent | qt,tests: Verify reason code and description of revocation (diff) | |
download | gpgme-7f089165e3ae42274e75e0e6fa1c45ca641f4023.tar.gz gpgme-7f089165e3ae42274e75e0e6fa1c45ca641f4023.zip |
qt: Check arguments passed to the revoke key job
* lang/qt/src/qgpgmerevokekeyjob.cpp (check_arguments): New.
(QGpgMERevokeKeyJob::start, QGpgMERevokeKeyJob::exec): Call
check_arguments.
* lang/qt/tests/t-revokekey.cpp (RevokeKeyJobTest): Add member functions
testErrorHandling_nullKey, testErrorHandling_invalidReason,
testErrorHandling_invalidDescription.
--
Check that the key is not a null key, that the reason has a valid
value, and that the description lines do not contain endline characters
and are not empty.
GnuPG-bug-id: 5904
Diffstat (limited to 'lang/qt/src/qgpgmerevokekeyjob.cpp')
-rw-r--r-- | lang/qt/src/qgpgmerevokekeyjob.cpp | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/lang/qt/src/qgpgmerevokekeyjob.cpp b/lang/qt/src/qgpgmerevokekeyjob.cpp index 08585414..8a2c224e 100644 --- a/lang/qt/src/qgpgmerevokekeyjob.cpp +++ b/lang/qt/src/qgpgmerevokekeyjob.cpp @@ -46,6 +46,8 @@ #include <gpg-error.h> +#include "qgpgme_debug.h" + using namespace QGpgME; using namespace GpgME; @@ -57,6 +59,29 @@ QGpgMERevokeKeyJob::QGpgMERevokeKeyJob(Context *context) QGpgMERevokeKeyJob::~QGpgMERevokeKeyJob() = default; + +static Error check_arguments(const Key &key, + RevocationReason reason, + const std::vector<std::string> &description) +{ + if (key.isNull()) { + qWarning(QGPGME_LOG) << "Error: Key is null key"; + return Error::fromCode(GPG_ERR_INV_ARG); + } + if (reason < RevocationReason::Unspecified || reason > RevocationReason::NoLongerUsed) { + qWarning(QGPGME_LOG) << "Error: Invalid revocation reason" << static_cast<int>(reason); + return Error::fromCode(GPG_ERR_INV_VALUE); + } + if (std::any_of(std::begin(description), std::end(description), + [](const std::string &line) { + return line.empty() || line.find('\n') != std::string::npos; + })) { + qWarning(QGPGME_LOG) << "Error: Revocation description contains empty lines or lines with endline characters"; + return Error::fromCode(GPG_ERR_INV_VALUE); + } + return {}; +} + static QGpgMERevokeKeyJob::result_type revoke_key(Context *ctx, const Key &key, RevocationReason reason, const std::vector<std::string> &description) @@ -80,17 +105,24 @@ Error QGpgMERevokeKeyJob::start(const GpgME::Key &key, GpgME::RevocationReason reason, const std::vector<std::string> &description) { - run(std::bind(&revoke_key, std::placeholders::_1, key, reason, description)); - return {}; + Error err = check_arguments(key, reason, description); + if (!err) { + run(std::bind(&revoke_key, std::placeholders::_1, key, reason, description)); + } + return err; } Error QGpgMERevokeKeyJob::exec(const GpgME::Key &key, GpgME::RevocationReason reason, const std::vector<std::string> &description) { - const result_type r = revoke_key(context(), key, reason, description); - resultHook(r); - return std::get<0>(r); + Error err = check_arguments(key, reason, description); + if (!err) { + const result_type r = revoke_key(context(), key, reason, description); + resultHook(r); + err = std::get<0>(r); + } + return err; } #include "qgpgmerevokekeyjob.moc" |