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

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


The following commit(s) were added to refs/heads/master by this push:
     new 1d53672c Fix SEGV with invalid appenders (#471)
1d53672c is described below

commit 1d53672ca5f415a064ad2bf08862ffd7f235e38f
Author: Robert Middleton <[email protected]>
AuthorDate: Sun Feb 2 10:37:51 2025 -0500

    Fix SEGV with invalid appenders (#471)
    
    If a non-appender class is attempted to be used as an appender, a SEGV can
    occur.  Add explicit check to make sure that the class being used is in fact
    an appender.
---
 src/main/cpp/domconfigurator.cpp                    | 4 ++++
 src/test/cpp/xml/domtestcase.cpp                    | 8 ++++++++
 src/test/resources/input/xml/DOMInvalidAppender.xml | 7 +++++++
 3 files changed, 19 insertions(+)

diff --git a/src/main/cpp/domconfigurator.cpp b/src/main/cpp/domconfigurator.cpp
index b734b6f6..41141381 100644
--- a/src/main/cpp/domconfigurator.cpp
+++ b/src/main/cpp/domconfigurator.cpp
@@ -224,6 +224,10 @@ AppenderPtr DOMConfigurator::parseAppender(Pool& p,
        {
                ObjectPtr instance = 
ObjectPtr(Loader::loadClass(className).newInstance());
                AppenderPtr appender = LOG4CXX_NS::cast<Appender>(instance);
+               if(!appender){
+                       LogLog::error(LOG4CXX_STR("Could not cast class of type 
[") + className + LOG4CXX_STR("] to appender"));
+                       return AppenderPtr();
+               }
                PropertySetter propSetter(appender);
 
                appender->setName(subst(getAttribute(utf8Decoder, 
appenderElement, NAME_ATTR)));
diff --git a/src/test/cpp/xml/domtestcase.cpp b/src/test/cpp/xml/domtestcase.cpp
index 29d83a48..f5210ff5 100644
--- a/src/test/cpp/xml/domtestcase.cpp
+++ b/src/test/cpp/xml/domtestcase.cpp
@@ -53,6 +53,7 @@ LOGUNIT_CLASS(DOMTestCase)
 #endif
        LOGUNIT_TEST(test3);
        LOGUNIT_TEST(test4);
+       LOGUNIT_TEST(invalidAppender);
        LOGUNIT_TEST(invalidLevel);
        LOGUNIT_TEST_SUITE_END();
 
@@ -228,6 +229,13 @@ public:
                LOGUNIT_ASSERT(exists);
        }
 
+       void invalidAppender()
+       {
+               // Load an XML file that attempts to use a levelmatchfilter as 
an appender.
+               // We should not crash when loading this file.
+               
DOMConfigurator::configure(LOG4CXX_TEST_STR("input/xml/DOMInvalidAppender.xml"));
+  }
+  
        void invalidLevel()
        {
                // Load an XML file that attempts to use a filter as a level.
diff --git a/src/test/resources/input/xml/DOMInvalidAppender.xml 
b/src/test/resources/input/xml/DOMInvalidAppender.xml
new file mode 100644
index 00000000..f11c06e2
--- /dev/null
+++ b/src/test/resources/input/xml/DOMInvalidAppender.xml
@@ -0,0 +1,7 @@
+<log4j:configuration xmlns:log4j=' '>
+  <appender name="TEMP" class="levelmatchfilter"></appender>
+
+  <root>
+    <appender-ref ref="TEMP"/>
+  </root>
+</log4j:configuration>

Reply via email to