changeset 31560:6e550be9e418

Avoid out-of-bounds read if mp_msg prints an empty string.
author reimar
date Fri, 02 Jul 2010 23:43:09 +0000
parents 631f813874f0
children 1b8ac7d80ad9
files mp_msg.c
diffstat 1 files changed, 3 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mp_msg.c	Fri Jul 02 21:19:21 2010 +0000
+++ b/mp_msg.c	Fri Jul 02 23:43:09 2010 +0000
@@ -181,6 +181,7 @@
     char tmp[MSGSIZE_MAX];
     FILE *stream = lev <= MSGL_WARN ? stderr : stdout;
     static int header = 1;
+    size_t len;
 
     if (!mp_msg_test(mod, lev)) return; // do not display
     va_start(va, format);
@@ -223,7 +224,8 @@
     if (header)
         print_msg_module(stream, mod);
     set_msg_color(stream, lev);
-    header = tmp[strlen(tmp)-1] == '\n' || tmp[strlen(tmp)-1] == '\r';
+    len = strlen(tmp);
+    header = len && (tmp[len-1] == '\n' || tmp[len-1] == '\r');
 
     fprintf(stream, "%s", tmp);
     if (mp_msg_color)