diff options
Diffstat (limited to 'Swiften/IDN/LibIDNConverter.cpp')
-rw-r--r-- | Swiften/IDN/LibIDNConverter.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Swiften/IDN/LibIDNConverter.cpp b/Swiften/IDN/LibIDNConverter.cpp index f36929a..78303b1 100644 --- a/Swiften/IDN/LibIDNConverter.cpp +++ b/Swiften/IDN/LibIDNConverter.cpp @@ -1,25 +1,28 @@ /* - * Copyright (c) 2012-2013 Isode Limited. + * Copyright (c) 2012-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/IDN/LibIDNConverter.h> extern "C" { #include <stringprep.h> #include <idna.h> } -#include <vector> #include <cassert> #include <cstdlib> +#include <vector> + +#include <boost/shared_ptr.hpp> + #include <Swiften/Base/ByteArray.h> #include <Swiften/Base/SafeAllocator.h> -#include <boost/shared_ptr.hpp> +#include <Swiften/IDN/UTF8Validator.h> using namespace Swift; namespace { static const int MAX_STRINGPREP_SIZE = 1024; @@ -34,12 +37,16 @@ namespace { return 0; } template<typename StringType, typename ContainerType> ContainerType getStringPreparedInternal(const StringType& s, IDNConverter::StringPrepProfile profile) { ContainerType input(s.begin(), s.end()); + if (!UTF8IsValid(s.data(), s.size())) { + return ContainerType(); + } + input.resize(MAX_STRINGPREP_SIZE); if (stringprep(&input[0], MAX_STRINGPREP_SIZE, static_cast<Stringprep_profile_flags>(0), getLibIDNProfile(profile)) == 0) { return input; } else { return ContainerType(); |