Add extra IPv6 address validation, fix crash when saving IPv6 settings

main
Aaron Rainbolt 1 year ago
parent 04c53a4e03
commit d69935679c

@ -22,6 +22,11 @@ Ipv6SettingsTab::~Ipv6SettingsTab()
QVariantMap Ipv6SettingsTab::readSettings() QVariantMap Ipv6SettingsTab::readSettings()
{ {
// If the user has invalid data in here, just return the original settings data
if (!checkValidity()) {
return origSettings;
}
QVariantMap output; QVariantMap output;
switch (ui->methodComboBox->currentIndex()) { switch (ui->methodComboBox->currentIndex()) {
case 0: // Automatic case 0: // Automatic
@ -79,6 +84,7 @@ QVariantMap Ipv6SettingsTab::readSettings()
void Ipv6SettingsTab::loadSettings(QVariantMap settings) void Ipv6SettingsTab::loadSettings(QVariantMap settings)
{ {
origSettings = settings; // We may need to restore these if something about the settings the user puts in is invalid.
if (settings["ipv6Method"].isValid()) { if (settings["ipv6Method"].isValid()) {
switch (settings["ipv6Method"].toInt()) { switch (settings["ipv6Method"].toInt()) {
case ConnectionSettingsEngine::Ipv6Automatic: case ConnectionSettingsEngine::Ipv6Automatic:
@ -179,3 +185,35 @@ void Ipv6SettingsTab::onManualIpv6ConfigurationRemoveButtonClicked()
{ {
ui->manualIpv6ConfigurationTable->removeRow(ui->manualIpv6ConfigurationTable->currentRow()); ui->manualIpv6ConfigurationTable->removeRow(ui->manualIpv6ConfigurationTable->currentRow());
} }
bool Ipv6SettingsTab::checkValidity()
{
// almost copied verbatim from plasma-nm
if (ui->methodComboBox->currentIndex() == 4) { // manual
if (!ui->manualIpv6ConfigurationTable->rowCount()) {
return false;
}
for (int i = 0, rowCount = ui->manualIpv6ConfigurationTable->rowCount(); i < rowCount; i++) {
QHostAddress ip = QHostAddress(ui->manualIpv6ConfigurationTable->item(i, 0)->text());
const int prefix = ui->manualIpv6ConfigurationTable->item(i, 1)->text().toInt();
QHostAddress gateway = QHostAddress(ui->manualIpv6ConfigurationTable->item(i, 2)->text());
if (ip.isNull() || !(prefix >= 1 && prefix <= 128) || (gateway.isNull() && !ui->manualIpv6ConfigurationTable->item(i, 2)->text().isEmpty())) {
return false;
}
}
}
if (!ui->dnsServersLineEdit->text().isEmpty() && (ui->methodComboBox->currentIndex() == 0 || ui->methodComboBox->currentIndex() == 1 || ui->methodComboBox->currentIndex() == 4)) { // Automatic, AutomaticIPOnly, or Manual
const QStringList tmp = ui->dnsServersLineEdit->text().split(QLatin1Char(','));
for (const QString &str : tmp) {
QHostAddress addr(str);
if (addr.isNull()) {
return false;
}
}
}
return true;
}

@ -30,6 +30,9 @@ private slots:
private: private:
Ui::Ipv6SettingsTab *ui; Ui::Ipv6SettingsTab *ui;
QVariantMap origSettings;
bool checkValidity();
}; };
#endif // IPV6SETTINGSTAB_H #endif // IPV6SETTINGSTAB_H

@ -4,6 +4,7 @@
#include <QLocale> #include <QLocale>
#include <QTranslator> #include <QTranslator>
#include <QDebug> #include <QDebug>
#include <QDBusMetaType>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -18,6 +19,9 @@ int main(int argc, char *argv[])
break; break;
} }
} }
qDBusRegisterMetaType<IpV6DBusAddress>();
qDBusRegisterMetaType<IpV6DBusAddressList>();
NetworkSelector w; NetworkSelector w;
w.show(); w.show();
return a.exec(); return a.exec();

Loading…
Cancel
Save