diff --git a/HISTORY b/HISTORY index 2242786..40a12a0 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,7 @@ +Version 1.12 2014-12-05 + * bug fixed: must check the return value of vsnprintf + Version 1.11 2014-11-20 * remove usleep call in logger.c * bug fixed: NOT set last_block->next when realloc diff --git a/libfastcommon.spec b/libfastcommon.spec index 8b25f71..56bce2e 100644 --- a/libfastcommon.spec +++ b/libfastcommon.spec @@ -1,5 +1,5 @@ Name: libfastcommon -Version: 1.0.11 +Version: 1.0.12 Release: 1%{?dist} Summary: c common functions library extracted from my open source projects FastDFS License: GPL diff --git a/src/logger.c b/src/logger.c index 2d1a977..9bc89c3 100644 --- a/src/logger.c +++ b/src/logger.c @@ -800,6 +800,10 @@ void log_it_ex(LogContext *pContext, const int priority, const char *format, ... va_start(ap, format); len = vsnprintf(text, sizeof(text), format, ap); va_end(ap); + if (len > sizeof(text)) + { + len = sizeof(text); + } switch(priority) { @@ -859,9 +863,13 @@ void log_it_ex(LogContext *pContext, const int priority, const char *format, ... va_start(ap, format); \ len = vsnprintf(text, sizeof(text), format, ap); \ va_end(ap); \ + if (len > sizeof(text)) \ + { \ + len = sizeof(text); \ + } \ } \ \ - log_it_ex2(pContext, caption, text, len, bNeedSync, true); \ + log_it_ex2(pContext, caption, text, len, bNeedSync, true); void logEmergEx(LogContext *pContext, const char *format, ...) @@ -914,7 +922,10 @@ void logAccess(LogContext *pContext, struct timeval *tvStart, \ va_start(ap, format); len = vsnprintf(text, sizeof(text), format, ap); va_end(ap); - + if (len > sizeof(text)) + { + len = sizeof(text); + } doLogEx(pContext, tvStart, NULL, text, len, false, true); }