Guard against CWE-134
I am using FlawFinder to scan my project and I get this one message.
syslog:If syslog's format strings can be influenced by an attacker, they can be exploited (CWE-134). Use a constant format string for syslog. Constant format string, so not considered risky.
The code is
bool logger_log_at_level(const struct module_logger* logger, const char* message, const int32_t log_level) {
bool log_sent = false;
if((log_level >= LOG_EMERG) && (log_level <= LOG_DEBUG)) {
(void)setlogmask(LOG_UPTO(logger->log_mask));
openlog(logger->logger_name, logger->logger_options, logger->logger_facility_code);
syslog(log_level, "%s", message);
closelog();
log_sent = true;
}
return log_sent;
}
I understand that other formatters can be passed in and allow for attackers to gain access to data. My question is how do I prevent this warning in this case? What else can I pass into `syslog` to make FlawFinder happy?
Posted Mar 22, 2022, 9:12 PM UTC