From d184bd8c8271dd92c9e7f176fd022be9f7f79f76 Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Wed, 6 Dec 2017 02:02:54 -0500 Subject: [PATCH] Perform ip string validation inside setWebUiAuthSubnetWhitelist --- src/base/preferences.cpp | 12 ++++++++++-- src/base/preferences.h | 2 +- src/gui/ipsubnetwhitelistoptionsdialog.cpp | 8 +++----- src/webui/prefjson.cpp | 12 ++---------- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index 88766b365..10320c313 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -487,10 +487,18 @@ QList Preferences::getWebUiAuthSubnetWhitelist() const return subnets; } -void Preferences::setWebUiAuthSubnetWhitelist(const QList &subnets) +void Preferences::setWebUiAuthSubnetWhitelist(const QStringList &subnets) { + QList filteredSubnets; + foreach (QString subnetString, subnets) { + bool ok = false; + const Utils::Net::Subnet subnet = Utils::Net::parseSubnet(subnetString.trimmed(), &ok); + if (ok) + filteredSubnets.append(subnet); + } + QStringList subnetsStringList; - for (const Utils::Net::Subnet &subnet : subnets) + for (const Utils::Net::Subnet &subnet : filteredSubnets) subnetsStringList.append(Utils::Net::subnetToString(subnet)); setValue("Preferences/WebUI/AuthSubnetWhitelist", subnetsStringList); diff --git a/src/base/preferences.h b/src/base/preferences.h index 3e5087fa4..b81419e6a 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -191,7 +191,7 @@ public: bool isWebUiAuthSubnetWhitelistEnabled() const; void setWebUiAuthSubnetWhitelistEnabled(bool enabled); QList getWebUiAuthSubnetWhitelist() const; - void setWebUiAuthSubnetWhitelist(const QList &subnets); + void setWebUiAuthSubnetWhitelist(const QStringList &subnets); QString getWebUiUsername() const; void setWebUiUsername(const QString &username); QString getWebUiPassword() const; diff --git a/src/gui/ipsubnetwhitelistoptionsdialog.cpp b/src/gui/ipsubnetwhitelistoptionsdialog.cpp index 0cbf9c9c4..ebc69fa13 100644 --- a/src/gui/ipsubnetwhitelistoptionsdialog.cpp +++ b/src/gui/ipsubnetwhitelistoptionsdialog.cpp @@ -68,12 +68,10 @@ void IPSubnetWhitelistOptionsDialog::on_buttonBox_accepted() { if (m_modified) { // save to session - QList subnets; + QStringList subnets; // Operate on the m_sortFilter to grab the strings in sorted order - for (int i = 0; i < m_sortFilter->rowCount(); ++i) { - const QString subnet = m_sortFilter->index(i, 0).data().toString(); - subnets.append(QHostAddress::parseSubnet(subnet)); - } + for (int i = 0; i < m_sortFilter->rowCount(); ++i) + subnets.append(m_sortFilter->index(i, 0).data().toString()); Preferences::instance()->setWebUiAuthSubnetWhitelist(subnets); QDialog::accept(); } diff --git a/src/webui/prefjson.cpp b/src/webui/prefjson.cpp index 2fb41b849..e1be04572 100644 --- a/src/webui/prefjson.cpp +++ b/src/webui/prefjson.cpp @@ -437,16 +437,8 @@ void prefjson::setPreferences(const QString& json) if (m.contains("bypass_auth_subnet_whitelist_enabled")) pref->setWebUiAuthSubnetWhitelistEnabled(m["bypass_auth_subnet_whitelist_enabled"].toBool()); if (m.contains("bypass_auth_subnet_whitelist")) { - QList subnets; - // recognize new line and comma as delimiters - foreach (QString subnetString, m["bypass_auth_subnet_whitelist"].toString().split(QRegularExpression("\n|,"), QString::SkipEmptyParts)) { - bool ok = false; - const Utils::Net::Subnet subnet = Utils::Net::parseSubnet(subnetString.trimmed(), &ok); - if (ok) - subnets.append(subnet); - } - - pref->setWebUiAuthSubnetWhitelist(subnets); + // recognize new lines and commas as delimiters + pref->setWebUiAuthSubnetWhitelist(m["bypass_auth_subnet_whitelist"].toString().split(QRegularExpression("\n|,"), QString::SkipEmptyParts)); } // Update my dynamic domain name if (m.contains("dyndns_enabled"))