From 66ebf37c735158e060c5acf8df62391b8b6182ef Mon Sep 17 00:00:00 2001 From: Reinhard Tartler Date: Sat, 30 Apr 2011 08:11:13 +0200 Subject: [PATCH] Fix races in default av_log handler Prevent competing threads from overwriting (shared) buffers. Original patch by: Michael Niedermayer (cherry picked from commit 0247bdee2581a6857a24c5ff297f01d3a3112b11) --- libavutil/log.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavutil/log.c b/libavutil/log.c index 9a8b66ee4d..9319dcdbe7 100644 --- a/libavutil/log.c +++ b/libavutil/log.c @@ -59,7 +59,8 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) { static int print_prefix=1; static int count; - static char line[1024], prev[1024]; + static char prev[1024]; + char line[1024]; static const uint8_t color[]={0x41,0x41,0x11,0x03,9,9,9}; AVClass* avc= ptr ? *(AVClass**)ptr : NULL; if(level>av_log_level) @@ -73,7 +74,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl); print_prefix= line[strlen(line)-1] == '\n'; - if(print_prefix && !strcmp(line, prev)){ + if(print_prefix && !strncmp(line, prev, sizeof line)){ count++; return; } @@ -82,7 +83,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) count=0; } colored_fputs(color[av_clip(level>>3, 0, 6)], line); - strcpy(prev, line); + strncpy(prev, line, sizeof line); } static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;