1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00
2001-03-19  Ulrich Drepper  <drepper@redhat.com>

	* elf/dl-dst.h (DL_DST_COUNT): Add __builtin_expect.

	* elf/dl-load.c (_dl_dst_count): Make DST recognition more robust.
	(_dl_dst_substitute): Likewise.
This commit is contained in:
Ulrich Drepper
2001-03-20 06:52:36 +00:00
parent 4a4d50f372
commit 2541eda0d4
3 changed files with 68 additions and 60 deletions

View File

@ -1,3 +1,10 @@
2001-03-19 Ulrich Drepper <drepper@redhat.com>
* elf/dl-dst.h (DL_DST_COUNT): Add __builtin_expect.
* elf/dl-load.c (_dl_dst_count): Make DST recognition more robust.
(_dl_dst_substitute): Likewise.
2001-03-17 Bruno Haible <haible@clisp.cons.org> 2001-03-17 Bruno Haible <haible@clisp.cons.org>
* intl/loadmsgcat.c (_nl_load_domain) [!_LIBC]: Use fstat, not fstat64. * intl/loadmsgcat.c (_nl_load_domain) [!_LIBC]: Use fstat, not fstat64.

View File

@ -1,5 +1,5 @@
/* Handling of dynamic sring tokens. /* Handling of dynamic sring tokens.
Copyright (C) 1999 Free Software Foundation, Inc. Copyright (C) 1999, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or The GNU C Library is free software; you can redistribute it and/or
@ -24,7 +24,7 @@
size_t __cnt = 0; \ size_t __cnt = 0; \
const char *__sf = strchr (name, '$'); \ const char *__sf = strchr (name, '$'); \
\ \
if (__sf != NULL) \ if (__builtin_expect (__sf != NULL, 0)) \
__cnt = _dl_dst_count (__sf, is_path); \ __cnt = _dl_dst_count (__sf, is_path); \
\ \
__cnt; }) __cnt; })

View File

@ -180,26 +180,28 @@ _dl_dst_count (const char *name, int is_path)
{ {
size_t len = 1; size_t len = 1;
/* $ORIGIN is not expanded for SUID/GUID programs. /* $ORIGIN is not expanded for SUID/GUID programs and it must
always appear first in path.
Note that it is no bug that the strings in the first two `strncmp' Note that it is no bug that the string in the second and
calls are longer than the sequence which is actually tested. */ fourth `strncmp' call is longer than the sequence which is
if ((((strncmp (&name[1], "ORIGIN}", 6) == 0 actually tested. */
&& (!__libc_enable_secure if (((strncmp (&name[1], "{ORIGIN}", 8) == 0 && (len = 9) != 0)
|| ((name[7] == '\0' || (is_path && name[7] == ':')) || (strncmp (&name[1], "{ORIGIN}" + 1, 6) == 0
&& (name == start || (is_path && name[-1] == ':')))) && (name[7] == '\0' || name[7] == '/'
&& (len = 7) != 0) || (is_path && name[7] == ':'))
|| (strncmp (&name[1], "PLATFORM}", 8) == 0 && (len = 9) != 0)) && (len = 7) != 0)))
&& (name[len] == '\0' || name[len] == '/' {
|| (is_path && name[len] == ':'))) if (__builtin_expect (!__libc_enable_secure, 1)
|| (name[1] == '{' && (name == start || (is_path && name[-1] == ':')))
&& ((strncmp (&name[2], "ORIGIN}", 7) == 0 ++cnt;
&& (!__libc_enable_secure }
|| ((name[9] == '\0' || (is_path && name[9] == ':')) else if ((strncmp (&name[1], "{PLATFORM}", 10) == 0
&& (name == start || (is_path && name[-1] == ':')))) && (len = 11) != 0)
&& (len = 9) != 0) || (strncmp (&name[1], "{PLATFORM}" + 1, 8) == 0
|| (strncmp (&name[2], "PLATFORM}", 9) == 0 && (name[9] == '\0' || name[9] == '/'
&& (len = 11) != 0)))) || (is_path && name[9] == ':'))
&& (len = 9) != 0))
++cnt; ++cnt;
name = strchr (name + len, '$'); name = strchr (name + len, '$');
@ -225,57 +227,56 @@ _dl_dst_substitute (struct link_map *l, const char *name, char *result,
do do
{ {
if (*name == '$') if (__builtin_expect (*name, 'a') == '$')
{ {
const char *repl; const char *repl = NULL;
size_t len; size_t len = 1;
/* Note that it is no bug that the strings in the first two `strncmp' /* Note that it is no bug that the string in the second and
calls are longer than the sequence which is actually tested. */ fourth `strncmp' call is longer than the sequence which
if ((((strncmp (&name[1], "ORIGIN}", 6) == 0 && (len = 7) != 0) is actually tested. */
|| (strncmp (&name[1], "PLATFORM}", 8) == 0 && (len = 9) != 0)) if (((strncmp (&name[1], "{ORIGIN}", 8) == 0 && (len = 9) != 0)
&& (name[len] == '\0' || name[len] == '/' || (strncmp (&name[1], "{ORIGIN}" + 1, 6) == 0
|| (is_path && name[len] == ':'))) && (name[7] == '\0' || name[7] == '/'
|| (name[1] == '{' || (is_path && name[7] == ':'))
&& ((strncmp (&name[2], "ORIGIN}", 7) == 0 && (len = 9) != 0) && (len = 7) != 0)))
|| (strncmp (&name[2], "PLATFORM}", 9) == 0
&& (len = 11) != 0))))
{ {
repl = ((len == 7 || name[2] == 'O') if (__builtin_expect (!__libc_enable_secure, 1)
? (__libc_enable_secure && (name == start || (is_path && name[-1] == ':')))
&& ((name[len] != '\0' repl = l->l_origin;
&& (!is_path || name[len] != ':')) }
|| (name != start else if ((strncmp (&name[1], "{PLATFORM}", 10) == 0
&& (!is_path || name[-1] != ':'))) && (len = 11) != 0)
? NULL : l->l_origin) || (strncmp (&name[1], "{PLATFORM}" + 1, 8) == 0
: _dl_platform); && (name[9] == '\0' || name[9] == '/' || name[9] == ':')
&& (len = 9) != 0))
repl = _dl_platform;
if (repl != NULL && repl != (const char *) -1)
{ if (repl != NULL && repl != (const char *) -1)
wp = __stpcpy (wp, repl); {
name += len; wp = __stpcpy (wp, repl);
} name += len;
else }
{ else if (len > 1)
/* We cannot use this path element, the value of the {
replacement is unknown. */ /* We cannot use this path element, the value of the
wp = last_elem; replacement is unknown. */
name += len; wp = last_elem;
while (*name != '\0' && (!is_path || *name != ':')) name += len;
++name; while (*name != '\0' && (!is_path || *name != ':'))
} ++name;
} }
else else
/* No DST we recognize. */ /* No DST we recognize. */
*wp++ = *name++; *wp++ = *name++;
} }
else if (is_path && *name == ':') else
{ {
*wp++ = *name++; *wp++ = *name++;
last_elem = wp; if (is_path && *name == ':')
last_elem = wp;
} }
else
*wp++ = *name++;
} }
while (*name != '\0'); while (*name != '\0');