Avoid array-bounds warning for strncat on i586 (bug 20260)
[glibc.git] / libio / vtables.c
blobe364ea03edbfa75b1c07d4d46d7d1d7195268dce
1 /* libio vtable validation.
2 Copyright (C) 2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <dlfcn.h>
20 #include <libioP.h>
21 #include <stdio.h>
23 #ifdef SHARED
25 void (*IO_accept_foreign_vtables) (void) attribute_hidden;
27 /* Used to detected multiple libcs. */
28 extern struct dl_open_hook *_dl_open_hook;
29 libc_hidden_proto (_dl_open_hook);
31 #else /* !SHARED */
33 /* Used to check whether static dlopen support is needed. */
34 # pragma weak __dlopen
36 #endif
38 void attribute_hidden
39 _IO_vtable_check (void)
41 #ifdef SHARED
42 /* Honor the compatibility flag. */
43 void (*flag) (void) = atomic_load_relaxed (&IO_accept_foreign_vtables);
44 PTR_DEMANGLE (flag);
45 if (flag == &_IO_vtable_check)
46 return;
48 /* In case this libc copy is in a non-default namespace, we always
49 need to accept foreign vtables because there is always a
50 possibility that FILE * objects are passed across the linking
51 boundary. */
53 Dl_info di;
54 struct link_map *l;
55 if (_dl_open_hook != NULL
56 || (_dl_addr (_IO_vtable_check, &di, &l, NULL) != 0
57 && l->l_ns != LM_ID_BASE))
58 return;
61 #else /* !SHARED */
62 /* We cannot perform vtable validation in the static dlopen case
63 because FILE * handles might be passed back and forth across the
64 boundary. Therefore, we disable checking in this case. */
65 if (__dlopen != NULL)
66 return;
67 #endif
69 __libc_fatal ("Fatal error: glibc detected an invalid stdio handle\n");