diff options
| author | Tobias Markmann <tm@ayena.de> | 2018-11-08 13:50:25 (GMT) |
|---|---|---|
| committer | Tobias Markmann <tm@ayena.de> | 2018-11-08 17:26:20 (GMT) |
| commit | 644db9fce94670e610db46bdd28eb9d1e658a798 (patch) | |
| tree | 7773b18c1eeca8d7d8cb5bb8cd25ae0b7b4a7447 | |
| parent | 0b4e062a59613b2597b712c0106c3ed08b747637 (diff) | |
| download | swift-644db9fce94670e610db46bdd28eb9d1e658a798.zip swift-644db9fce94670e610db46bdd28eb9d1e658a798.tar.bz2 | |
Handle RFC 1035 label and domain len restrictions in libidn backend
LibIDNConverter was fixed to handle these restrictions
correctly.
Test-Information:
Added unit tests for RFC 1035 length restrictions for labels
and domain names.
The libidn and ICU backends pass the new test.
Change-Id: Ie570b0ee4c5c6381f7769f6178ec2a5824074221
| -rw-r--r-- | Swiften/IDN/LibIDNConverter.cpp | 3 | ||||
| -rw-r--r-- | Swiften/IDN/UnitTest/IDNConverterTest.cpp | 18 |
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& | |||
| 78 | if (idna_to_ascii_8z(domain.c_str(), &output, IDNA_USE_STD3_ASCII_RULES) == IDNA_SUCCESS) { | 78 | if (idna_to_ascii_8z(domain.c_str(), &output, IDNA_USE_STD3_ASCII_RULES) == IDNA_SUCCESS) { |
| 79 | std::string result(output); | 79 | std::string result(output); |
| 80 | free(output); | 80 | free(output); |
| 81 | if (result.size() > 255) { | ||
| 82 | return boost::optional<std::string>(); | ||
| 83 | } | ||
| 81 | return result; | 84 | return result; |
| 82 | } | 85 | } |
| 83 | else { | 86 | 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) { | |||
| 78 | boost::optional<std::string> result = testling_->getIDNAEncoded("www.foo,bar.com"); | 78 | boost::optional<std::string> result = testling_->getIDNAEncoded("www.foo,bar.com"); |
| 79 | ASSERT_FALSE(result); | 79 | ASSERT_FALSE(result); |
| 80 | } | 80 | } |
| 81 | |||
| 82 | TEST_F(IDNConverterTest, testRFC1035LengthRestrictions) { | ||
| 83 | // label size check, 63 octets or less | ||
| 84 | ASSERT_TRUE(testling_->getIDNAEncoded(std::string(63, 'a') + ".example")); | ||
| 85 | ASSERT_TRUE(testling_->getIDNAEncoded(std::string(63, 'a') + "." + std::string(63, 'a') + ".example")); | ||
| 86 | ASSERT_FALSE(testling_->getIDNAEncoded(std::string(64, 'a') + "." + std::string(63, 'a') + ".example")); | ||
| 87 | ASSERT_FALSE(testling_->getIDNAEncoded(std::string(63, 'a') + "." + std::string(64, 'a') + ".example")); | ||
| 88 | ASSERT_FALSE(testling_->getIDNAEncoded(std::string(0, 'a') + "." + std::string(63, 'a') + ".example")); | ||
| 89 | ASSERT_FALSE(testling_->getIDNAEncoded(std::string(63, 'a') + "." + std::string(0, 'a') + ".example")); | ||
| 90 | |||
| 91 | // domain name 255 octets or less | ||
| 92 | ASSERT_TRUE(testling_->getIDNAEncoded(std::string(63, 'a') + ".example")); | ||
| 93 | ASSERT_TRUE(testling_->getIDNAEncoded(std::string(63, 'a') + "." + std::string(63, 'a') + ".example")); | ||
| 94 | ASSERT_TRUE(testling_->getIDNAEncoded(std::string(63, 'a') + "." + std::string(63, 'a') + "." + std::string(63, 'a') + ".example")); | ||
| 95 | ASSERT_TRUE(testling_->getIDNAEncoded(std::string(63, 'a') + "." + std::string(63, 'a') + "." + std::string(63, 'a') + "." + std::string(55, 'a') + ".example")); | ||
| 96 | ASSERT_FALSE(testling_->getIDNAEncoded(std::string(63, 'a') + "." + std::string(63, 'a') + "." + std::string(63, 'a') + "." + std::string(56, 'a') + ".example")); | ||
| 97 | ASSERT_FALSE(testling_->getIDNAEncoded(std::string(63, 'a') + "." + std::string(56, 'a') + "." + std::string(63, 'a') + "." + std::string(63, 'a') + ".example")); | ||
| 98 | } | ||
Swift