From 7579c40124c9b287bb67e974bda46e879e1a1ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Wed, 28 Aug 2024 16:32:18 +0200 Subject: cpp: Go with default answer on unknown question by key edit interface * lang/cpp/src/editinteractor.cpp (edit_interactor_callback_impl): Send empty string to edit interface if General Error occurred. -- A General Error is usually returned by the nextState function of the concrete EditInteractor subclasses if gpg asks an unexpected question which isn't handled by the edit interactor's state machine. In this case, it's usually safe to go with the default answer. This makes the edit interactors much more robust. GnuPG-bug-id: 7274 --- lang/cpp/src/editinteractor.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lang/cpp/src/editinteractor.cpp') diff --git a/lang/cpp/src/editinteractor.cpp b/lang/cpp/src/editinteractor.cpp index 84ddf398..5f9236cb 100644 --- a/lang/cpp/src/editinteractor.cpp +++ b/lang/cpp/src/editinteractor.cpp @@ -167,6 +167,20 @@ public: } error: + if (err.code() == GPG_ERR_GENERAL) { + // gpg may have asked an unknown question; try to use the default answer + if (ei->debug) { + std::fprintf(ei->debug, "EditInteractor: action result \"%s\" (go with the default answer)\n", ""); + } + if (writeAll(fd, "\n", 1) != 1) { + err = Error::fromSystemError(); + if (ei->debug) { + std::fprintf(ei->debug, "EditInteractor: Could not write to fd %d (%s)\n", fd, err.asStdString().c_str()); + } + } else { + err = Error(); + } + } if (err || err.isCanceled()) { ei->error = err; ei->state = EditInteractor::ErrorState; -- cgit v1.2.3