2018-01-01 00:32:25 +00:00
|
|
|
/* Copyright (C) 1993-2018 Free Software Foundation, Inc.
|
2001-07-06 04:58:11 +00:00
|
|
|
This file is part of the GNU C Library.
|
1997-10-13 01:27:24 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1997-10-13 01:27:24 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
1997-10-13 01:27:24 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
1997-10-13 01:27:24 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>.
|
1997-10-13 01:27:24 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
As a special exception, if you link the code in this file with
|
|
|
|
files compiled with a GNU compiler to produce an executable,
|
|
|
|
that does not cause the resulting executable to be covered by
|
|
|
|
the GNU Lesser General Public License. This exception does not
|
|
|
|
however invalidate any other reasons why the executable file
|
|
|
|
might be covered by the GNU Lesser General Public License.
|
|
|
|
This exception applies to code released by its copyright holders
|
|
|
|
in files containing the exception. */
|
1997-10-13 01:27:24 +00:00
|
|
|
|
2000-03-21 23:09:29 +00:00
|
|
|
#include <shlib-compat.h>
|
2000-03-22 08:01:35 +00:00
|
|
|
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
|
2000-03-21 23:09:29 +00:00
|
|
|
|
1997-12-14 22:24:57 +00:00
|
|
|
#define _IO_USE_OLD_IO_FILE
|
1997-10-13 01:27:24 +00:00
|
|
|
#include "libioP.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
2018-02-07 23:42:04 +00:00
|
|
|
FILE *
|
2004-03-10 09:29:17 +00:00
|
|
|
attribute_compat_text_section
|
2015-10-16 20:21:49 +00:00
|
|
|
_IO_old_fopen (const char *filename, const char *mode)
|
1997-10-13 01:27:24 +00:00
|
|
|
{
|
|
|
|
struct locked_FILE
|
|
|
|
{
|
2003-11-04 09:58:57 +00:00
|
|
|
struct _IO_FILE_complete_plus fp;
|
1997-10-13 01:27:24 +00:00
|
|
|
#ifdef _IO_MTSAFE_IO
|
|
|
|
_IO_lock_t lock;
|
|
|
|
#endif
|
|
|
|
} *new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
|
|
|
|
|
|
|
|
if (new_f == NULL)
|
|
|
|
return NULL;
|
|
|
|
#ifdef _IO_MTSAFE_IO
|
2003-11-04 09:58:57 +00:00
|
|
|
new_f->fp.file._file._lock = &new_f->lock;
|
1997-10-13 01:27:24 +00:00
|
|
|
#endif
|
2003-11-04 09:58:57 +00:00
|
|
|
_IO_old_init (&new_f->fp.file._file, 0);
|
2015-05-18 11:58:54 +00:00
|
|
|
_IO_JUMPS_FILE_plus (&new_f->fp) = &_IO_old_file_jumps;
|
libio: Implement vtable verification [BZ #20191]
This commit puts all libio vtables in a dedicated, read-only ELF
section, so that they are consecutive in memory. Before any indirect
jump, the vtable pointer is checked against the section boundaries,
and the process is terminated if the vtable pointer does not fall into
the special ELF section.
To enable backwards compatibility, a special flag variable
(_IO_accept_foreign_vtables), protected by the pointer guard, avoids
process termination if libio stream object constructor functions have
been called earlier. Such constructor functions are called by the GCC
2.95 libstdc++ library, and this mechanism ensures compatibility with
old binaries. Existing callers inside glibc of these functions are
adjusted to call the original functions, not the wrappers which enable
vtable compatiblity.
The compatibility mechanism is used to enable passing FILE * objects
across a static dlopen boundary, too.
2016-06-23 18:01:40 +00:00
|
|
|
_IO_old_file_init_internal ((struct _IO_FILE_plus *) &new_f->fp);
|
2018-02-07 23:42:04 +00:00
|
|
|
if (_IO_old_file_fopen ((FILE *) &new_f->fp, filename, mode) != NULL)
|
|
|
|
return (FILE *) &new_f->fp;
|
2012-05-23 11:33:15 +00:00
|
|
|
_IO_un_link ((struct _IO_FILE_plus *) &new_f->fp);
|
1997-10-13 01:27:24 +00:00
|
|
|
free (new_f);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
strong_alias (_IO_old_fopen, __old_fopen)
|
2000-03-27 05:18:47 +00:00
|
|
|
compat_symbol (libc, _IO_old_fopen, _IO_fopen, GLIBC_2_0);
|
|
|
|
compat_symbol (libc, __old_fopen, fopen, GLIBC_2_0);
|
2000-03-21 23:09:29 +00:00
|
|
|
#endif
|