summaryrefslogtreecommitdiff
path: root/libavutil/log.c
diff options
context:
space:
mode:
authorReinhard Tartler <siretart@tauware.de>2011-04-27 21:21:54 +0200
committerReinhard Tartler <siretart@sandy.tauware.de>2011-04-29 22:46:13 +0200
commit0247bdee2581a6857a24c5ff297f01d3a3112b11 (patch)
tree3454a5867c732cadc8a91a23765a17eb5c7d736e /libavutil/log.c
parentcf3ac54339c42530342ec053b981d7b717404889 (diff)
Fix races in default av_log handler
Prevent competing threads from overwriting (shared) buffers. Original patch by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/log.c')
-rw-r--r--libavutil/log.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/libavutil/log.c b/libavutil/log.c
index deab11965d..cfeb21cd5a 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -83,7 +83,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 int is_atty;
AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
if(level>av_log_level)
@@ -108,7 +109,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
if(!is_atty) is_atty= isatty(2) ? 1 : -1;
#endif
- if(print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev)){
+ if(print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strncmp(line, prev, sizeof line)){
count++;
if(is_atty==1)
fprintf(stderr, " Last message repeated %d times\r", count);
@@ -119,7 +120,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
count=0;
}
colored_fputs(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;