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/UTF8ValidatorTest.cpp
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/UTF8ValidatorTest.cpp')
-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 @@
1/*
2 * Copyright (c) 2015 Isode Limited.
3 * All rights reserved.
4 * See the COPYING file for more information.
5 */
6
7#include <cppunit/extensions/HelperMacros.h>
8#include <cppunit/extensions/TestFactoryRegistry.h>
9
10#include <Swiften/IDN/UTF8Validator.h>
11
12using namespace Swift;
13
14class UTF8ValidatorTest : public CppUnit::TestFixture {
15 CPPUNIT_TEST_SUITE(UTF8ValidatorTest);
16
17 CPPUNIT_TEST(testValidUTF8Sequences);
18 CPPUNIT_TEST(testInvalidUTF8Sequences);
19
20 CPPUNIT_TEST_SUITE_END();
21
22public:
23 void testValidUTF8Sequences() {
24 {
25 unsigned char test[] = {0x74, 0x65, 0x73, 0x74};
26 CPPUNIT_ASSERT(UTF8IsValid(test, sizeof(test)));
27 }
28
29 {
30 unsigned char test[] = {0xf4, 0x8f, 0x80, 0xbf};
31 CPPUNIT_ASSERT(UTF8IsValid(test, sizeof(test)));
32 }
33 }
34
35 void testInvalidUTF8Sequences() {
36 {
37 unsigned char test[] = {0x41, 0xC2, 0x3E, 0x42};
38 CPPUNIT_ASSERT(!UTF8IsValid(test, sizeof(test)));
39 }
40
41 {
42 unsigned char test[] = {0xf4};
43 CPPUNIT_ASSERT(!UTF8IsValid(test, sizeof(test)));
44 }
45
46 {
47 unsigned char test[] = {0xf4, 0x8f, 0x65, 0x73, 0x80, 0xbf};
48 CPPUNIT_ASSERT(!UTF8IsValid(test, sizeof(test)));
49 }
50 }
51
52};
53
54CPPUNIT_TEST_SUITE_REGISTRATION(UTF8ValidatorTest);