You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ts...@apache.org on 2020/08/08 08:50:59 UTC

[logging-log4cxx] 01/01: Fixed an infinite loop in "Transcoder::encode(const LogString&, std::wstring&)" by appending LOSSCHAR. The most likely alternative would be to throw on any invalid input instead, but that's not the case right now and LOSSCHAR used in other places as well.

This is an automated email from the ASF dual-hosted git repository.

tschoening pushed a commit to branch logcxx_398_transcoder_encode_losschar
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git

commit 097cecd0d9353e44de4bc5024689b8d0a7cc925d
Author: Thorsten Schöning <ts...@am-soft.de>
AuthorDate: Sat Aug 8 10:49:39 2020 +0200

    Fixed an infinite loop in "Transcoder::encode(const LogString&, std::wstring&)" by appending LOSSCHAR. The most likely alternative would be to throw on any invalid input instead, but that's not the case right now and LOSSCHAR used in other places as well.
    
    https://issues.apache.org/jira/browse/LOGCXX-398
---
 src/changes/changes.xml     |  1 +
 src/main/cpp/transcoder.cpp | 13 ++++++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 937fc4a..fb2f76f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -58,6 +58,7 @@
 			<action issue="LOGCXX-411" type="fix">Crash when logging on multiple threads.</action>
 			<action issue="LOGCXX-400" type="fix">C++11 does not allow char literals with highest bit set unless cast</action>
 			<action issue="LOGCXX-399" type="fix">Non-ascii character output wrong.</action>
+			<action issue="LOGCXX-398" type="fix">Infinite loop in Transcoder::encode(const LogString&amp; src, std::wstring&amp; dst)</action>
 			<action issue="LOGCXX-394" type="fix">Levels are not thread safe</action>
 			<action issue="LOGCXX-388" type="fix">Hierarchy::updateParents loops forever on illegal logger-name like '.logger1'</action>
 			<action issue="LOGCXX-382" type="fix">Mingw build type conversion error</action>
diff --git a/src/main/cpp/transcoder.cpp b/src/main/cpp/transcoder.cpp
index d423fb4..76e9361 100644
--- a/src/main/cpp/transcoder.cpp
+++ b/src/main/cpp/transcoder.cpp
@@ -509,11 +509,18 @@ void Transcoder::encode(const LogString& src, std::wstring& dst)
 	dst.append(src);
 #else
 
-	for (LogString::const_iterator i = src.begin();
-		i != src.end();)
+	for (LogString::const_iterator i = src.begin(); i != src.end();)
 	{
 		unsigned int cp = Transcoder::decode(src, i);
-		encode(cp, dst);
+		if (cp != 0xFFFF)
+		{
+			encode(cp, dst);
+		}
+		else
+		{
+			dst.append(1, LOSSCHAR);
+			i++;
+		}
 	}
 
 #endif