This is an automated email from the ASF dual-hosted git repository.
FreeAndNil pushed a commit to branch Feature/AVSS-Fixes
in repository https://gitbox.apache.org/repos/asf/logging-log4net.git
The following commit(s) were added to refs/heads/Feature/AVSS-Fixes by this
push:
new 3113aa8a Fix unhandled exception in AppenderSkeleton finalizer isking
process termination Wrap Close() in the finalizer with try-catch for non-fatal
exceptions and move _isClosed into a finally block to prevent repeated
finalization attempts (CWE-755)
3113aa8a is described below
commit 3113aa8aee472edb7de73bf066d5a56c494ba520
Author: Jan Friedrich <[email protected]>
AuthorDate: Sun Jun 21 23:37:17 2026 +0200
Fix unhandled exception in AppenderSkeleton finalizer isking process
termination
Wrap Close() in the finalizer with try-catch for non-fatal exceptions and
move _isClosed into a finally block to prevent repeated finalization attempts
(CWE-755)
---
...8-fix-appender-skeleton-finalizer-exception.xml | 11 ++++++++++
src/log4net/Appender/AppenderSkeleton.cs | 24 +++++++++++++++++-----
2 files changed, 30 insertions(+), 5 deletions(-)
diff --git
a/src/changelog/3.3.2/298-fix-appender-skeleton-finalizer-exception.xml
b/src/changelog/3.3.2/298-fix-appender-skeleton-finalizer-exception.xml
new file mode 100644
index 00000000..f12ef5c4
--- /dev/null
+++ b/src/changelog/3.3.2/298-fix-appender-skeleton-finalizer-exception.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="https://logging.apache.org/xml/ns"
+ xsi:schemaLocation="https://logging.apache.org/xml/ns
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
+ type="fixed">
+ <issue id="f57d7b3-003"
link="https://github.com/apache/tooling-agents/blob/main/ASVS/reports/logging-log4net/f57d7b3/issues.md#issue-finding-003---finalizer-path-lacks-exception-protection-risking-process-termination"/>
+ <issue id="298" link="https://github.com/apache/logging-log4net/pull/298"/>
+ <description format="asciidoc">
+ fix unhandled exception in `AppenderSkeleton` finalizer that could
terminate the process when `OnClose()` throws (CWE-755)
+ </description>
+</entry>
diff --git a/src/log4net/Appender/AppenderSkeleton.cs
b/src/log4net/Appender/AppenderSkeleton.cs
index 6fb3ab3a..adf34128 100644
--- a/src/log4net/Appender/AppenderSkeleton.cs
+++ b/src/log4net/Appender/AppenderSkeleton.cs
@@ -65,13 +65,21 @@ public abstract class AppenderSkeleton : IAppender,
IBulkAppender, IOptionHandle
/// </remarks>
~AppenderSkeleton()
{
- // An appender might be closed then garbage collected.
+ // An appender might be closed then garbage collected.
// There is no point in closing twice.
- if (!_isClosed)
+ if (_isClosed)
+ {
+ return;
+ }
+ LogLog.Debug(_declaringType, $"Finalizing appender named [{Name}].");
+ try
{
- LogLog.Debug(_declaringType, $"Finalizing appender named [{Name}].");
Close();
}
+ catch (Exception ex) when (!ex.IsFatal())
+ {
+ LogLog.Warn(_declaringType, $"Exception during finalization of
{GetType().FullName} [{Name}].", ex);
+ }
}
/// <summary>
@@ -198,8 +206,14 @@ public void Close()
{
if (!_isClosed)
{
- OnClose();
- _isClosed = true;
+ try
+ {
+ OnClose();
+ }
+ finally
+ {
+ _isClosed = true;
+ }
}
}
}