4c174f
commit 3bb748257405e94e13de76573a4e9da1cfd961d0
4c174f
Author: Florian Weimer <fweimer@redhat.com>
4c174f
Date:   Tue Jul 3 15:54:49 2018 +0200
4c174f
4c174f
    libio: Disable vtable validation in case of interposition [BZ #23313]
978e96
    
4c174f
    (cherry picked from commit c402355dfa7807b8e0adb27c009135a7e2b9f1b0)
4c174f
9832fd
Backported from the upstream release/2.27/master branch.
4c174f
4c174f
diff --git a/libio/vtables.c b/libio/vtables.c
4c174f
index e364ea03edbfa75b..d6478e4bab9050ce 100644
4c174f
--- a/libio/vtables.c
4c174f
+++ b/libio/vtables.c
4c174f
@@ -68,3 +68,19 @@ _IO_vtable_check (void)
4c174f
 
4c174f
   __libc_fatal ("Fatal error: glibc detected an invalid stdio handle\n");
4c174f
 }
4c174f
+
4c174f
+/* Some variants of libstdc++ interpose _IO_2_1_stdin_ etc. and
4c174f
+   install their own vtables directly, without calling _IO_init or
4c174f
+   other functions.  Detect this by looking at the vtables values
4c174f
+   during startup, and disable vtable validation in this case.  */
4c174f
+#ifdef SHARED
4c174f
+__attribute__ ((constructor))
4c174f
+static void
4c174f
+check_stdfiles_vtables (void)
4c174f
+{
4c174f
+  if (_IO_2_1_stdin_.vtable != &_IO_file_jumps
4c174f
+      || _IO_2_1_stdout_.vtable != &_IO_file_jumps
4c174f
+      || _IO_2_1_stderr_.vtable != &_IO_file_jumps)
4c174f
+    IO_set_accept_foreign_vtables (&_IO_vtable_check);
4c174f
+}
4c174f
+#endif