Skip to content

Commit 159fb9e

Browse files
committed
main.c: Tweak fixargs() (re: cefe087)
src/cmd/ksh93/sh/main.c: fixargs(): - Erase the entire length of the command arguments buffer (the space from argv[0] until environ[0]) so that remnants of longer command arguments aren't left in 'ps' output when executing a hashbang-ess script with a shorter command line. - Disable fixargs() on FreeBSD. It has never had any effect on that system; apparently it either requires another method to rewrite arguments for 'ps' output purposes (which?) or it's not possible. src/cmd/ksh93/tests/basic.sh: - Skip the test if running on FreeBSD.
1 parent e720283 commit 159fb9e

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

‎src/cmd/ksh93/sh/main.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
/* These routines are referenced by this module */
5353
static void exfile(Shell_t*, Sfio_t*,int);
5454
static void chkmail(Shell_t *shp, char*);
55-
#if defined(_lib_fork) && !defined(_NEXT_SOURCE)
55+
#if defined(_lib_fork) && !defined(_NEXT_SOURCE) && !defined(__FreeBSD__)
5656
static void fixargs(char**,int);
5757
#else
5858
# define fixargs(a,b)
@@ -697,7 +697,7 @@ static void chkmail(Shell_t *shp, char *files)
697697
# define PSTAT 1
698698
#endif
699699

700-
#if defined(_lib_fork) && !defined(_NEXT_SOURCE)
700+
#if defined(_lib_fork) && !defined(_NEXT_SOURCE) && !defined(__FreeBSD__)
701701
/*
702702
* fix up command line for ps command
703703
*
@@ -735,9 +735,7 @@ static void fixargs(char **argv, int mode)
735735
if(mode==0)
736736
{
737737
buff = argv[0];
738-
while(cp = *argv++)
739-
command_len += strlen(cp)+1;
740-
command_len -= 1;
738+
command_len = environ[0] - buff - 1;
741739
return;
742740
}
743741
# endif /* PSTAT */

‎src/cmd/ksh93/tests/basic.sh‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,8 @@ getPsOutput() {
708708
while [[ $actual == [[:space:]]* ]]; do actual=${actual#?}; done
709709
while [[ $actual == *[[:space:]] ]]; do actual=${actual%?}; done
710710
}
711-
if getPsOutput "$$"
711+
if [[ $(uname -s) != FreeBSD ]] &&
712+
getPsOutput "$$" &&
712713
[[ "$SHELL $0" == "$actual"* ]] # "$SHELL $0" is how shtests invokes this script
713714
then expect='./atest 1 2'
714715
echo 'sleep 10; exit 0' >atest
@@ -718,8 +719,6 @@ then expect='./atest 1 2'
718719
kill "$!"
719720
[[ $actual == "$expect" ]] || err_exit "ksh didn't rewrite argv correctly" \
720721
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
721-
else err_exit "warning: skipping argv rewrite test due to noncompliant 'ps' utility (got $(printf %q "$actual"))"
722-
let Errors--
723722
fi
724723
unset -f getPsOutput
725724

0 commit comments

Comments
 (0)