Commit 261d2c5a authored by gabime's avatar gabime

Protected from size_t to int overflow in systemd sink

parent 847f7de0
......@@ -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);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment