GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Escaping special characters in multiple appenders by FreeAndNil · Pull Request #315 · apache/logging-log4net

Conversation

@FreeAndNil

@FreeAndNil FreeAndNil commented Sep 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Follow-ups from the second security scan, stacked on #314. One rule, applied to
every sink that had got it wrong: content a sink cannot carry is escaped visibly,
never silently deleted, and never allowed to cost the record or the event.

  • LocalSyslogAppender escapes newlines, which reached syslog(3) unchanged and
    let content forge a second record. NewLineHandling mirrors the remote appender,
    and SyslogNewLineHandling moves out of RemoteSyslogAppender so both can use
    it. Measured: glibc does no escaping of its own, contrary to the old comment.
  • EventLogAppender and OutputDebugStringAppender escape NUL, which ended the
    stored record with no error. Measured on Windows: a 45 character message with a
    NUL at 23 stored as its 23 character prefix.
  • RemoteSyslogAppender escapes characters outside RFC 3164 rather than deleting
    them. "Schönwetter 你好" reached the collector as "Schnwetter ".
  • TelnetAppender and SmtpPickupDirAppender escape unpaired surrogates. Both
    used a writer whose encoding throws: the first disconnected every connected
    client, the second destroyed the whole buffered batch and left a truncated mail.
  • EventLogAppender's size limit is computed rather than guessed. The old constant
    sat above the point where the service silently discards the record, so log4net
    truncated events into oblivion.

Behaviour changes: syslog exception traces are now one escaped record instead of
several lines, Keep restores the old behaviour; RemoteSyslogAppender.SyslogNewLineHandling is no longer nested,
configuration binds by value name and is unaffected.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
FreeAndNil added a commit that referenced this pull request Sep 1, 2026
@FreeAndNil
move SyslogNewLineHandling out of RemoteSyslogAppender #315
75676ef
LocalSyslogAppender needs the same option, so nesting it in one of the two
appenders no longer fits.

Breaking for code naming RemoteSyslogAppender.SyslogNewLineHandling. Configuration
binds the value by name and is unaffected.
FreeAndNil added a commit that referenced this pull request Sep 1, 2026
@FreeAndNil
escape newlines in LocalSyslogAppender content #315
158b61e
A newline in logged content ends the record for a syslog daemon that writes the
message through to a line oriented log, so content could forge a second entry that
looks authentic.

The code claimed syslog(3) escapes control characters itself. It does not: glibc
formats the buffer and hands it over, and the escaping seen on a mainstream Linux
is the daemon's. Measured with LOG_PERROR, an embedded newline comes out as two
lines.

NewLineHandling mirrors the option RemoteSyslogAppender has had all along, which
already escaped by default. Keep restores the previous behaviour. The remote
appender's habit of dropping non-ASCII is deliberately not copied.
FreeAndNil added a commit that referenced this pull request Sep 1, 2026
@FreeAndNil
escape NUL characters in OutputDebugStringAppender content #315
8a30b9c
OutputDebugStringW takes a null terminated string, so a NUL in logged content
ended the record there and dropped whatever the layout rendered after it.

The escape LocalSyslogAppender already had is now shared by both, since
EventLogAppender is the same shape and will want it too. Its tests moved onto the
shared helper with it.

The appender level test only runs on Windows: Append refuses to run elsewhere.
FreeAndNil added a commit that referenced this pull request Sep 1, 2026
@FreeAndNil
escape NUL characters in EventLogAppender content #315
b8d6bf1
ReportEventW takes a null terminated string, so a NUL in logged content ended the
stored record there and dropped whatever the layout rendered after it. WriteEntry
raises nothing, so the record simply stored short and no ErrorHandler call fired.

Measured on Windows 11 build 26200: a 45 character message with a NUL at 23 stored
as its 23 character prefix.

