-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Hardens PropertiesUtil
against recursive property sources
#3263
base: 2.24.x
Are you sure you want to change the base?
Conversation
As showed in #3252, Spring's `JndiPropertySource` not only can throw exceptions, but can also perform logging calls. Such a call causes a recursive call to `PropertiesUtil.getProperty("log4j2.flowMessageFactory"`) and a `StackOverflowException` in the best scenario. The worst scenario includes a deadlock. This PR: - Moves the creation of the default `MessageFactory` and `FlowMessageFactory` to the static initializer of `LoggerContext`. This should be close enough to the pre-2.23.0 location in `AbstractLogger`. The `LoggerContext` class is usually initialized, before Spring Boot adds its property sources to `PropertiesUtil`. - Adds a check to `PropertiesUtil` to ignore recursive calls. Closes #3252.
new LoggerContext(LoggerMessageFactoryCustomizationTest.class.getSimpleName())) { | ||
Logger logger = new Logger( | ||
loggerContext, | ||
"arguments_should_be_honored", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use @TestInfo
instead of hardcoding the method name. (Same goes for the other test methods too.)
import org.junitpioneer.jupiter.SetSystemProperty; | ||
|
||
@SetSystemProperty( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By making this test-scoped, aren't you changing the arguments_should_be_honored()
test? That is,
- Before: there are no property-provided configurations, but only arguments passed to
Logger::new
- New: there are property-provided configurations, and also arguments passed to
Logger::new
In the new case, you cannot know which configuration source has kicked in.
@Test | ||
@ResourceLock(value = Resources.SYSTEM_PROPERTIES, mode = ResourceAccessMode.READ) | ||
@Issue("https://github.com/apache/logging-log4j2/issues/3252") | ||
void testRecursivePropertySource() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we also verify the status logger warning?
As showed in #3252, Spring's
JndiPropertySource
not only can throw exceptions, but can also perform logging calls. Such a call causes a recursive call toPropertiesUtil.getProperty("log4j2.flowMessageFactory"
) and aStackOverflowException
in the best scenario. The worst scenario includes a deadlock.This PR:
MessageFactory
andFlowMessageFactory
to the static initializer ofLoggerContext
. This should be close enough to the pre-2.23.0 location inAbstractLogger
. TheLoggerContext
class is usually initialized, before Spring Boot adds its property sources toPropertiesUtil
.PropertiesUtil
to ignore recursive calls.Closes #3252.