[FFmpeg-cvslog] Fix races in default av_log handler
Reinhard Tartler
git at videolan.org
Mon May 2 03:23:21 CEST 2011
ffmpeg | branch: release/0.6 | Reinhard Tartler <siretart at sandy.tauware.de> | Sat Apr 30 08:11:13 2011 +0200| [66ebf37c735158e060c5acf8df62391b8b6182ef] | committer: Reinhard Tartler
Fix races in default av_log handler
Prevent competing threads from overwriting (shared) buffers.
Original patch by: Michael Niedermayer <michaelni at gmx.at>
(cherry picked from commit 0247bdee2581a6857a24c5ff297f01d3a3112b11)
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=66ebf37c735158e060c5acf8df62391b8b6182ef
---
libavutil/log.c | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/libavutil/log.c b/libavutil/log.c
index 9a8b66e..9319dcd 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;
More information about the ffmpeg-cvslog
mailing list