diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2004-02-23 20:47:40 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2004-02-23 20:47:40 +0000 |
commit | c1ecfaeb24fab9bbb95082794e7ab1a1989d41e7 (patch) | |
tree | 904f3b0e31a0fbbb9da800101b7ce5800a58d93e /libexec | |
parent | e1d553c77d0696c87302c5d1659dca3cae8971b2 (diff) |
Set the user variable environ early in ld.so so that library constructors can
properly see the environment. Fixes problem with MALLOC_OPTIONS on dynamic
executables. ok deraadt@
Diffstat (limited to 'libexec')
-rw-r--r-- | libexec/ld.so/loader.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/libexec/ld.so/loader.c b/libexec/ld.so/loader.c index 1b886448504..88e20cf13e2 100644 --- a/libexec/ld.so/loader.c +++ b/libexec/ld.so/loader.c @@ -1,4 +1,4 @@ -/* $OpenBSD: loader.c,v 1.72 2004/02/10 14:12:22 drahn Exp $ */ +/* $OpenBSD: loader.c,v 1.73 2004/02/23 20:47:39 drahn Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -54,6 +54,7 @@ void _dl_debug_state(void); void _dl_setup_env(char **); void _dl_dtors(void); void _dl_boot_bind(const long, long *, Elf_Dyn *); +void _dl_fixup_user_env(void); const char *_dl_progname; int _dl_pagesz; @@ -129,6 +130,7 @@ _dl_dopreload(char *paths) * grab interesting environment variables, zap bad env vars if * issetugid */ +char **_dl_so_envp; void _dl_setup_env(char **envp) { @@ -168,6 +170,7 @@ _dl_setup_env(char **envp) _dl_unsetenv("LD_NORANDOM", envp); } } + _dl_so_envp = envp; } /* @@ -334,6 +337,9 @@ _dl_boot(const char **argv, char **envp, const long loff, long *dl_data) _dl_add_object(dyn_obj); dyn_obj->status |= STAT_RELOC_DONE; + if (_dl_traceld == NULL) + _dl_fixup_user_env(); + /* * Everything should be in place now for doing the relocation * and binding. Call _dl_rtld to do the job. Fingers crossed. @@ -709,3 +715,26 @@ _dl_unsetenv(const char *var, char **env) env++; } } + +/* + * _dl_fixup_user_env() + * + * Set the user environment so that programs can use the environment + * while running constructors. Specifically, MALLOC_OPTIONS= for malloc() + */ +void +_dl_fixup_user_env(void) +{ + const Elf_Sym *sym; + Elf_Addr ooff; + struct elf_object dummy_obj; + + dummy_obj.dyn.symbolic = 0; + dummy_obj.load_name = "ld.so"; + + sym = NULL; + ooff = _dl_find_symbol("environ", _dl_objects, &sym, + SYM_SEARCH_ALL|SYM_NOWARNNOTFOUND|SYM_PLT, 0, &dummy_obj); + if (sym != NULL) + *((char ***)(sym->st_value + ooff)) = _dl_so_envp; +} |