Skip to content

Commit 2cf3be6

Browse files
committed
Merge bitcoin#508: [Qt] Fix crash when inputting wrong port for network proxy
f0cf0e8 [Trivial] Removing useless spaces (warrows) 1f2abb4 [Qt] Additional proxy checks in options-dialog (Mrs-X) 64f759e Fix crash when inputting wrong port for network proxy (warrows) Tree-SHA512: 104775603185135cac13a7c0bff266f37f119e34c6365cba542b242971a3c1fdf8a7b386915f1be6bfdbe25c1957a389f094f4742c248935c4970ba47dadf283
2 parents 4c01ba6 + f0cf0e8 commit 2cf3be6

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

src/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,12 +1171,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
11711171
if (proxyArg != "" && proxyArg != "0") {
11721172
CService proxyAddr;
11731173
if (!Lookup(proxyArg.c_str(), proxyAddr, 9050, fNameLookup)) {
1174-
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
1174+
return InitError(strprintf(_("Lookup(): Invalid -proxy address or hostname: '%s'"), proxyArg));
11751175
}
11761176

11771177
proxyType addrProxy = proxyType(proxyAddr, proxyRandomize);
11781178
if (!addrProxy.IsValid())
1179-
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
1179+
return InitError(strprintf(_("isValid(): Invalid -proxy address or hostname: '%s'"), proxyArg));
11801180

11811181
SetProxy(NET_IPV4, addrProxy);
11821182
SetProxy(NET_IPV6, addrProxy);

src/qt/optionsdialog.cpp

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet) : QDialog(paren
5959
connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyPort, SLOT(setEnabled(bool)));
6060

6161
ui->proxyIp->installEventFilter(this);
62+
ui->proxyPort->installEventFilter(this);
6263

6364
/* Window elements init */
6465
#ifdef Q_OS_MAC
@@ -142,7 +143,7 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet) : QDialog(paren
142143
mapper->setOrientation(Qt::Vertical);
143144

144145
/* setup/change UI elements when proxy IP is invalid/valid */
145-
connect(this, SIGNAL(proxyIpChecks(QValidatedLineEdit*, int)), this, SLOT(doProxyIpChecks(QValidatedLineEdit*, int)));
146+
connect(this, SIGNAL(proxyIpChecks(QValidatedLineEdit*, QLineEdit*)), this, SLOT(doProxyIpChecks(QValidatedLineEdit*, QLineEdit*)));
146147
}
147148

148149
OptionsDialog::~OptionsDialog()
@@ -299,30 +300,44 @@ void OptionsDialog::clearStatusLabel()
299300
ui->statusLabel->clear();
300301
}
301302

302-
void OptionsDialog::doProxyIpChecks(QValidatedLineEdit* pUiProxyIp, int nProxyPort)
303+
void OptionsDialog::doProxyIpChecks(QValidatedLineEdit* pUiProxyIp, QLineEdit* pUiProxyPort)
303304
{
304-
Q_UNUSED(nProxyPort);
305-
306305
const std::string strAddrProxy = pUiProxyIp->text().toStdString();
307306
CService addrProxy;
308307

309-
/* Check for a valid IPv4 / IPv6 address */
308+
// Check for a valid IPv4 / IPv6 address
310309
if (!(fProxyIpValid = LookupNumeric(strAddrProxy.c_str(), addrProxy))) {
311310
disableOkButton();
312311
pUiProxyIp->setValid(false);
313312
ui->statusLabel->setStyleSheet("QLabel { color: red; }");
314313
ui->statusLabel->setText(tr("The supplied proxy address is invalid."));
315-
} else {
316-
enableOkButton();
317-
ui->statusLabel->clear();
314+
return;
315+
}
316+
// Check proxy port
317+
if (!pUiProxyPort->hasAcceptableInput()){
318+
disableOkButton();
319+
ui->statusLabel->setStyleSheet("QLabel { color: red; }");
320+
ui->statusLabel->setText(tr("The supplied proxy port is invalid."));
321+
return;
318322
}
323+
324+
proxyType checkProxy = proxyType(addrProxy);
325+
if (!checkProxy.IsValid()) {
326+
disableOkButton();
327+
ui->statusLabel->setStyleSheet("QLabel { color: red; }");
328+
ui->statusLabel->setText(tr("The supplied proxy settings are invalid."));
329+
return;
330+
}
331+
332+
enableOkButton();
333+
ui->statusLabel->clear();
319334
}
320335

321336
bool OptionsDialog::eventFilter(QObject* object, QEvent* event)
322337
{
323338
if (event->type() == QEvent::FocusOut) {
324-
if (object == ui->proxyIp) {
325-
emit proxyIpChecks(ui->proxyIp, ui->proxyPort->text().toInt());
339+
if (object == ui->proxyIp || object == ui->proxyPort) {
340+
emit proxyIpChecks(ui->proxyIp, ui->proxyPort);
326341
}
327342
}
328343
return QDialog::eventFilter(object, event);

src/qt/optionsdialog.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
class OptionsModel;
1111
class QValidatedLineEdit;
12+
class QLineEdit;
1213

1314
QT_BEGIN_NAMESPACE
1415
class QDataWidgetMapper;
@@ -47,10 +48,10 @@ private slots:
4748

4849
void showRestartWarning(bool fPersistent = false);
4950
void clearStatusLabel();
50-
void doProxyIpChecks(QValidatedLineEdit* pUiProxyIp, int nProxyPort);
51+
void doProxyIpChecks(QValidatedLineEdit* pUiProxyIp, QLineEdit* pUiProxyPort);
5152

5253
signals:
53-
void proxyIpChecks(QValidatedLineEdit* pUiProxyIp, int nProxyPort);
54+
void proxyIpChecks(QValidatedLineEdit* pUiProxyIp, QLineEdit* pUiProxyPort);
5455

5556
private:
5657
Ui::OptionsDialog* ui;

0 commit comments

Comments
 (0)