[vlc-devel] [PATCH 2/2] Map page zero to '(null)' string if needed

Francois Cartegnie fcvlcdev at free.fr
Thu Jun 10 23:25:32 CEST 2010


---
 bin/vlc.c    |   18 +++++++++++++++++-
 configure.ac |   22 ++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/bin/vlc.c b/bin/vlc.c
index 2b287f1..cce0164 100644
--- a/bin/vlc.c
+++ b/bin/vlc.c
@@ -40,10 +40,13 @@
 #include <unistd.h>
 #include <dlfcn.h>
 
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(NEED_PRINTF_PAGEZEROFIX)
 #include <string.h>
 #endif
 
+#ifdef NEED_PRINTF_PAGEZEROFIX
+#include <sys/mman.h>
+#endif
 
 /* Explicit HACK */
 extern void LocaleFree (const char *);
@@ -165,6 +168,16 @@ int main( int i_argc, const char *ppsz_argv[] )
     /* Block all these signals */
     pthread_sigmask (SIG_BLOCK, &set, NULL);
 
+#ifdef NEED_PRINTF_PAGEZEROFIX
+    /* try to fix null strings if glibc doesn't
+       this can't work on latest Linux & BSD because of exploit fix
+    */
+    int page_zero_mapped = ( mmap(0, sysconf( _SC_PAGESIZE ),
+			    PROT_WRITE|PROT_READ,
+                            MAP_FIXED|MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) == 0 );
+    if ( page_zero_mapped )
+      memcpy((char *)0, "(null)\0", 7);
+#endif
     /* Note that FromLocale() can be used before libvlc is initialized */
     const char *argv[i_argc + 4];
     int argc = 0;
@@ -237,5 +250,8 @@ out:
         _exit (0);
     }
 #endif
+#ifdef NEED_PRINTF_PAGEZEROFIX
+    if ( page_zero_mapped ) munmap( 0, sysconf( _SC_PAGESIZE ) );
+#endif
     return 0;
 }
diff --git a/configure.ac b/configure.ac
index bc74f62..37ed6d1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -657,6 +657,28 @@ AC_CHECK_FUNC(getopt_long,, [
 ])
 AC_SUBST(GNUGETOPT_LIBS)
 
+dnl Solaris and non glibc builds will crash on NULL strings passed to *printf
+if test "${SYS}" == "solaris" -a "$cross_compiling" != "yes"; then
+  AC_CACHE_CHECK([for printf page zero fix], [ac_cv_printf_page_zero_fix], [
+    AC_RUN_IFELSE([
+      AC_LANG_SOURCE([[
+       #include <stdio.h>
+        int main(){
+          char foo[] = "(****)";
+          sprintf(foo, "%s", NULL);
+          return 0;
+        }
+      ]])
+     ],
+     [ac_cv_printf_page_zero_fix=no],
+     [ac_cv_printf_page_zero_fix=yes],
+     [ac_cv_printf_page_zero_fix=skipped])
+  ])
+  if test "$ac_cv_printf_page_zero_fix" = yes; then
+    AC_DEFINE(NEED_PRINTF_PAGEZEROFIX, 1, [*printf requires NULL to be fixed])
+  fi
+fi
+
 if test "${SYS}" != "mingw32" -a "${SYS}" != "mingwce"; then
 AC_CHECK_LIB(m,cos,[
   VLC_ADD_LIBS([adjust wave ripple psychedelic gradient a52tofloat32 dtstofloat32 x264 goom visual panoramix rotate noise grain scene kate flac lua chorus_flanger],[-lm])
-- 
1.6.4.4




More information about the vlc-devel mailing list