summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/IDN/LibIDNConverter.cpp3
-rw-r--r--Swiften/IDN/UnitTest/IDNConverterTest.cpp18
2 files changed, 21 insertions, 0 deletions
diff --git a/Swiften/IDN/LibIDNConverter.cpp b/Swiften/IDN/LibIDNConverter.cpp
index 2325015..e2a87be 100644
--- a/Swiften/IDN/LibIDNConverter.cpp
+++ b/Swiften/IDN/LibIDNConverter.cpp
@@ -78,6 +78,9 @@ boost::optional<std::string> LibIDNConverter::getIDNAEncoded(const std::string&
if (idna_to_ascii_8z(domain.c_str(), &output, IDNA_USE_STD3_ASCII_RULES) == IDNA_SUCCESS) {
std::string result(output);
free(output);
+ if (result.size() > 255) {
+ return boost::optional<std::string>();
+ }
return result;
}
else {
diff --git a/Swiften/IDN/UnitTest/IDNConverterTest.cpp b/Swiften/IDN/UnitTest/IDNConverterTest.cpp
index c5f94d0..77a1ece 100644
--- a/Swiften/IDN/UnitTest/IDNConverterTest.cpp
+++ b/Swiften/IDN/UnitTest/IDNConverterTest.cpp
@@ -78,3 +78,21 @@ TEST_F(IDNConverterTest, testGetEncoded_Invalid) {
boost::optional<std::string> result = testling_->getIDNAEncoded("www.foo,bar.com");
ASSERT_FALSE(result);
}
+
+TEST_F(IDNConverterTest, testRFC1035LengthRestrictions) {
+ // label size check, 63 octets or less
+ ASSERT_TRUE(testling_->getIDNAEncoded(std::string(63, 'a') + ".example"));
+ ASSERT_TRUE(testling_->getIDNAEncoded(std::string(63, 'a') + "." + std::string(63, 'a') + ".example"));
+ ASSERT_FALSE(testling_->getIDNAEncoded(std::string(64, 'a') + "." + std::string(63, 'a') + ".example"));
+ ASSERT_FALSE(testling_->getIDNAEncoded(std::string(63, 'a') + "." + std::string(64, 'a') + ".example"));
+ ASSERT_FALSE(testling_->getIDNAEncoded(std::string(0, 'a') + "." + std::string(63, 'a') + ".example"));
+ ASSERT_FALSE(testling_->getIDNAEncoded(std::string(63, 'a') + "." + std::string(0, 'a') + ".example"));
+
+ // domain name 255 octets or less
+ ASSERT_TRUE(testling_->getIDNAEncoded(std::string(63, 'a') + ".example"));
+ ASSERT_TRUE(testling_->getIDNAEncoded(std::string(63, 'a') + "." + std::string(63, 'a') + ".example"));
+ ASSERT_TRUE(testling_->getIDNAEncoded(std::string(63, 'a') + "." + std::string(63, 'a') + "." + std::string(63, 'a') + ".example"));
+ ASSERT_TRUE(testling_->getIDNAEncoded(std::string(63, 'a') + "." + std::string(63, 'a') + "." + std::string(63, 'a') + "." + std::string(55, 'a') + ".example"));
+ ASSERT_FALSE(testling_->getIDNAEncoded(std::string(63, 'a') + "." + std::string(63, 'a') + "." + std::string(63, 'a') + "." + std::string(56, 'a') + ".example"));
+ ASSERT_FALSE(testling_->getIDNAEncoded(std::string(63, 'a') + "." + std::string(56, 'a') + "." + std::string(63, 'a') + "." + std::string(63, 'a') + ".example"));
+}