NopeCharon opened a new issue, #800:
URL: https://github.com/apache/logging-log4cxx/issues/800
Three configuration values are converted with `StringHelper::toInt` (i.e.
`std::stoi`), which throws `std::invalid_argument` or `std::out_of_range` when
the value is not a valid integer. None of the configuration code paths catch
these standard exceptions, so a typo in a configuration value escapes into the
application:
| Value | Code | Example |
| --- | --- | --- |
| `LOG4CXX_CONFIGURATION_WATCH_SECONDS` (environment variable or
`Configurator::properties()`) |
`DefaultConfigurator::getConfigurationWatchDelay` |
`LOG4CXX_CONFIGURATION_WATCH_SECONDS=5s` |
| `RollingFileAppender` `MaxBackupIndex` option |
`RollingFileAppender::setOption` | `log4j.appender.R.MaxBackupIndex=ten` |
| `SyslogAppender` `SyslogHost` option with a port |
`SyslogAppender::setSyslogHost` | `<param name="SyslogHost" value="loghost:"/>`
|
Consequences:
* With the watch-seconds case, the exception escapes from the first
`LogManager::getLogger()` call, because `Hierarchy::ensureIsConfigured` and
`DefaultConfigurator::configure` do not catch it. An unhandled exception there
usually terminates the program at startup.
* `DOMConfigurator` only catches `helpers::Exception`, so the
`MaxBackupIndex`/`SyslogHost` cases escape from `DOMConfigurator::configure`.
* `PropertyConfigurator::doConfigure(const File&, ...)` catches
`std::exception`, but it abandons the rest of the configuration file.
Also, a large `LOG4CXX_CONFIGURATION_WATCH_SECONDS` value (e.g. `3000000`)
overflows `int` when multiplied by 1000.
Reproduction (current master, Linux):
```cpp
rolling::RollingFileAppender a;
a.setOption(LOG4CXX_STR("MaxBackupIndex"), LOG4CXX_STR("ten")); // throws
std::invalid_argument("stoi")
net::SyslogAppender s;
s.setOption(LOG4CXX_STR("SyslogHost"), LOG4CXX_STR("loghost:")); // throws
std::invalid_argument("stoi")
spi::Configurator::properties().setProperty(LOG4CXX_STR("LOG4CXX_CONFIGURATION_WATCH_SECONDS"),
LOG4CXX_STR("abc"));
LogManager::getLogger("x"); // throws std::invalid_argument("stoi") when a
configuration file exists
```
Expected: an invalid value is treated like other numeric options (e.g.
`MaxIndex`, `MaxMessageLength`), which use `OptionConverter::toInt` and fall
back to a default instead of throwing.
--
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]