Escaping happens before the size limit is applied, since it doubles each NUL, and
PrepareEventText exists so that ordering can be tested without an event log.
FreeAndNil added a commit that referenced this pull request Sep 1, 2026
@FreeAndNil
escape what RemoteSyslogAppender cannot send instead of deleting it #315
900f286


RFC 3164 allows only visible ASCII and space in the message, and everything else
fell through the loop unwritten. "Schoenwetter <CJK>" reached the collector as
"Schnwetter ", and a tab vanished from between its neighbours, with no marker and
no error.

Such characters are now written as a \uXXXX escape, which stays inside the allowed
range. Encoding still cannot make the message body non-ASCII, which the appender
page now says.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
compare ordinally when asserting no NUL survives #315
e722104
Does.Not.Contain is culture sensitive, and a culture sensitive comparison treats
NUL as ignorable: it reports a match in a string that contains none. Both new
escape tests therefore failed on Windows against correctly escaped output.

ContainsConstraint has no comparison knob at all, so these use
Contains.Substring(x).Using(StringComparison.Ordinal), negated with the ! operator
Constraint defines. The EventLog test asserts the whole value instead, which is
ordinal and pins the length too.

This is the shape f018 reports in StringMatchFilter, which is still open.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
move SyslogNewLineHandling out of RemoteSyslogAppender #315
ff7c677
LocalSyslogAppender needs the same option, so nesting it in one of the two
appenders no longer fits.

Breaking for code naming RemoteSyslogAppender.SyslogNewLineHandling. Configuration
binds the value by name and is unaffected.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
escape newlines in LocalSyslogAppender content #315
780f309
A newline in logged content ends the record for a syslog daemon that writes the
message through to a line oriented log, so content could forge a second entry that
looks authentic.

The code claimed syslog(3) escapes control characters itself. It does not: glibc
formats the buffer and hands it over, and the escaping seen on a mainstream Linux
is the daemon's. Measured with LOG_PERROR, an embedded newline comes out as two
lines.

NewLineHandling mirrors the option RemoteSyslogAppender has had all along, which
already escaped by default. Keep restores the previous behaviour. The remote
appender's habit of dropping non-ASCII is deliberately not copied.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
escape NUL characters in OutputDebugStringAppender content #315
dcbbef0
OutputDebugStringW takes a null terminated string, so a NUL in logged content
ended the record there and dropped whatever the layout rendered after it.

The escape LocalSyslogAppender already had is now shared by both, since
EventLogAppender is the same shape and will want it too. Its tests moved onto the
shared helper with it.

The appender level test only runs on Windows: Append refuses to run elsewhere.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
escape NUL characters in EventLogAppender content #315
dce0929
ReportEventW takes a null terminated string, so a NUL in logged content ended the
stored record there and dropped whatever the layout rendered after it. WriteEntry
raises nothing, so the record simply stored short and no ErrorHandler call fired.

Measured on Windows 11 build 26200: a 45 character message with a NUL at 23 stored
as its 23 character prefix.

Escaping happens before the size limit is applied, since it doubles each NUL, and
PrepareEventText exists so that ordering can be tested without an event log.
@FreeAndNil
FreeAndNil force-pushed the Feature/315-local-syslog-newlines branch from e722104 to 6aca022 Compare September 2, 2026 04:32
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
escape what RemoteSyslogAppender cannot send instead of deleting it #315
aadd936


RFC 3164 allows only visible ASCII and space in the message, and everything else
fell through the loop unwritten. "Schoenwetter <CJK>" reached the collector as
"Schnwetter ", and a tab vanished from between its neighbours, with no marker and
no error.

Such characters are now written as a \uXXXX escape, which stays inside the allowed
range. Encoding still cannot make the message body non-ASCII, which the appender
page now says.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
compare ordinally when asserting no NUL survives #315
6aca022
Does.Not.Contain is culture sensitive, and a culture sensitive comparison treats
NUL as ignorable: it reports a match in a string that contains none. Both new
escape tests therefore failed on Windows against correctly escaped output.

