olga / rpms / glibc

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