libsepol/cil: Write a message when a log message is truncated

The MAX_LOG_SIZE is 512. It is possible that a log message could
exceed the max size (such as for neverallowx rules). If so, then
write out "<LOG MESSAGE TRUNCATED>", so that it is obvious that
the log message has been truncated.

Reported-by: Jonathan Hettwer <j2468h@googlemail.com>
Signed-off-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
James Carter 2022-03-09 18:02:44 -05:00
parent 8243b3e825
commit 5456002f1a

View File

@ -53,8 +53,13 @@ __attribute__ ((format (printf, 2, 0))) void cil_vlog(enum cil_log_level lvl, co
{
if (cil_log_level >= lvl) {
char buff[MAX_LOG_SIZE];
vsnprintf(buff, MAX_LOG_SIZE, msg, args);
(*cil_log_handler)(cil_log_level, buff);
int n = vsnprintf(buff, MAX_LOG_SIZE, msg, args);
if (n > 0) {
(*cil_log_handler)(cil_log_level, buff);
if (n >= MAX_LOG_SIZE) {
(*cil_log_handler)(cil_log_level, " <LOG MESSAGE TRUNCATED>");
}
}
}
}