summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoanna Hulboj <joanna.hulboj@isode.com>2019-10-03 08:11:09 (GMT)
committerJoanna Hulboj <joanna.hulboj@isode.com>2019-10-03 09:09:08 (GMT)
commitdf07a5e1e654c5fe4b513b8b0e41a392e9955cdf (patch)
treee864e06a81c85bb1876c59a2f7107a443ed0cc75
parent6f5fa6a02eb7502a15afab70c91451b8142e2ac3 (diff)
downloadswift-df07a5e1e654c5fe4b513b8b0e41a392e9955cdf.zip
swift-df07a5e1e654c5fe4b513b8b0e41a392e9955cdf.tar.bz2
Treat numeric domain JID as invalid
DomainJID consisting of only numbers is not treated as valid. Test-information: Unit tests pass on Windows 10 and Ubuntu 18.04.1 LTS. Change-Id: If23ba8b8ea2a3c72d6f6e3acec4f587166c14e61
-rw-r--r--Swiften/JID/JID.cpp4
-rw-r--r--Swiften/JID/UnitTest/JIDTest.cpp5
2 files changed, 8 insertions, 1 deletions
diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp
index 5c6ea9d..a584b79 100644
--- a/Swiften/JID/JID.cpp
+++ b/Swiften/JID/JID.cpp
@@ -123,20 +123,22 @@ void JID::nameprepAndSetComponents(const std::string& node, const std::string& d
auto inner = std::string(domain.begin() + 1, domain.end() - 1);
auto hostAddress = HostAddress::fromString(inner);
if (hostAddress && hostAddress->isValid()) {
setComponents(node, domain, resource);
return;
}
}
const auto isAnyOfNonNumericAndNotDot = std::any_of(std::begin(domain), std::end(domain), [](char c) {return !::isdigit(c) && c != '.'; });
+ const auto isDomainAllNumeric = std::all_of(std::begin(domain), std::end(domain), [](char c) {return ::isdigit(c) ; });
- if (!isAnyOfNonNumericAndNotDot) {
+ //Prevent Windows validating non-dotted integers as OK if it can unpack them
+ if (!isAnyOfNonNumericAndNotDot && !isDomainAllNumeric) {
auto hostAddress = HostAddress::fromString(domain);
if (hostAddress && hostAddress->isValid()) {
setComponents(node, domain, resource);
return;
}
}
if (!isAnyOfNonNumericAndNotDot || !idnConverter->getIDNAEncoded(domain)) {
valid_ = false;
diff --git a/Swiften/JID/UnitTest/JIDTest.cpp b/Swiften/JID/UnitTest/JIDTest.cpp
index 894378d..fc7583f 100644
--- a/Swiften/JID/UnitTest/JIDTest.cpp
+++ b/Swiften/JID/UnitTest/JIDTest.cpp
@@ -18,18 +18,19 @@ class JIDTest : public CppUnit::TestFixture
CPPUNIT_TEST(testConstructorWithString_Empty);
CPPUNIT_TEST(testConstructorWithString_NoResource);
CPPUNIT_TEST(testConstructorWithString_NoNode);
CPPUNIT_TEST(testConstructorWithString_EmptyResource);
CPPUNIT_TEST(testConstructorWithString_OnlyDomain);
CPPUNIT_TEST(testConstructorWithString_OnlyDomainWithDot);
CPPUNIT_TEST(testConstructorWithString_OnlyDomainDotStrippedOff);
CPPUNIT_TEST(testConstructorWithString_InvalidOnlyDomainSingleDot);
CPPUNIT_TEST(testConstructorWithString_InvalidDomain);
+ CPPUNIT_TEST(testConstructorWithString_InvalidDomainOnlyDigits);
CPPUNIT_TEST(testConstructorWithString_InvalidDomainEmptyLabel);
CPPUNIT_TEST(testConstructorWithString_UpperCaseNode);
CPPUNIT_TEST(testConstructorWithString_UpperCaseDomain);
CPPUNIT_TEST(testConstructorWithString_UpperCaseResource);
CPPUNIT_TEST(testConstructorWithString_EmptyNode);
CPPUNIT_TEST(testConstructorWithString_EmptyDomain);
CPPUNIT_TEST(testConstructorWithString_EmptyDomainWithResource);
CPPUNIT_TEST(testConstructorWithString_DotDomain);
CPPUNIT_TEST(testConstructorWithString_DotDomainWithResource);
@@ -156,18 +157,22 @@ class JIDTest : public CppUnit::TestFixture
void testConstructorWithString_InvalidOnlyDomainSingleDot() {
CPPUNIT_ASSERT(!JID(".").isValid());
}
void testConstructorWithString_InvalidDomain() {
CPPUNIT_ASSERT(!JID("foo@bar,baz").isValid());
}
+ void testConstructorWithString_InvalidDomainOnlyDigits() {
+ CPPUNIT_ASSERT(!JID("1234").isValid());
+ }
+
void testConstructorWithString_InvalidDomainEmptyLabel() {
CPPUNIT_ASSERT(!JID("foo@bar..").isValid());
}
void testConstructorWithString_UpperCaseNode() {
JID testling("Fo\xCE\xA9@bar");
CPPUNIT_ASSERT_EQUAL(std::string("fo\xCF\x89"), testling.getNode());
CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getDomain());