ContainsConstraint has no comparison knob at all, so these use
Contains.Substring(x).Using(StringComparison.Ordinal), negated with the ! operator
Constraint defines. The EventLog test asserts the whole value instead, which is
ordinal and pins the length too.

This is the shape f018 reports in StringMatchFilter, which is still open.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
move SyslogNewLineHandling out of RemoteSyslogAppender #315
0b1826b
LocalSyslogAppender needs the same option, so nesting it in one of the two
appenders no longer fits.

Breaking for code naming RemoteSyslogAppender.SyslogNewLineHandling. Configuration
binds the value by name and is unaffected.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
escape newlines in LocalSyslogAppender content #315
1540450
A newline in logged content ends the record for a syslog daemon that writes the
message through to a line oriented log, so content could forge a second entry that
looks authentic.

The code claimed syslog(3) escapes control characters itself. It does not: glibc
formats the buffer and hands it over, and the escaping seen on a mainstream Linux
is the daemon's. Measured with LOG_PERROR, an embedded newline comes out as two
lines.

NewLineHandling mirrors the option RemoteSyslogAppender has had all along, which
already escaped by default. Keep restores the previous behaviour. The remote
appender's habit of dropping non-ASCII is deliberately not copied.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
escape NUL characters in OutputDebugStringAppender content #315
acd34b1
OutputDebugStringW takes a null terminated string, so a NUL in logged content
ended the record there and dropped whatever the layout rendered after it.

The escape LocalSyslogAppender already had is now shared by both, since
EventLogAppender is the same shape and will want it too. Its tests moved onto the
shared helper with it.

The appender level test only runs on Windows: Append refuses to run elsewhere.
@FreeAndNil
FreeAndNil force-pushed the Feature/315-local-syslog-newlines branch from 6aca022 to 3e5e016 Compare September 2, 2026 19:20
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
escape NUL characters in EventLogAppender content #315
e4c2bd4
ReportEventW takes a null terminated string, so a NUL in logged content ended the
stored record there and dropped whatever the layout rendered after it. WriteEntry
raises nothing, so the record simply stored short and no ErrorHandler call fired.

Measured on Windows 11 build 26200: a 45 character message with a NUL at 23 stored
as its 23 character prefix.

Escaping happens before the size limit is applied, since it doubles each NUL, and
PrepareEventText exists so that ordering can be tested without an event log.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
escape what RemoteSyslogAppender cannot send instead of deleting it #315
4f1d01f


RFC 3164 allows only visible ASCII and space in the message, and everything else
fell through the loop unwritten. "Schoenwetter <CJK>" reached the collector as
"Schnwetter ", and a tab vanished from between its neighbours, with no marker and
no error.

Such characters are now written as a \uXXXX escape, which stays inside the allowed
range. Encoding still cannot make the message body non-ASCII, which the appender
page now says.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
compare ordinally when asserting no NUL survives #315
3e5e016
Does.Not.Contain is culture sensitive, and a culture sensitive comparison treats
NUL as ignorable: it reports a match in a string that contains none. Both new
escape tests therefore failed on Windows against correctly escaped output.

ContainsConstraint has no comparison knob at all, so these use
Contains.Substring(x).Using(StringComparison.Ordinal), negated with the ! operator
Constraint defines. The EventLog test asserts the whole value instead, which is
ordinal and pins the length too.

This is the shape f018 reports in StringMatchFilter, which is still open.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
move SyslogNewLineHandling out of RemoteSyslogAppender #315
793ca06
LocalSyslogAppender needs the same option, so nesting it in one of the two
appenders no longer fits.

Breaking for code naming RemoteSyslogAppender.SyslogNewLineHandling. Configuration
binds the value by name and is unaffected.
@FreeAndNil
FreeAndNil force-pushed the Feature/315-local-syslog-newlines branch from 3e5e016 to 65c603f Compare September 2, 2026 20:44
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
escape newlines in LocalSyslogAppender content #315
95c921d
A newline in logged content ends the record for a syslog daemon that writes the
message through to a line oriented log, so content could forge a second entry that
looks authentic.

