Skip to content

#643 Log complete messages with embedded nul characters in console writers#658

Merged
swebb2066 merged 6 commits into
apache:masterfrom
apache-hb:master
May 19, 2026
Merged

#643 Log complete messages with embedded nul characters in console writers#658
swebb2066 merged 6 commits into
apache:masterfrom
apache-hb:master

Conversation

@apache-hb
Copy link
Copy Markdown
Contributor

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.

@swebb2066
Copy link
Copy Markdown
Contributor

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.


{
FILE *fp = fopen(path.c_str(), "wb");
size_t written = helpers::writeToConsole(false, message, fp);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be:

LOG4CXX_DECODE_CHAR(lsMessage, message);
size_t written = helpers::writeToConsole(lsMessage, fp);

#include "../logunit.h"

#include <log4cxx/private/consolewriter_priv.h>
#include <log4cxx/helpers/pool.h>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just need the following
#include <log4cxx/helpers/transcoder.h>

@swebb2066 swebb2066 merged commit fc67599 into apache:master May 19, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logging text with embedded nul bytes truncates log message

2 participants