You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "apache-hb (via GitHub)" <gi...@apache.org> on 2026/05/10 17:01:42 UTC

[PR] #643 Log complete messages with embedded nul characters in console writers [logging-log4cxx]

apache-hb opened a new pull request, #658:
URL: https://github.com/apache/logging-log4cxx/pull/658

   Resolves #643 
   Writes to stdout and stderr now go through fwrite rather than fputs. This stops embedded nul characters in log messages from truncating the rest of the message. Added a regression test `testWriteEmbeddedNullCharacters` to go along with the changes.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] #643 Log complete messages with embedded nul characters in console writers [logging-log4cxx]

Posted by "swebb2066 (via GitHub)" <gi...@apache.org>.
swebb2066 merged PR #658:
URL: https://github.com/apache/logging-log4cxx/pull/658


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] #643 Log complete messages with embedded nul characters in console writers [logging-log4cxx]

Posted by "swebb2066 (via GitHub)" <gi...@apache.org>.
swebb2066 commented on PR #658:
URL: https://github.com/apache/logging-log4cxx/pull/658#issuecomment-4447784311

   I think moving the duplicated `isWide()` implementations to a single implementation in `consolewrite.cpp` would improve the code.
   
   Note that both implementations are currently `private`, so can be removed from the class interface without breaking the ABI.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] #643 Log complete messages with embedded nul characters in console writers [logging-log4cxx]

Posted by "swebb2066 (via GitHub)" <gi...@apache.org>.
swebb2066 commented on code in PR #658:
URL: https://github.com/apache/logging-log4cxx/pull/658#discussion_r3263182527


##########
src/test/cpp/helpers/consolewritertestcase.cpp:
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../logunit.h"
+
+#include <log4cxx/private/consolewriter_priv.h>
+#include <log4cxx/helpers/pool.h>

Review Comment:
   Just need the following 
   `#include <log4cxx/helpers/transcoder.h>`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] #643 Log complete messages with embedded nul characters in console writers [logging-log4cxx]

Posted by "swebb2066 (via GitHub)" <gi...@apache.org>.
swebb2066 commented on code in PR #658:
URL: https://github.com/apache/logging-log4cxx/pull/658#discussion_r3239502359


##########
src/test/cpp/helpers/consolewritertestcase.cpp:
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../logunit.h"
+
+#include <log4cxx/private/consolewriter_priv.h>
+#include <log4cxx/helpers/pool.h>
+#include <apr_file_io.h>
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+
+
+LOGUNIT_CLASS(ConsoleWriterTest)
+{
+	LOGUNIT_TEST_SUITE(ConsoleWriterTest);
+	LOGUNIT_TEST(testWriteEmbeddedNullCharacters);
+	LOGUNIT_TEST_SUITE_END();
+
+public:
+	/**
+	 * Tests writing to an unknown host.
+	 */
+	void testWriteEmbeddedNullCharacters()
+	{
+		Pool p;
+		const char* tmpdir = NULL;
+		apr_status_t stat = apr_temp_dir_get(&tmpdir, p.getAPRPool());
+		LOGUNIT_ASSERT_EQUAL(APR_SUCCESS, stat);
+
+		std::string path = tmpdir;
+		path += "/log4cxx.test.log";
+
+		remove(path.c_str());
+
+		std::string message{"Hello\0World!", 12};
+
+		{
+			FILE *fp = fopen(path.c_str(), "wb");
+			size_t written = helpers::writeToConsole(false, message, fp);

Review Comment:
   This should be:
   ```
   LOG4CXX_DECODE_CHAR(lsMessage, message);
   size_t written = helpers::writeToConsole(lsMessage, fp);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org