From a08515735de79eda5994d15abfce3c0fee30a7f9 Mon Sep 17 00:00:00 2001 From: Thomas Bushnell Date: Thu, 5 Nov 1998 20:42:00 +0000 Subject: Thu Nov 5 15:26:50 1998 Thomas Bushnell, BSG * hashexec.c (check_hashbang): Keep INTERP_LEN with the correct value (bytes of memory holding INTERP) for later use. (check_hashbang: setup_args): Set argv[0] from the interpreter name, not copied from the existing command line. --- exec/ChangeLog | 7 +++++++ exec/hashexec.c | 31 +++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) (limited to 'exec') diff --git a/exec/ChangeLog b/exec/ChangeLog index e670493e..32f01fa0 100644 --- a/exec/ChangeLog +++ b/exec/ChangeLog @@ -1,3 +1,10 @@ +Thu Nov 5 15:26:50 1998 Thomas Bushnell, BSG + + * hashexec.c (check_hashbang): Keep INTERP_LEN with a the correct + value (bytes of memory holding INTERP) for later use. + (check_hashbang: setup_args): Set argv[0] from the interpreter + name, not copied from the existing command line. + 1998-07-15 Roland McGrath * exec.c (do_exec): Set boot->phdr_addr and boot->user_entry after diff --git a/exec/hashexec.c b/exec/hashexec.c index 61e743b6..e430b454 100644 --- a/exec/hashexec.c +++ b/exec/hashexec.c @@ -1,5 +1,5 @@ /* GNU Hurd standard exec server, #! script execution support. - Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. Written by Roland McGrath. This file is part of the GNU Hurd. @@ -166,6 +166,8 @@ check_hashbang (struct execdata *e, else ++len; /* Include the terminating null. */ + interp_len = strlen (interp) + 1; + user_crdir = user_cwdir = MACH_PORT_NULL; rwlock_reader_lock (&std_lock); @@ -298,12 +300,15 @@ check_hashbang (struct execdata *e, /* Prepare the arguments to pass to the interpreter from the original arguments and the name of the script file. The args will look - like `ARGV[0] {ARG} FILE_NAME ARGV[1..n]' (ARG might have been + like `INTERP {ARG} FILE_NAME ARGV[1..n]' (ARG might have been omitted). */ namelen = strlen (file_name) + 1; - new_argvlen = argvlen + len + namelen; + new_argvlen + = (argvlen - strlen (argv) - 1) /* existing args - old argv[0] */ + + interplen + len + namelen; /* New args */ + e->error = vm_allocate (mach_task_self (), (vm_address_t *) &new_argv, new_argvlen, 1); @@ -313,18 +318,28 @@ check_hashbang (struct execdata *e, if (! setjmp (args_faulted)) { char *other_args; - other_args = memccpy (new_argv, argv, '\0', argvlen); - p = &new_argv[other_args ? other_args - new_argv : argvlen]; + + p = new_argv; + + /* INTERP */ + memcpy (p, interp, interp_len); + p += interp_len; + + /* Maybe ARG */ if (arg) { memcpy (p, arg, len); p += len; } + + /* FILE_NAME */ memcpy (p, file_name, namelen); p += namelen; - if (other_args) - memcpy (p, other_args - new_argv + argv, - argvlen - (other_args - new_argv)); + + /* Maybe remaining args */ + other_args = argv + strlen (argv) + 1; + if (other_args - argv < argvlen) + memcpy (p, other_args, argvlen - (other_args - argv)); } else { -- cgit v1.2.3