From 89c5f1bee68c58091ac978eca7ff220f8f4ab0bf Mon Sep 17 00:00:00 2001 From: Lauris Kaplinski Date: Mon, 12 Aug 2024 17:20:43 +0300 Subject: [PATCH 1/5] Send meaningful json and exit directly if invalid argument is encountered in stdin mode --- src/controller/controller.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/controller/controller.cpp b/src/controller/controller.cpp index 4bbbd9f7..8dc74273 100644 --- a/src/controller/controller.cpp +++ b/src/controller/controller.cpp @@ -108,6 +108,9 @@ void Controller::run() // Command parameter is only used if exception will be raised during json creation writeResponseToStdOut(isInStdinMode, {{QStringLiteral("invalid-argument"), exc.what()}}, "invalid-argument"); + // Exit directly here + disposeUI(); + exit(); } onCriticalFailure(exc.what()); } catch (const std::exception& error) { From 1f3cdb048223e47156128a1fd5989ae8189267e6 Mon Sep 17 00:00:00 2001 From: Lauris Kaplinski Date: Wed, 21 Aug 2024 12:45:42 +0300 Subject: [PATCH 2/5] Use QString::fill instead of eraseData to force copy-on-write --- src/ui/webeiddialog.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ui/webeiddialog.cpp b/src/ui/webeiddialog.cpp index 261319b5..9da3026e 100644 --- a/src/ui/webeiddialog.cpp +++ b/src/ui/webeiddialog.cpp @@ -292,8 +292,9 @@ QString WebEidDialog::getPin() // QString uses QAtomicPointer internally and is thread-safe. // There should be only single reference and this is transferred to the caller for safety QString ret = pin; - eraseData(pin); - pin.clear(); + // Cannot use eraseData because we have to force Qt copy-on-write + pin.fill('\0'); + pin.clear(); return ret; } From 6e9b434831d8443818715d6decda297e77fe16c2 Mon Sep 17 00:00:00 2001 From: lauris71 Date: Mon, 19 Aug 2024 14:44:51 +0300 Subject: [PATCH 3/5] Update src/controller/controller.cpp Co-authored-by: Raul Metsma --- src/controller/controller.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controller/controller.cpp b/src/controller/controller.cpp index 8dc74273..3cd280b7 100644 --- a/src/controller/controller.cpp +++ b/src/controller/controller.cpp @@ -111,6 +111,7 @@ void Controller::run() // Exit directly here disposeUI(); exit(); + return; } onCriticalFailure(exc.what()); } catch (const std::exception& error) { From f67d7584b9af4fa4fd462c16bbc8110c670698b0 Mon Sep 17 00:00:00 2001 From: Mart Somermaa Date: Fri, 30 Aug 2024 19:54:12 +0300 Subject: [PATCH 4/5] Revert unnecessary std::invalid_argument handling WE2-479 Signed-off-by: Mart Somermaa --- src/controller/controller.cpp | 13 ------------- src/ui/webeiddialog.cpp | 6 +++--- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/controller/controller.cpp b/src/controller/controller.cpp index 3cd280b7..5894e103 100644 --- a/src/controller/controller.cpp +++ b/src/controller/controller.cpp @@ -101,19 +101,6 @@ void Controller::run() startCommandExecution(); - } catch (const std::invalid_argument& exc) { - if (isInStdinMode) { - // Pass invalid argument message to the caller just in case it may be interested - // The result will be {"invalid-argument" : message} - // Command parameter is only used if exception will be raised during json creation - writeResponseToStdOut(isInStdinMode, {{QStringLiteral("invalid-argument"), exc.what()}}, - "invalid-argument"); - // Exit directly here - disposeUI(); - exit(); - return; - } - onCriticalFailure(exc.what()); } catch (const std::exception& error) { onCriticalFailure(error.what()); } diff --git a/src/ui/webeiddialog.cpp b/src/ui/webeiddialog.cpp index 9da3026e..3c91341a 100644 --- a/src/ui/webeiddialog.cpp +++ b/src/ui/webeiddialog.cpp @@ -292,9 +292,9 @@ QString WebEidDialog::getPin() // QString uses QAtomicPointer internally and is thread-safe. // There should be only single reference and this is transferred to the caller for safety QString ret = pin; - // Cannot use eraseData because we have to force Qt copy-on-write - pin.fill('\0'); - pin.clear(); + // Cannot use eraseData because we have to force Qt copy-on-write + pin.fill('\0'); + pin.clear(); return ret; } From a5825d031521670d19c7fd4e181862a3fc7cc6ba Mon Sep 17 00:00:00 2001 From: Mart Somermaa Date: Fri, 30 Aug 2024 19:56:01 +0300 Subject: [PATCH 5/5] Remove code duplication by implementing displayPinBlockedError() via displayFatalError() WE2-479 Signed-off-by: Mart Somermaa --- src/ui/webeiddialog.cpp | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/ui/webeiddialog.cpp b/src/ui/webeiddialog.cpp index 3c91341a..76f7ab75 100644 --- a/src/ui/webeiddialog.cpp +++ b/src/ui/webeiddialog.cpp @@ -20,8 +20,6 @@ * SOFTWARE. */ -#include "utils/erasedata.hpp" - #include "webeiddialog.hpp" #include "application.hpp" #include "punycode.hpp" @@ -465,7 +463,6 @@ void WebEidDialog::onVerifyPinFailed(const VerifyPinFailed::Status status, const break; case Status::PIN_BLOCKED: displayPinBlockedError(); - resizeHeight(); return; case Status::INVALID_PIN_LENGTH: message = [] { return tr("Invalid PIN length"); }; @@ -482,7 +479,7 @@ void WebEidDialog::onVerifyPinFailed(const VerifyPinFailed::Status status, const case Status::UNKNOWN_ERROR: message = [] { return tr("Technical error"); }; displayFatalError(message); - break; + return; } ui->pinErrorLabel->setVisible(bool(message)); @@ -682,17 +679,7 @@ void WebEidDialog::setupOK(Func func, const char* text, bool enabled) void WebEidDialog::displayPinBlockedError() { - ui->pinTitleLabel->hide(); - ui->pinInput->hide(); - ui->pinTimeoutTimer->stop(); - ui->pinTimeRemaining->hide(); - ui->pinEntryTimeoutProgressBar->hide(); - setTrText(ui->pinErrorLabel, QT_TR_NOOP("PIN is locked. Unblock and try again.")); - ui->pinErrorLabel->show(); - ui->okButton->hide(); - ui->cancelButton->setEnabled(true); - ui->cancelButton->show(); - ui->helpButton->show(); + displayFatalError([] { return tr("PIN is locked. Unblock and try again."); }); } void WebEidDialog::displayFatalError(std::function message) @@ -707,6 +694,8 @@ void WebEidDialog::displayFatalError(std::function message) ui->okButton->hide(); ui->cancelButton->setEnabled(true); ui->cancelButton->show(); + ui->helpButton->show(); + resizeHeight(); } void WebEidDialog::showPinInputWarning(bool show)