mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-24 17:41:34 +08:00
Protected from size_t to int overflow in systemd sink
This commit is contained in:
parent
847f7de003
commit
261d2c5ae4
@ -44,16 +44,23 @@ protected:
|
||||
{
|
||||
int err;
|
||||
|
||||
size_t length = msg.payload.size();
|
||||
// limit to max int
|
||||
if(length > std::numeric_limits<int>::max())
|
||||
{
|
||||
length = std::numeric_limits<int>::max();
|
||||
}
|
||||
|
||||
// Do not send source location if not available
|
||||
if (msg.source.empty())
|
||||
{
|
||||
// Note: function call inside '()' to avoid macro expansion
|
||||
err = (sd_journal_send)(
|
||||
"MESSAGE=%.*s", static_cast<int>(msg.payload.size()), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level), nullptr);
|
||||
"MESSAGE=%.*s", static_cast<int>(length), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level), nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(msg.payload.size()), msg.payload.data(), "PRIORITY=%d",
|
||||
err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), msg.payload.data(), "PRIORITY=%d",
|
||||
syslog_level(msg.level), "SOURCE_FILE=%s", msg.source.filename, "SOURCE_LINE=%d", msg.source.line, "SOURCE_FUNC=%s",
|
||||
msg.source.funcname, nullptr);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user