]> git.sesse.net Git - vlc/commitdiff
Catch unsafe (but alas common) strerror()
authorRémi Denis-Courmont <remi@remlab.net>
Sun, 18 Apr 2010 14:32:19 +0000 (17:32 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sun, 18 Apr 2010 14:32:52 +0000 (17:32 +0300)
bin/override.c

index f3eebae5a069ad596a87737bc751750a7b42f9d5..b5de22d0f558b4c941937048c63ea11c75ffc0a9 100644 (file)
@@ -33,6 +33,7 @@ void vlc_enable_override (void);
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <dlfcn.h>
 #include <pthread.h>
 #ifdef HAVE_EXECINFO_H
@@ -260,6 +261,20 @@ char *setlocale (int cat, const char *locale)
 }
 
 
+/* strerror() is not thread-safe in theory (POSIX), nor in practice (glibc).
+ * This caused quite nasty crashes in the history of VLC/Linux. */
+char *strerror (int val)
+{
+    if (override)
+    {
+        static const char msg[] =
+            "Error message unavailable (use strerror_r instead of strerror)!";
+        LOG("Blocked", "%d", val);
+        return (char *)msg;
+    }
+    return CALL(strerror, val);
+}
+
 /*** Xlib ****/
 #ifdef HAVE_X11_XLIB_H
 # include <X11/Xlib.h>