summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRolf Eike Beer <kde@opensource.sf-tec.de>2012-03-27 08:01:34 (GMT)
committerRolf Eike Beer <kde@opensource.sf-tec.de>2012-03-27 12:12:19 (GMT)
commit2de8490d527d47d4fa4d8e643aefba5e842d2826 (patch)
tree84d0e4c5111c8d2fc521c9aee2197d3c3b875bb5
parent42f8b1b51b09cb4b64fadf7e6cdd5ce359b0fa74 (diff)
track object deletion while GnuPG transactions are running
The process may quit and cause the object to get deleted while we are e.g. waiting for a password input. Check if the object is still alive before reading the next input. If we detect the process to go away also close the password dialog as it can't do anything useful then anymore. BUG:296634 FIXED-IN:4.8.2
-rw-r--r--kgpginterface.cpp4
-rw-r--r--transactions/kgpgtransaction.cpp27
2 files changed, 24 insertions, 7 deletions
diff --git a/kgpginterface.cpp b/kgpginterface.cpp
index fae5f93..c215c73 100644
--- a/kgpginterface.cpp
+++ b/kgpginterface.cpp
@@ -24,6 +24,7 @@
#include <kio/netaccess.h>
#include <KMessageBox>
#include <KPasswordDialog>
+#include <KPushButton>
#include <knewpassworddialog.h>
#include <KLocale>
#include <KProcess>
@@ -423,8 +424,10 @@ int KgpgInterface::sendPassphrase(const QString &text, KProcess *process, const
QPointer<KProcess> gpgprocess = process;
QByteArray passphrase;
int code;
+
if (isnew) {
QPointer<KNewPasswordDialog> dlg = new KNewPasswordDialog(widget);
+ QObject::connect(process, SIGNAL(processExited()), dlg->button(KDialog::Cancel), SLOT(click()));
dlg->setPrompt(text);
dlg->setAllowEmptyPasswords(false);
code = dlg->exec();
@@ -433,6 +436,7 @@ int KgpgInterface::sendPassphrase(const QString &text, KProcess *process, const
delete dlg;
} else {
QPointer<KPasswordDialog> dlg = new KPasswordDialog(widget);
+ QObject::connect(process, SIGNAL(processExited()), dlg->button(KDialog::Cancel), SLOT(click()));
dlg->setPrompt(text);
code = dlg->exec();
if (!dlg.isNull())
diff --git a/transactions/kgpgtransaction.cpp b/transactions/kgpgtransaction.cpp
index d3590e7..155d90c 100644
--- a/transactions/kgpgtransaction.cpp
+++ b/transactions/kgpgtransaction.cpp
@@ -13,10 +13,6 @@
#include "kgpgtransaction.h"
-#include <QByteArray>
-#include <QStringList>
-#include <QWidget>
-
#include <KDebug>
#include <knewpassworddialog.h>
#include <KLocale>
@@ -24,6 +20,12 @@
#include "gpgproc.h"
#include "kgpginterface.h"
+#include <KPushButton>
+#include <QByteArray>
+#include <QStringList>
+#include <QWeakPointer>
+#include <QWidget>
+
class KGpgTransactionPrivate: QObject {
public:
KGpgTransactionPrivate(KGpgTransaction *parent, bool allowChaining);
@@ -112,8 +114,10 @@ void
KGpgTransactionPrivate::slotReadReady()
{
QString line;
+ QWeakPointer<GPGProc> process(m_process);
+ QWeakPointer<KGpgTransaction> par(m_parent);
- while (m_process->readln(line, true) >= 0) {
+ while (!process.isNull() && (m_process->readln(line, true) >= 0)) {
if (m_quitTries)
m_quitLines << line;
#ifdef KGPG_DEBUG_TRANSACTIONS
@@ -125,8 +129,16 @@ KGpgTransactionPrivate::slotReadReady()
} else if (line.startsWith(QLatin1String("[GNUPG:] BAD_PASSPHRASE "))) {
m_success = KGpgTransaction::TS_BAD_PASSPHRASE;
} else if (line.startsWith(QLatin1String("[GNUPG:] GET_HIDDEN passphrase.enter"))) {
- m_passphraseAction = m_parent->passphraseRequested();
- switch (m_passphraseAction) {
+ // Do not directly assign to the member here, the object could
+ // get deleted while waiting for the result
+ const KGpgTransaction::ts_passphrase_actions action = m_parent->passphraseRequested();
+
+ if (par.isNull())
+ return;
+
+ m_passphraseAction = action;
+
+ switch (action) {
case KGpgTransaction::PA_USER_ABORTED:
m_parent->setSuccess(KGpgTransaction::TS_USER_ABORTED);
// sending "quit" here is useless as it would be interpreted as the passphrase
@@ -286,6 +298,7 @@ KGpgTransaction::askNewPassphrase(const QString& text)
d->m_passwordDialog->setAllowEmptyPasswords(false);
connect(d->m_passwordDialog, SIGNAL(newPassword(QString)), SLOT(slotPasswordEntered(QString)));
connect(d->m_passwordDialog, SIGNAL(rejected()), SLOT(slotPasswordAborted()));
+ connect(d->m_process, SIGNAL(processExited()), d->m_passwordDialog->button(KDialog::Cancel), SLOT(clicked()));
d->m_passwordDialog->show();
}