summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Mons <edwin.mons@isode.com>2018-10-24 14:53:32 (GMT)
committerEdwin Mons <edwin.mons@isode.com>2018-10-24 16:37:20 (GMT)
commitf0b7ffcea9b9983555b0555ea5815a193d1e129c (patch)
treed3cda9eb667c50665019baa483298b280363f0bb /Swiften
parent1c71c5a77e037038c581a68774c96fad9a79030b (diff)
downloadswift-f0b7ffcea9b9983555b0555ea5815a193d1e129c.zip
swift-f0b7ffcea9b9983555b0555ea5815a193d1e129c.tar.bz2
Honour JID part length in ICUConverter
ICUConverter allowed jidparts greater than 1023 bytes during stringprep. The SConscript of StorageTest did not work when libidn had been disabled, which prevented test=unit from completing. Test-Information: Unit tests pass on Debian 9 in a build with ICU and ASan enabled. Change-Id: I791a09457c6b852e61ce1281871e0f3ca0ce645c
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/IDN/ICUConverter.cpp13
-rw-r--r--Swiften/QA/StorageTest/SConscript3
2 files changed, 6 insertions, 10 deletions
diff --git a/Swiften/IDN/ICUConverter.cpp b/Swiften/IDN/ICUConverter.cpp
index d6b0827..37ce708 100644
--- a/Swiften/IDN/ICUConverter.cpp
+++ b/Swiften/IDN/ICUConverter.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012-2016 Isode Limited.
+ * Copyright (c) 2012-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -19,6 +19,8 @@ using namespace Swift;
using boost::numeric_cast;
namespace {
+ static constexpr auto maxStringPrepLength = 1023;
+
typedef std::vector<UChar, SafeAllocator<UChar> > ICUString;
const char* toConstCharArray(const std::string& input) {
@@ -93,15 +95,8 @@ namespace {
ICUString icuInput = convertToICUString(s);
ICUString icuResult;
UParseError parseError;
- icuResult.resize(icuInput.size());
+ icuResult.resize(maxStringPrepLength);
int32_t icuResultLength = usprep_prepare(icuProfile.get(), vecptr(icuInput), numeric_cast<int32_t>(icuInput.size()), vecptr(icuResult), numeric_cast<int32_t>(icuResult.size()), USPREP_ALLOW_UNASSIGNED, &parseError, &status);
- icuResult.resize(numeric_cast<size_t>(icuResultLength));
- if (status == U_BUFFER_OVERFLOW_ERROR) {
- status = U_ZERO_ERROR;
- icuResult.resize(numeric_cast<size_t>(icuResultLength));
- icuResultLength = usprep_prepare(icuProfile.get(), vecptr(icuInput), numeric_cast<int32_t>(icuInput.size()), vecptr(icuResult), numeric_cast<int32_t>(icuResult.size()), USPREP_ALLOW_UNASSIGNED, &parseError, &status);
- icuResult.resize(numeric_cast<size_t>(icuResultLength));
- }
if (U_FAILURE(status)) {
return std::vector<char, SafeAllocator<char> >();
}
diff --git a/Swiften/QA/StorageTest/SConscript b/Swiften/QA/StorageTest/SConscript
index b8360ec..46107a0 100644
--- a/Swiften/QA/StorageTest/SConscript
+++ b/Swiften/QA/StorageTest/SConscript
@@ -10,7 +10,8 @@ if env["TEST"] :
myenv.MergeFlags(myenv["CPPUNIT_FLAGS"])
myenv.MergeFlags(myenv["GOOGLETEST_FLAGS"])
myenv.MergeFlags(myenv["BOOST_FLAGS"])
- myenv.MergeFlags(myenv["LIBIDN_FLAGS"])
+ myenv.MergeFlags(myenv.get("LIBIDN_FLAGS", {}))
+ myenv.MergeFlags(myenv.get("ICU_FLAGS", {}))
myenv.MergeFlags(myenv.get("EXPAT_FLAGS", {}))
myenv.MergeFlags(myenv.get("LIBXML_FLAGS", {}))
myenv.MergeFlags(myenv["PLATFORM_FLAGS"])