The code claimed syslog(3) escapes control characters itself. It does not: glibc
formats the buffer and hands it over, and the escaping seen on a mainstream Linux
is the daemon's. Measured with LOG_PERROR, an embedded newline comes out as two
lines.

NewLineHandling mirrors the option RemoteSyslogAppender has had all along, which
already escaped by default. Keep restores the previous behaviour. The remote
appender's habit of dropping non-ASCII is deliberately not copied.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
escape NUL characters in OutputDebugStringAppender content #315
4c0cf92
OutputDebugStringW takes a null terminated string, so a NUL in logged content
ended the record there and dropped whatever the layout rendered after it.

The escape LocalSyslogAppender already had is now shared by both, since
EventLogAppender is the same shape and will want it too. Its tests moved onto the
shared helper with it.

The appender level test only runs on Windows: Append refuses to run elsewhere.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
escape NUL characters in EventLogAppender content #315
db91fcc
ReportEventW takes a null terminated string, so a NUL in logged content ended the
stored record there and dropped whatever the layout rendered after it. WriteEntry
raises nothing, so the record simply stored short and no ErrorHandler call fired.

Measured on Windows 11 build 26200: a 45 character message with a NUL at 23 stored
as its 23 character prefix.

Escaping happens before the size limit is applied, since it doubles each NUL, and
PrepareEventText exists so that ordering can be tested without an event log.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
escape what RemoteSyslogAppender cannot send instead of deleting it #315
f3db5b3


RFC 3164 allows only visible ASCII and space in the message, and everything else
fell through the loop unwritten. "Schoenwetter <CJK>" reached the collector as
"Schnwetter ", and a tab vanished from between its neighbours, with no marker and
no error.

Such characters are now written as a \uXXXX escape, which stays inside the allowed
range. Encoding still cannot make the message body non-ASCII, which the appender
page now says.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
compare ordinally when asserting no NUL survives #315
fb60a84
Does.Not.Contain is culture sensitive, and a culture sensitive comparison treats
NUL as ignorable: it reports a match in a string that contains none. Both new
escape tests therefore failed on Windows against correctly escaped output.

ContainsConstraint has no comparison knob at all, so these use
Contains.Substring(x).Using(StringComparison.Ordinal), negated with the ! operator
Constraint defines. The EventLog test asserts the whole value instead, which is
ordinal and pins the length too.

This is the shape f018 reports in StringMatchFilter, which is still open.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
compute the EventLog size limit instead of guessing it #315
65c603f
The limit is a whole record budget, and the log name, the source and the machine
name are spent from it one character for one. The fixed 31837 sat above the real
ceiling, so log4net truncated to a size the service then discarded: the event was
lost whole rather than shortened, with no exception and no record.

Measured on Windows 11 build 26200 over five source name lengths and two log names
with no residual: stored while message + logName + applicationName stays within
31736. One character more and nothing is stored.

ApplicationName defaults to the app domain name, so the consumer's assembly name
came out of the budget invisibly. A 1024 margin is held back because crossing the
line is not one lost message: the write still consumes log space, and a log given
about thirty of them was later found reporting a negative record count.

Truncation is now reported through the error handler. There is no channel where
the service records a dropped write, so that is the only signal available.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
move SyslogNewLineHandling out of RemoteSyslogAppender #315
4058cff
LocalSyslogAppender needs the same option, so nesting it in one of the two
appenders no longer fits.

Breaking for code naming RemoteSyslogAppender.SyslogNewLineHandling. Configuration
binds the value by name and is unaffected.
FreeAndNil added a commit that referenced this pull request Sep 2, 2026
@FreeAndNil
escape newlines in LocalSyslogAppender content #315
470e710
A newline in logged content ends the record for a syslog daemon that writes the
message through to a line oriented log, so content could forge a second entry that
looks authentic.

