From 19537f8943ac4106c6d4ab0e00a48a8c0a9a0519 Mon Sep 17 00:00:00 2001 From: Shreenidhi Shedi Date: Mon, 9 Aug 2021 00:26:23 +0530 Subject: [PATCH] fix(install): validate return values log.c Signed-off-by: Shreenidhi Shedi --- src/install/log.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/install/log.c b/src/install/log.c index 3f77b5a5c1..f5ba54e561 100644 --- a/src/install/log.c +++ b/src/install/log.c @@ -167,20 +167,25 @@ static int log_dispatch(int level, const char *file, unsigned int line, const ch int log_metav(int level, const char *file, unsigned int line, const char *func, const char *format, va_list ap) { - - char buffer[LINE_MAX]; + char buffer[LINE_MAX] = {0}; int saved_errno, r; if (_likely_(LOG_PRI(level) > log_max_level)) return 0; saved_errno = errno; - vsnprintf(buffer, sizeof(buffer), format, ap); + + r = vsnprintf(buffer, sizeof(buffer), format, ap); + if (r <= 0) { + goto end; + } + char_array_0(buffer); r = log_dispatch(level, file, line, func, buffer); - errno = saved_errno; +end: + errno = saved_errno; return r; } @@ -204,12 +209,12 @@ _noreturn_ static void log_assert(const char *text, const char *file, unsigned i { static char buffer[LINE_MAX]; - snprintf(buffer, sizeof(buffer), format, text, file, line, func); - - char_array_0(buffer); - log_abort_msg = buffer; + if (snprintf(buffer, sizeof(buffer), format, text, file, line, func) > 0) { + char_array_0(buffer); + log_abort_msg = buffer; + log_dispatch(LOG_CRIT, file, line, func, buffer); + } - log_dispatch(LOG_CRIT, file, line, func, buffer); abort(); }