summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@gnu.org>2000-08-01 20:34:41 +0000
committerMark Kettenis <kettenis@gnu.org>2000-08-01 20:34:41 +0000
commit555be45444c5fd082580a1cd7bd695905e627717 (patch)
treef51a28102b09f355fdf919dd34bcde86091ab5cc
parent91856709da3e84e2d2b3addcb24815ba88f11cd7 (diff)
downloadglibc-555be45444c5fd082580a1cd7bd695905e627717.tar.gz
* sysdeps/mach/hurd/dl-sysdep.c (_dl_sysdep_start): Take into
acount that elf/rtld's main program might remove some varibales from the environment if we're trying to be secure. Move the Hurd startup data if necessary, or, if we there is no startup data, make sure the magical convention that ARGV[0] is stored just after the environment list.
-rw-r--r--ChangeLog9
-rw-r--r--sysdeps/mach/hurd/dl-sysdep.c49
2 files changed, 48 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 0ab4e3414e..1214922ed9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2000-07-29 Mark Kettenis <kettenis@gnu.org>
+
+ * sysdeps/mach/hurd/dl-sysdep.c (_dl_sysdep_start): Take into
+ acount that elf/rtld's main program might remove some varibales
+ from the environment if we're trying to be secure. Move the Hurd
+ startup data if necessary, or, if we there is no startup data,
+ make sure the magical convention that ARGV[0] is stored just after
+ the environment list.
+
2000-06-01 Ulrich Drepper <drepper@redhat.com>
* sysdeps/i386/elf/setjmp.S: Work around change is recent
diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c
index c79c388b9f..5d084bb97a 100644
--- a/sysdeps/mach/hurd/dl-sysdep.c
+++ b/sysdeps/mach/hurd/dl-sysdep.c
@@ -1,5 +1,5 @@
/* Operating system support for run-time dynamic linker. Hurd version.
- Copyright (C) 1995, 96, 97, 98, 99 Free Software Foundation, Inc.
+ Copyright (C) 1995, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -184,16 +184,45 @@ unfmh(); /* XXX */
_dl_hurd_data->phdrsz / sizeof (Elf32_Phdr),
&_dl_hurd_data->user_entry);
- if (_dl_skip_args && _dl_argv[-_dl_skip_args] == (char *) p)
+ /* The call above might screw a few things up.
+
+ First of all, if _dl_skip_args is nonzero, we are ignoring
+ the first few arguments. However, if we have no Hurd startup
+ data, it is the magical convention that ARGV[0] == P. The
+ startup code in init-first.c will get confused if this is not
+ the case, so we must rearrange things to make it so. We'll
+ overwrite the origional ARGV[0] at P with ARGV[_dl_skip_args].
+
+ Secondly, if we need to be secure, it removes some dangerous
+ environment variables. If we have no Hurd startup date this
+ changes P (since that's the location after the terminating
+ NULL in the list of environment variables). We do the same
+ thing as in the first case but make sure we recalculate P.
+ If we do have Hurd startup data, we have to move the data
+ such that it starts just after the terminating NULL in the
+ environment list.
+
+ We use memmove, since the locations might overlap. */
+ if (__libc_enable_secure || _dl_skip_args)
{
- /* We are ignoring the first few arguments, but we have no Hurd
- startup data. It is magical convention that ARGV[0] == P in
- this case. The startup code in init-first.c will get confused
- if this is not the case, so we must rearrange things to make
- it so. Overwrite the original ARGV[0] at P with
- ARGV[_dl_skip_args]. */
- assert ((char *) p < _dl_argv[0]);
- _dl_argv[0] = strcpy ((char *) p, _dl_argv[0]);
+ char **newp;
+
+ for (newp = _environ; *newp++;);
+
+ if (_dl_argv[-_dl_skip_args] == (char *) p)
+ {
+ if ((char *) newp != _dl_argv[0])
+ {
+ assert ((char *) newp < _dl_argv[0]);
+ _dl_argv[0] = memmove ((char *) newp, _dl_argv[0],
+ strlen (_dl_argv[0]) + 1);
+ }
+ }
+ else
+ {
+ if ((void *) newp != _dl_hurd_data)
+ memmove (newp, _dl_hurd_data, sizeof (*_dl_hurd_data));
+ }
}
{