2023-01-07 05:08:04 +08:00
|
|
|
/* Copyright (C) 1993-2023 Free Software Foundation, Inc.
|
2001-07-06 12:58:11 +08:00
|
|
|
This file is part of the GNU C Library.
|
1997-10-13 09:27:24 +08:00
|
|
|
|
2001-07-06 12:58:11 +08: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 09:27:24 +08:00
|
|
|
|
2001-07-06 12:58:11 +08: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 09:27:24 +08:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 12:58:11 +08:00
|
|
|
Lesser General Public License for more details.
|
1997-10-13 09:27:24 +08:00
|
|
|
|
2001-07-06 12:58:11 +08:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-10 07:18:22 +08:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 13:40:42 +08:00
|
|
|
<https://www.gnu.org/licenses/>.
|
1997-10-13 09:27:24 +08:00
|
|
|
|
2001-07-06 12:58:11 +08: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 09:27:24 +08:00
|
|
|
|
2000-03-22 07:09:29 +08:00
|
|
|
#include <shlib-compat.h>
|
2000-03-22 16:01:35 +08:00
|
|
|
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
|
2000-03-22 07:09:29 +08:00
|
|
|
|
1997-12-15 06:24:57 +08:00
|
|
|
#define _IO_USE_OLD_IO_FILE
|
1997-10-13 09:27:24 +08:00
|
|
|
#include "libioP.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
2018-02-08 07:42:04 +08:00
|
|
|
FILE *
|
2004-03-10 17:29:17 +08:00
|
|
|
attribute_compat_text_section
|
2015-10-17 04:21:49 +08:00
|
|
|
_IO_old_fopen (const char *filename, const char *mode)
|
1997-10-13 09:27:24 +08:00
|
|
|
{
|
|
|
|
struct locked_FILE
|
|
|
|
{
|
2003-11-04 17:58:57 +08:00
|
|
|
struct _IO_FILE_complete_plus fp;
|
1997-10-13 09:27:24 +08: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 17:58:57 +08:00
|
|
|
new_f->fp.file._file._lock = &new_f->lock;
|
1997-10-13 09:27:24 +08:00
|
|
|
#endif
|
2003-11-04 17:58:57 +08:00
|
|
|
_IO_old_init (&new_f->fp.file._file, 0);
|
2015-05-18 19:58:54 +08: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-24 02:01:40 +08:00
|
|
|
_IO_old_file_init_internal ((struct _IO_FILE_plus *) &new_f->fp);
|
2018-02-08 07:42:04 +08:00
|
|
|
if (_IO_old_file_fopen ((FILE *) &new_f->fp, filename, mode) != NULL)
|
|
|
|
return (FILE *) &new_f->fp;
|
2012-05-23 19:33:15 +08:00
|
|
|
_IO_un_link ((struct _IO_FILE_plus *) &new_f->fp);
|
1997-10-13 09:27:24 +08:00
|
|
|
free (new_f);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
strong_alias (_IO_old_fopen, __old_fopen)
|
2000-03-27 13:18:47 +08:00
|
|
|
compat_symbol (libc, _IO_old_fopen, _IO_fopen, GLIBC_2_0);
|
|
|
|
compat_symbol (libc, __old_fopen, fopen, GLIBC_2_0);
|
2000-03-22 07:09:29 +08:00
|
|
|
#endif
|