NopeCharon opened a new pull request, #802:
URL: https://github.com/apache/logging-log4cxx/pull/802

   Fixes #800
   
   ## Problem
   
   `LOG4CXX_CONFIGURATION_WATCH_SECONDS`, the `RollingFileAppender` 
`MaxBackupIndex` option and the port part of the `SyslogAppender` `SyslogHost` 
option are converted with `StringHelper::toInt` (`std::stoi`). A value that is 
not an integer throws `std::invalid_argument` or `std::out_of_range`, and the 
configurators do not catch these standard exceptions:
   
   - `DefaultConfigurator::configure`, and so the first 
`LogManager::getLogger()` call, throws when the watch seconds value is 
malformed.
   - `DOMConfigurator::configure` throws, because it only catches 
`helpers::Exception`.
   - `PropertyConfigurator` abandons the rest of the configuration file.
   
   ## Fix
   
   Use `OptionConverter::toInt`, which other numeric options (`MaxIndex`, 
`MaxMessageLength`, ...) already use, so a malformed value falls back to a 
default:
   
   - A malformed watch seconds value disables watching, as a non-positive value 
already does. Large values are clamped so the conversion to milliseconds can no 
longer overflow `int`.
   - A malformed `MaxBackupIndex` leaves the current value unchanged.
   - A malformed `SyslogHost` port selects the default syslog port.
   
   Valid values behave exactly as before.
   
   ## Testing
   
   New tests:
   - `DefaultConfiguratorTest::testMalformedWatchSeconds`
   - `RollingFileAppenderPropertiesTest::testMalformedMaxBackupIndex`
   - `SyslogAppenderTestCase::testSyslogHostWithMalformedPort`
   
   Without the fix, each of them fails with `Unexpected std::exception: stoi`. 
With the fix, the full `ctest` suite passes (70/70) on Linux (GCC 13, Ubuntu 
24.04).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

  • [PR] Do not throw from malformed... NopeCharon (via GitHub) via notifications

Reply via email to