aboutsummaryrefslogtreecommitdiff
path: root/elf/rtld.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1996-08-29 00:31:18 +0000
committerUlrich Drepper <drepper@redhat.com>1996-08-29 00:31:18 +0000
commit14bab8de31e04b990c2ce83d844f634ec57a6cc6 (patch)
treef6a25bd165f8997c08e58f6f2de69e9d34e0fda0 /elf/rtld.c
parentb236e99d90748f6caf77994e96dc5aaa48ce2993 (diff)
downloadglibc-14bab8de31e04b990c2ce83d844f634ec57a6cc6.zip
glibc-14bab8de31e04b990c2ce83d844f634ec57a6cc6.tar.gz
glibc-14bab8de31e04b990c2ce83d844f634ec57a6cc6.tar.bz2
update from main archive 960828glibc-1.93cvs/libc-960829cvs/libc-1-93
Thu Aug 29 00:28:08 1996 Ulrich Drepper <drepper@cygnus.com> * stdio-common/printf_fp.c (__printf_fp): Use default value `.` if `decimal' char is 0. * C-numeric.c (not_available): New constant. (_nl_C_LC_NUMERIC): Use `not_available' for grouping value. * nss/nsswitch.conf: Example configuration file. * nss/db-Makefile: Example Makefile for generation of databases for nss_db. * nss/Makefile (distribute): Add nsswitch.conf and db-Makefile. 1996-08-28 Paul Eggert <eggert@twinsun.com> * C-messages.c (_nl_C_LC_MESSAGES): Set yesexpr to "^[yY]" and noexpr to "^[nN]"; this conforms to POSIX.2. * C-time.c (_nl_C_LC_TIME): Change %d to %e in d_t_format, to conform to POSIX.2. 1996-08-28 Paul Eggert <eggert@twinsun.com> * C-monetary.c (not_available): New constant. (_nl_C_LC_MONETARY): Set mon_decimal_point to "", and set mon_grouping, int_frac_digits, frac_digits, p_cs_precedes, p_sep_by_space, n_cs_precedes, n_sep_by_space, p_sign_posn, and n_sign_posn to CHAR_MAX, as required by the POSIX Standard. Wed Aug 28 23:12:28 1996 Ulrich Drepper <drepper@cygnus.com> * nss/nss_db/db-XXX.c: Correct function names. They must be `_nss_db_*' instead of `_nss_files_*'. (lookup): `parse_line' returns 1 if succesful. * nss/nss_files/files-service.c (servbyname): Key for database must also contain protocol names. (servbypt): Likewise. Test must also check for protocol. Add `proto' argument. Tue Aug 27 09:56:13 1996 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * MakeTAGS ($P/subdirs.pot): Prefix all file names, not only the first one. Fri Aug 16 16:11:25 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> * nss/nss_dns/dns-host.c (_nss_dns_gethostbyname2_r): Treat EPFNOSUPPORT and EAFNOSUPPORT as implying NSS_STATUS_UNAVAIL just like ECONNREFUSED already does. (_nss_dns_gethostbyaddr_r): Likewise. * nss/nss_dns/dns-network.c (_nss_dns_getnetbyname_r): Likewise. (_nss_dns_getnetbyaddr_r): Likewise. * sysdeps/mach/hurd/socket.c (socket): For message transmission and RPC errors that indicate that the socket server is not really present and able to do its job, turn the error into EPFNOSUPPORT. * sysdeps/generic/sbrk.c (__sbrk): Get kernel brk address always only if in static libc or if statically linked program uses libc.so.
Diffstat (limited to 'elf/rtld.c')
-rw-r--r--elf/rtld.c115
1 files changed, 96 insertions, 19 deletions
diff --git a/elf/rtld.c b/elf/rtld.c
index 8b75492..0736218 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -38,6 +38,12 @@ extern ElfW(Addr) _dl_sysdep_start (void **start_argptr,
ElfW(Addr) *user_entry));
extern void _dl_sysdep_start_cleanup (void);
+/* System-dependent function to read a file's whole contents
+ in the most convenient manner available. */
+extern void *_dl_sysdep_read_whole_file (const char *filename,
+ size_t *filesize_ptr,
+ int mmap_prot);
+
int _dl_argc;
char **_dl_argv;
const char *_dl_rpath;
@@ -138,6 +144,8 @@ dl_main (const ElfW(Phdr) *phdr,
enum { normal, list, verify, trace } mode;
struct link_map **preloads;
unsigned int npreloads;
+ size_t file_size;
+ char *file;
mode = getenv ("LD_TRACE_LOADED_OBJECTS") != NULL ? trace : normal;
@@ -296,8 +304,77 @@ of this helper program; chances are you did not intend to run this program.\n",
l->l_next = &_dl_rtld_map;
_dl_rtld_map.l_prev = l;
+ /* We have two ways to specify objects to preload: via environment
+ variable and via the file /etc/ld.so.preload. The later can also
+ be used when security is enabled. */
preloads = NULL;
npreloads = 0;
+
+ /* Read the contents of the file. */
+ file = _dl_sysdep_read_whole_file ("/etc/ld.so.preload", &file_size,
+ PROT_READ | PROT_WRITE);
+ if (file)
+ {
+ /* Parse the file. It contains names of libraries to be loaded,
+ separated by white spaces or `:'. It may also contain
+ comments introduced by `#'. */
+ char *problem;
+ char *runp;
+ size_t rest;
+
+ /* Eliminate comments. */
+ runp = file;
+ rest = file_size;
+ while (rest > 0)
+ {
+ char *comment = memchr (runp, '#', rest);
+ if (comment == NULL)
+ break;
+
+ rest -= comment - runp;
+ do
+ *comment = ' ';
+ while (--rest > 0 && *++comment != '\n');
+ }
+
+ /* We have one problematic case: if we have a name at the end of
+ the file without a trailing terminating characters, we cannot
+ place the \0. Handle the case separately. */
+ if (file[file_size - 1] != ' ' && file[file_size] != '\t'
+ && file[file_size] != '\n')
+ {
+ problem = &file[file_size];
+ while (problem > file && problem[-1] != ' ' && problem[-1] != '\t'
+ && problem[-1] != '\n')
+ --problem;
+
+ if (problem > file)
+ problem[-1] = '\0';
+ }
+ else
+ problem = NULL;
+
+ if (file != problem)
+ {
+ char *p;
+ runp = file;
+ while ((p = strsep (&runp, ": \t\n")) != NULL)
+ {
+ (void) _dl_map_object (NULL, p, lt_library);
+ ++npreloads;
+ }
+ }
+
+ if (problem != NULL)
+ {
+ char *p = strndupa (problem, file_size - (problem - file));
+ (void) _dl_map_object (NULL, p, lt_library);
+ }
+
+ /* We don't need the file anymore. */
+ __munmap (file, file_size);
+ }
+
if (! __libc_enable_secure)
{
const char *preloadlist = getenv ("LD_PRELOAD");
@@ -313,25 +390,25 @@ of this helper program; chances are you did not intend to run this program.\n",
(void) _dl_map_object (NULL, p, lt_library);
++npreloads;
}
-
- if (npreloads != 0)
- {
- /* Set up PRELOADS with a vector of the preloaded libraries. */
- struct link_map *l;
- unsigned int i;
- preloads = __alloca (npreloads * sizeof preloads[0]);
- l = _dl_rtld_map.l_next; /* End of the chain before preloads. */
- i = 0;
- do
- {
- preloads[i++] = l;
- l = l->l_next;
- } while (l);
- assert (i == npreloads);
- }
}
}
+ if (npreloads != 0)
+ {
+ /* Set up PRELOADS with a vector of the preloaded libraries. */
+ struct link_map *l;
+ unsigned int i;
+ preloads = __alloca (npreloads * sizeof preloads[0]);
+ l = _dl_rtld_map.l_next; /* End of the chain before preloads. */
+ i = 0;
+ do
+ {
+ preloads[i++] = l;
+ l = l->l_next;
+ } while (l);
+ assert (i == npreloads);
+ }
+
/* Load all the libraries specified by DT_NEEDED entries. If LD_PRELOAD
specified some libraries to load, these are inserted before the actual
dependencies in the executable's searchlist for symbol resolution. */
@@ -386,7 +463,7 @@ of this helper program; chances are you did not intend to run this program.\n",
char buf[20], *bp;
buf[sizeof buf - 1] = '\0';
bp = _itoa (l->l_addr, &buf[sizeof buf - 1], 16, 0);
- while (&buf[sizeof buf - 1] - bp < sizeof l->l_addr * 2)
+ while ((size_t) (&buf[sizeof buf - 1] - bp) < sizeof l->l_addr * 2)
*--bp = '0';
_dl_sysdep_message ("\t", l->l_libname, " => ", l->l_name,
" (0x", bp, ")\n", NULL);
@@ -403,12 +480,12 @@ of this helper program; chances are you did not intend to run this program.\n",
char buf[20], *bp;
buf[sizeof buf - 1] = '\0';
bp = _itoa (ref->st_value, &buf[sizeof buf - 1], 16, 0);
- while (&buf[sizeof buf - 1] - bp < sizeof loadbase * 2)
+ while ((size_t) (&buf[sizeof buf - 1] - bp) < sizeof loadbase * 2)
*--bp = '0';
_dl_sysdep_message (_dl_argv[i], " found at 0x", bp, NULL);
buf[sizeof buf - 1] = '\0';
bp = _itoa (loadbase, &buf[sizeof buf - 1], 16, 0);
- while (&buf[sizeof buf - 1] - bp < sizeof loadbase * 2)
+ while ((size_t) (&buf[sizeof buf - 1] - bp) < sizeof loadbase * 2)
*--bp = '0';
_dl_sysdep_message (" in object at 0x", bp, "\n", NULL);
}