summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/cmd/ksh/builtins/alias.c9
-rw-r--r--usr/src/lib/libshell/Makefile.demo1
-rw-r--r--usr/src/lib/libshell/common/sh/macro.c2
-rw-r--r--usr/src/lib/libshell/common/tests/sun_solaris_cr_6807179_shellpattern_uses_getpwnam.sh89
-rw-r--r--usr/src/lib/libshell/misc/ERRATA.txt23
-rw-r--r--usr/src/pkgdefs/SUNWosdem/prototype_com1
6 files changed, 119 insertions, 6 deletions
diff --git a/usr/src/cmd/ksh/builtins/alias.c b/usr/src/cmd/ksh/builtins/alias.c
index 0e2a5623fe..b477d7353c 100644
--- a/usr/src/cmd/ksh/builtins/alias.c
+++ b/usr/src/cmd/ksh/builtins/alias.c
@@ -38,8 +38,7 @@
/* Builtin script, original derived from alias.sh */
static const char *script = "\n"
/* Get name of builtin */
-"builtin basename\n"
-"typeset cmd=\"$(basename \"$0\")\"\n"
+"typeset cmd=\"${0##*/}\"\n"
/*
* If the requested command is not an alias load it explicitly
* to make sure it is not bound to a path (those built-ins which
@@ -53,13 +52,13 @@ static const char *script = "\n"
*/
"if [[ \"${cmd}\" != ~(Elr)(alias|unalias|command) ]] && "
"! alias \"${cmd}\" >/dev/null 2>&1 ; then\n"
-" builtin \"${cmd}\"\n"
+ "builtin \"${cmd}\"\n"
"fi\n"
/* command is a keyword and needs to be handled separately */
"if [[ \"${cmd}\" == \"command\" ]] ; then\n"
-" command \"$@\"\n"
+ "command \"$@\"\n"
"else\n"
-" \"${cmd}\" \"$@\"\n"
+ "\"${cmd}\" \"$@\"\n"
"fi\n"
"exitval=$?";
diff --git a/usr/src/lib/libshell/Makefile.demo b/usr/src/lib/libshell/Makefile.demo
index f32a2c75b1..f59b5dd5a5 100644
--- a/usr/src/lib/libshell/Makefile.demo
+++ b/usr/src/lib/libshell/Makefile.demo
@@ -103,6 +103,7 @@ DEMOFILES= \
tests/sun_solaris_cr_6763594_command_failure_execs_twice.sh \
tests/sun_solaris_cr_6766246_pattern_matching_bug.sh \
tests/sun_solaris_cr_6800929_large_command_substitution_hang.sh \
+ tests/sun_solaris_cr_6807179_shellpattern_uses_getpwnam.sh \
tests/sun_solaris_getconf.sh \
tests/sun_solaris_local_compound_nameref001.sh \
tests/sun_solaris_staticvariables.sh \
diff --git a/usr/src/lib/libshell/common/sh/macro.c b/usr/src/lib/libshell/common/sh/macro.c
index 7b1ab77b48..cb938764d6 100644
--- a/usr/src/lib/libshell/common/sh/macro.c
+++ b/usr/src/lib/libshell/common/sh/macro.c
@@ -439,7 +439,7 @@ static void copyto(register Mac_t *mp,int endch, int newquote)
mp->sp = NIL(Sfio_t*);
mp->quote = newquote;
first = cp = fcseek(0);
- if(!mp->quote && *cp=='~')
+ if(!mp->quote && *cp=='~' && cp[1]!=LPAREN)
tilde = stktell(stkp);
/* handle // operator specially */
if(mp->pattern==2 && *cp=='/')
diff --git a/usr/src/lib/libshell/common/tests/sun_solaris_cr_6807179_shellpattern_uses_getpwnam.sh b/usr/src/lib/libshell/common/tests/sun_solaris_cr_6807179_shellpattern_uses_getpwnam.sh
new file mode 100644
index 0000000000..3e65edbfae
--- /dev/null
+++ b/usr/src/lib/libshell/common/tests/sun_solaris_cr_6807179_shellpattern_uses_getpwnam.sh
@@ -0,0 +1,89 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# This test checks whether ksh93 does unneccesaty |libc::getpwnam()|
+# calls for "~(modifer)pattern"-style shell patterns
+#
+# This was reported as CR #6807179 ("ksh93 does unneccesary |libc::getpwnam()| lookups for ~(modifier) pattern patterns"):
+# ------------ snip ------------
+# ksh93 does unneccesary |libc::getpwnam()| lookups for
+# ~(modifer)pattern patterns, e.g. [[ $foo == ~(E)hello.*world ]].
+# The problem is that the shell ~(modifer)pattern is an extended
+# pattern syntax which allows to specify a "modifer" to change
+# the behaviour for "pattern". However the '~' at the beginning
+# of this string is causing a tilde expansion (or better: It's
+# filling an internal buffer as preparation for tilde expansion
+# and this code calls |libc::getpwnam()|) which shouldn't be
+# done in this case.
+# [1]=For example the "modifer" allows to specifcy "perl",
+# "fgrep", "grep", "egrep", "POSIX shell", "korn shell" and
+# other types of pattern matching systems (or select stuff
+# like archors, case-insensitive matching etc. etc.).
+# ------------ snip ------------
+#
+
+# test setup
+function err_exit
+{
+ print -u2 -n "\t"
+ print -u2 -r ${Command}[$1]: "${@:2}"
+ (( Errors++ ))
+}
+alias err_exit='err_exit $LINENO'
+
+set -o nounset
+Command=${0##*/}
+integer Errors=0
+
+typeset tmpfile
+
+tmpfile="$(mktemp "/tmp/sun_solaris_cr_6807179_shellpattern_uses_getpwnam.${PPID}.$$.XXXXXX")" || err_exit "Cannot create temporary file."
+rm -f "${tmpfile}"
+
+
+# test 1: Check if the shell uses |libc::getpwnam()| for pattern "~(Elr)wo.*ld"
+truss -u :: -o "${tmpfile}" ${SHELL} -c '[[ ${hello} == ~(Elr)wo.*ld ]] ; true' || err_exit "truss returned failure=$?"
+[[ "$( < "${tmpfile}")" != *getpwnam* ]] || err_exit "truss log reports the use of getpwnam() for pattern ~(Elr)wo.*ld"
+rm "${tmpfile}" || err_exit "rm ${tmpfile} failed."
+
+
+# test 2: Check if the shell uses |libc::getpwnam()| for pattern "~(Si)wo*ld"
+truss -u :: -o "${tmpfile}" ${SHELL} -c '[[ ${hello} == ~(Si)wo*ld ]] ; true' || err_exit "truss returned failure=$?"
+[[ "$( < "${tmpfile}")" != *getpwnam* ]] || err_exit "truss log reports the use of getpwnam() for pattern ~(Si)wo*ld"
+rm "${tmpfile}" || err_exit "rm ${tmpfile} failed."
+
+
+# test 3: Same as test 1 but uses ~root/ as pattern which will force the use of |libc::getpwnam()|
+getent passwd root >/dev/null || err_exit "getent passwd root failed" # safeguard to make sure we get a warning if user root is missing
+
+truss -u :: -o "${tmpfile}" ${SHELL} -c '[[ ${hello} == ~root/ ]] ; true' || err_exit "truss returned failure=$?"
+[[ "$( < "${tmpfile}" )" == *getpwnam* ]] || err_exit "truss log reports the use of getpwnam() for pattern ~root/"
+rm "${tmpfile}" || err_exit "rm ${tmpfile} failed."
+
+
+# tests done
+exit $((Errors))
diff --git a/usr/src/lib/libshell/misc/ERRATA.txt b/usr/src/lib/libshell/misc/ERRATA.txt
index f14a66a950..23a8ef17c9 100644
--- a/usr/src/lib/libshell/misc/ERRATA.txt
+++ b/usr/src/lib/libshell/misc/ERRATA.txt
@@ -308,4 +308,27 @@ Index: src/lib/libshell/common/sh/xec.c
shp->outpipe = pvn;
pvo[1] = -1;
-- snip --
+
+
+######## Errata #005: ########
+A fix was backported for CR #6807179 to cure an unneccesary
+|libc::getpwnam()| lookup when the shell encountered a
+"~(modifer)pattern"-shell pattern (the leading '~' triggered a
+(unneccesary) tilde expansion).
+The following files have been changed:
+-- snip --
+--- src/lib/libshell/common/sh/macro.c Wed Feb 18 11:53:56 2009 +0800
++++ src/lib/libshell/common/sh/macro.c Wed Feb 18 21:45:00 2009 +0100
+@@ -439,7 +439,7 @@
+ mp->sp = NIL(Sfio_t*);
+ mp->quote = newquote;
+ first = cp = fcseek(0);
+- if(!mp->quote && *cp=='~')
++ if(!mp->quote && *cp=='~' && cp[1]!=LPAREN)
+ tilde = stktell(stkp);
+ /* handle // operator specially */
+ if(mp->pattern==2 && *cp=='/')
+
+-- snip --
+
#EOF.
diff --git a/usr/src/pkgdefs/SUNWosdem/prototype_com b/usr/src/pkgdefs/SUNWosdem/prototype_com
index 3623f4bc83..e6377962d2 100644
--- a/usr/src/pkgdefs/SUNWosdem/prototype_com
+++ b/usr/src/pkgdefs/SUNWosdem/prototype_com
@@ -134,6 +134,7 @@ f none usr/demo/ksh/tests/sun_solaris_cr_6754020_weird_square_bracket_expansion.
f none usr/demo/ksh/tests/sun_solaris_cr_6763594_command_failure_execs_twice.sh 644 root bin
f none usr/demo/ksh/tests/sun_solaris_cr_6766246_pattern_matching_bug.sh 644 root bin
f none usr/demo/ksh/tests/sun_solaris_cr_6800929_large_command_substitution_hang.sh 644 root bin
+f none usr/demo/ksh/tests/sun_solaris_cr_6807179_shellpattern_uses_getpwnam.sh 644 root bin
f none usr/demo/ksh/tests/sun_solaris_getconf.sh 644 root bin
f none usr/demo/ksh/tests/sun_solaris_local_compound_nameref001.sh 644 root bin
f none usr/demo/ksh/tests/sun_solaris_staticvariables.sh 644 root bin