summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2015-09-17 08:14:57 (GMT)
committerSwift Review <review@swift.im>2015-10-16 10:38:19 (GMT)
commit3a2b966711dbe6fa937c485d7ad56916219badb2 (patch)
tree30e9f30bc3f2a3ca6b4ed0c5c11f4ae0703485d0 /Swiften/IDN/UnitTest
parent582ca915b5b82ada46d1183a7b882455ee01b7b1 (diff)
downloadswift-3a2b966711dbe6fa937c485d7ad56916219badb2.zip
swift-3a2b966711dbe6fa937c485d7ad56916219badb2.tar.bz2
Add UTF-8 validation function and validate input to libIDN functions
This is required to protect against the CVE-2015-2059 vulnerability in libIDN. Test-Information: Added unit tests for UTF-8 validation and tested that existing unit tests still pass. Change-Id: I0a94136894c6e0004081456c59155a78a3dabf5f
Diffstat (limited to 'Swiften/IDN/UnitTest')
-rw-r--r--Swiften/IDN/UnitTest/UTF8ValidatorTest.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/Swiften/IDN/UnitTest/UTF8ValidatorTest.cpp b/Swiften/IDN/UnitTest/UTF8ValidatorTest.cpp
new file mode 100644
index 0000000..0295757
--- /dev/null
+++ b/Swiften/IDN/UnitTest/UTF8ValidatorTest.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/IDN/UTF8Validator.h>
+
+using namespace Swift;
+
+class UTF8ValidatorTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(UTF8ValidatorTest);
+
+ CPPUNIT_TEST(testValidUTF8Sequences);
+ CPPUNIT_TEST(testInvalidUTF8Sequences);
+
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void testValidUTF8Sequences() {
+ {
+ unsigned char test[] = {0x74, 0x65, 0x73, 0x74};
+ CPPUNIT_ASSERT(UTF8IsValid(test, sizeof(test)));
+ }
+
+ {
+ unsigned char test[] = {0xf4, 0x8f, 0x80, 0xbf};
+ CPPUNIT_ASSERT(UTF8IsValid(test, sizeof(test)));
+ }
+ }
+
+ void testInvalidUTF8Sequences() {
+ {
+ unsigned char test[] = {0x41, 0xC2, 0x3E, 0x42};
+ CPPUNIT_ASSERT(!UTF8IsValid(test, sizeof(test)));
+ }
+
+ {
+ unsigned char test[] = {0xf4};
+ CPPUNIT_ASSERT(!UTF8IsValid(test, sizeof(test)));
+ }
+
+ {
+ unsigned char test[] = {0xf4, 0x8f, 0x65, 0x73, 0x80, 0xbf};
+ CPPUNIT_ASSERT(!UTF8IsValid(test, sizeof(test)));
+ }
+ }
+
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(UTF8ValidatorTest);