The code claimed syslog(3) escapes control characters itself. It does not: glibc
formats the buffer and hands it over, and the escaping seen on a mainstream Linux
is the daemon's. Measured with LOG_PERROR, an embedded newline comes out as two
lines.

NewLineHandling mirrors the option RemoteSyslogAppender has had all along, which
already escaped by default. Keep restores the previous behaviour. The remote
appender's habit of dropping non-ASCII is deliberately not copied.
This was referenced Nov 12, 2026
Bump the nuget-dependencies group with 14 updates SvenGroot/JumboCore#78
Closed
Bump Crc32.NET and 12 others SvenGroot/JumboCore#79
Closed
Bump log4net from 3.3.2 to 3.5.0 jasonlandreth/GarminR10-BLE-Connector#6
Closed
DEV: Bump log4net from 3.4.0 to 3.5.0 origam/origam#5193
Merged
DEV: Bump log4net from 3.4.0 to 3.5.0 origam/origam#5194
Merged
DEV: Bump log4net from 3.4.0 to 3.5.0 origam/origam#5195
Merged
DEV: Bump log4net from 3.4.0 to 3.5.0 origam/origam#5196
Merged
DEV: Bump log4net from 3.4.0 to 3.5.0 origam/origam#5197
Merged
DEV: Bump log4net from 3.4.0 to 3.5.0 origam/origam#5198
Merged
Bump log4net from 3.3.0 to 3.5.0 chutch3/kenku#87
Merged
Bump log4net from 2.0.15 to 3.6.0 sg-scale/NETworkManager--2022.12.20.0#5
Open
Bump the minor-version-updates group with 4 updates PxTools/PCAxis.Menu.OracleDatamodelMenu#115
Merged
Bump log4net and 3 others PxTools/PCAxis.Metadata#108
Merged
Bump Crc32.NET and 12 others SvenGroot/JumboCore#80
Closed
Bump the nuget-dependencies group with 14 updates SvenGroot/JumboCore#81
Closed
Bump log4net and 4 others PxTools/PCAxis.Menu.MsSqlDatamodelMenu#114
Merged
Bump log4net and 3 others PxTools/PXWeb.SavedQuery.Oracle#119
Merged
Bump log4net and 4 others PxTools/PCAxis.Core#142
Merged
Bump log4net from 3.3.1 to 3.6.0 bbtsoftware/AzureDevOpsPolicyConfigurator#255
Open
Bump the minor-version-updates group with 4 updates PxTools/PCAxis.Menu#100
Merged
Bump log4net and 3 others PxTools/PCAxis.Query#113
Merged
Bump log4net and PCAxis.Core PxTools/PCAxis.Query#114
Closed
Bump log4net from 2.0.8 to 3.6.0 devsecops-lab-luis/demo-ghas-multilenguaje#27
Open
Dependency (dependabot/nuget): Bump log4net from 3.3.0 to 3.6.0 Nevergoodstudy/NETworkManager-macOS#24
Open
Bump the nuget-dependencies group with 14 updates SvenGroot/JumboCore#82
Open
Bump Crc32.NET and 12 others SvenGroot/JumboCore#83
Open
deps: Bump log4net from 3.3.2 to 3.6.0 OliverRetro/WavePlus#62
Open
Bump log4net from 3.3.1 to 3.6.0 bNobo/needabreak#176
Open
This was referenced Nov 19, 2026
Bump log4net from 3.3.2 to 3.6.0 jasonlandreth/GarminR10-BLE-Connector#7
Open
Bump Crc32.NET and 12 others SvenGroot/JumboCore#84
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gdziadkiewicz gdziadkiewicz gdziadkiewicz approved these changes
@fluffynuts fluffynuts Awaiting requested review from fluffynuts

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

3.5.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@FreeAndNil @gdziadkiewicz
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.