Merge #8073: qt: askpassphrasedialog: Clear pass fields on accept

02ce2a3 qt: askpassphrasedialog: Clear pass fields on accept (Pavel Vasin)
This commit is contained in:
Wladimir J. van der Laan 2016-05-26 07:22:44 +02:00
commit eb2f6f72db
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
2 changed files with 18 additions and 4 deletions

View File

@ -77,10 +77,7 @@ AskPassphraseDialog::AskPassphraseDialog(Mode mode, QWidget *parent) :
AskPassphraseDialog::~AskPassphraseDialog() AskPassphraseDialog::~AskPassphraseDialog()
{ {
// Attempt to overwrite text so that they do not linger around in memory secureClearPassFields();
ui->passEdit1->setText(QString(" ").repeated(ui->passEdit1->text().size()));
ui->passEdit2->setText(QString(" ").repeated(ui->passEdit2->text().size()));
ui->passEdit3->setText(QString(" ").repeated(ui->passEdit3->text().size()));
delete ui; delete ui;
} }
@ -103,6 +100,8 @@ void AskPassphraseDialog::accept()
newpass1.assign(ui->passEdit2->text().toStdString().c_str()); newpass1.assign(ui->passEdit2->text().toStdString().c_str());
newpass2.assign(ui->passEdit3->text().toStdString().c_str()); newpass2.assign(ui->passEdit3->text().toStdString().c_str());
secureClearPassFields();
switch(mode) switch(mode)
{ {
case Encrypt: { case Encrypt: {
@ -260,3 +259,17 @@ bool AskPassphraseDialog::eventFilter(QObject *object, QEvent *event)
} }
return QDialog::eventFilter(object, event); return QDialog::eventFilter(object, event);
} }
static void SecureClearQLineEdit(QLineEdit* edit)
{
// Attempt to overwrite text so that they do not linger around in memory
edit->setText(QString(" ").repeated(edit->text().size()));
edit->clear();
}
void AskPassphraseDialog::secureClearPassFields()
{
SecureClearQLineEdit(ui->passEdit1);
SecureClearQLineEdit(ui->passEdit2);
SecureClearQLineEdit(ui->passEdit3);
}

View File

@ -42,6 +42,7 @@ private:
private Q_SLOTS: private Q_SLOTS:
void textChanged(); void textChanged();
void secureClearPassFields();
protected: protected:
bool event(QEvent *event); bool event(QEvent *event);