Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty appender ref recursion #472

Merged
merged 2 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/cpp/domconfigurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ AppenderPtr DOMConfigurator::parseAppender(Pool& p,
{
LogString refName = subst(getAttribute(utf8Decoder, currentElement, REF_ATTR));

if (appender->instanceof(AppenderAttachable::getStaticClass()))
if (!refName.empty() && appender->instanceof(AppenderAttachable::getStaticClass()))
{
AppenderAttachablePtr aa = LOG4CXX_NS::cast<AppenderAttachable>(appender);
if (LogLog::isDebugEnabled())
Expand All @@ -310,6 +310,10 @@ AppenderPtr DOMConfigurator::parseAppender(Pool& p,
}
aa->addAppender(findAppenderByReference(p, utf8Decoder, currentElement, doc, appenders));
}
else if (refName.empty())
{
LogLog::error(LOG4CXX_STR("Can't add appender with empty ref attribute"));
}
else
{
LogLog::error(LOG4CXX_STR("Requesting attachment of appender named [") +
Expand Down
8 changes: 8 additions & 0 deletions src/test/cpp/xml/domtestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ LOGUNIT_CLASS(DOMTestCase)
#endif
LOGUNIT_TEST(test3);
LOGUNIT_TEST(test4);
LOGUNIT_TEST(recursiveAppenderRef);
LOGUNIT_TEST(invalidAppender);
LOGUNIT_TEST(invalidLevel);
LOGUNIT_TEST_SUITE_END();
Expand Down Expand Up @@ -229,6 +230,13 @@ LOGUNIT_CLASS(DOMTestCase)
LOGUNIT_ASSERT(exists);
}


void recursiveAppenderRef()
{
// Load a bad XML file, make sure that we don't crash in endless recursion
DOMConfigurator::configure(LOG4CXX_TEST_STR("input/xml/DOMConfiguratorRecursive.xml"));
}

void invalidAppender()
{
// Load an XML file that attempts to use a levelmatchfilter as an appender.
Expand Down
10 changes: 10 additions & 0 deletions src/test/resources/input/xml/DOMConfiguratorRecursive.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<log4j:configuration xmlns:log4j=" ">
<appender class="AsyncAppender">
<appender-ref/>
</appender>

<logger>
<appender-ref/>
</logger>

</log4j:configuration>