libsepol/cil: Write a message when a log message is truncated
PATCH 1/1 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 <[email protected]>
Signed-off-by James Carter <[email protected]>
--- libsepol/cil/src/cil_log.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
libsepol/cil/src/cil_log.c +7 -2
@@ -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>" ); + } + } } }
Signature · 1 line
2.34.1
Quoted 8 lines · James Carter
The
MAX_LOG_SIZEis 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 <[email protected]>Signed-off-by James Carter <[email protected]>
Merged.
Jim
Quoted 27 lines
--- libsepol/cil/src/cil_log.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)libsepol/cil/src/cil_log.c +7
-3@@ -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>" ); + } + } } } --2.34.1