diff options
| author | Edwin Mons <edwin.mons@isode.com> | 2018-10-24 14:53:32 (GMT) |
|---|---|---|
| committer | Edwin Mons <edwin.mons@isode.com> | 2018-10-24 16:37:20 (GMT) |
| commit | f0b7ffcea9b9983555b0555ea5815a193d1e129c (patch) | |
| tree | d3cda9eb667c50665019baa483298b280363f0bb | |
| parent | 1c71c5a77e037038c581a68774c96fad9a79030b (diff) | |
| download | swift-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
| -rw-r--r-- | Swiften/IDN/ICUConverter.cpp | 13 | ||||
| -rw-r--r-- | Swiften/QA/StorageTest/SConscript | 3 |
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 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2012-2016 Isode Limited. | 2 | * Copyright (c) 2012-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -19,6 +19,8 @@ using namespace Swift; | |||
| 19 | using boost::numeric_cast; | 19 | using boost::numeric_cast; |
| 20 | 20 | ||
| 21 | namespace { | 21 | namespace { |
| 22 | static constexpr auto maxStringPrepLength = 1023; | ||
| 23 | |||
| 22 | typedef std::vector<UChar, SafeAllocator<UChar> > ICUString; | 24 | typedef std::vector<UChar, SafeAllocator<UChar> > ICUString; |
| 23 | 25 | ||
| 24 | const char* toConstCharArray(const std::string& input) { | 26 | const char* toConstCharArray(const std::string& input) { |
| @@ -93,15 +95,8 @@ namespace { | |||
| 93 | ICUString icuInput = convertToICUString(s); | 95 | ICUString icuInput = convertToICUString(s); |
| 94 | ICUString icuResult; | 96 | ICUString icuResult; |
| 95 | UParseError parseError; | 97 | UParseError parseError; |
| 96 | icuResult.resize(icuInput.size()); | 98 | icuResult.resize(maxStringPrepLength); |
| 97 | 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); | 99 | 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); |
| 98 | icuResult.resize(numeric_cast<size_t>(icuResultLength)); | ||
| 99 | if (status == U_BUFFER_OVERFLOW_ERROR) { | ||
| 100 | status = U_ZERO_ERROR; | ||
| 101 | icuResult.resize(numeric_cast<size_t>(icuResultLength)); | ||
| 102 | 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); | ||
| 103 | icuResult.resize(numeric_cast<size_t>(icuResultLength)); | ||
| 104 | } | ||
| 105 | if (U_FAILURE(status)) { | 100 | if (U_FAILURE(status)) { |
| 106 | return std::vector<char, SafeAllocator<char> >(); | 101 | return std::vector<char, SafeAllocator<char> >(); |
| 107 | } | 102 | } |
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"] : | |||
| 10 | myenv.MergeFlags(myenv["CPPUNIT_FLAGS"]) | 10 | myenv.MergeFlags(myenv["CPPUNIT_FLAGS"]) |
| 11 | myenv.MergeFlags(myenv["GOOGLETEST_FLAGS"]) | 11 | myenv.MergeFlags(myenv["GOOGLETEST_FLAGS"]) |
| 12 | myenv.MergeFlags(myenv["BOOST_FLAGS"]) | 12 | myenv.MergeFlags(myenv["BOOST_FLAGS"]) |
| 13 | myenv.MergeFlags(myenv["LIBIDN_FLAGS"]) | 13 | myenv.MergeFlags(myenv.get("LIBIDN_FLAGS", {})) |
| 14 | myenv.MergeFlags(myenv.get("ICU_FLAGS", {})) | ||
| 14 | myenv.MergeFlags(myenv.get("EXPAT_FLAGS", {})) | 15 | myenv.MergeFlags(myenv.get("EXPAT_FLAGS", {})) |
| 15 | myenv.MergeFlags(myenv.get("LIBXML_FLAGS", {})) | 16 | myenv.MergeFlags(myenv.get("LIBXML_FLAGS", {})) |
| 16 | myenv.MergeFlags(myenv["PLATFORM_FLAGS"]) | 17 | myenv.MergeFlags(myenv["PLATFORM_FLAGS"]) |
Swift