-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Reproducer script: IFS=$'\t\t' val=$'\tone\t\ttwo\tthree\t' set -o posix; set $val; print -n $# set +o posix; set $val; print -n $# set -o posix; set $val; print -n $# set +o posix; set $val; print $# The output is normally correct but is wrong when xtrace is on: $ arch/darwin.arm64-64/bin/ksh test6.sh 3535 $ arch/darwin.arm64-64/bin/ksh -x test6.sh 2>/dev/null 5353 Analysis: In sh_argopts() in args.c, whenever we're going to change the posix (SH_POSIX) option, sh_invalidate_ifs() is called to trigger a regeneration of the IFS state table (in get_ifs(), init.c); this is necessary to enable or disable the effect of the doubled-up whitespace character. The 'set' command is then traced with a sh_trace() call before the new options take effect. The trace involves expanding PS4, which involes reading IFS, which causes get_ifs() to regenerate the IFS state table before the posix option change takes effect. src/cmd/ksh93/sh/args.c: sh_argopts(): - Instead of calling sh_invalidate_ifs() immediately, remember the need to call it in a flag variable. - Use that flag to delay the actual sh_invalidate_ifs() call until after sh_trace() has been called. Re-reading the sh_invalidate_ifs() function caused me to realise that this function has a bug, too. For np pointing to IFS, it assumes that the IFS discipline IFS_disc is pointed to by np->nvfun. This is not correct if another discipline is added to it, e.g. by defining an IFS.get() shell discipline function. Doing that causes an invalid read in sh_invalidate_ifs() and incorrect behaviour. src/cmd/ksh93/sh/init.c: sh_invalidate_ifs(): - Move the function to after the IFS_disc declaration. - Use nv_hasdisc() (nvdisc.c) to find the pointer to IFS_disc starting from np->nvfun, which is a linked list. src/cmd/ksh93/tests/posix.sh: - Set a dummy IFS.get() to test the above fix.
- Loading branch information
Showing
5 changed files
with
30 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters