1# 2# CDDL HEADER START 3# 4# The contents of this file are subject to the terms of the 5# Common Development and Distribution License (the "License"). 6# You may not use this file except in compliance with the License. 7# 8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9# or http://www.opensolaris.org/os/licensing. 10# See the License for the specific language governing permissions 11# and limitations under the License. 12# 13# When distributing Covered Code, include this CDDL HEADER in each 14# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15# If applicable, add the following below this CDDL HEADER, with the 16# fields enclosed by brackets "[]" replaced with your own identifying 17# information: Portions Copyright [yyyy] [name of copyright owner] 18# 19# CDDL HEADER END 20# 21 22# 23# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 24# 25 26# 27# This test checks whether ksh93 does not execute builtin command 28# "foo" when referencing variable "foo" when the variable is not 29# set (this applies to all builtin commands not bound to a 30# specific PATH element, e.g. "test", "sleep", "print" etc.). 31# 32# This was reported as CR #6848486 ('"echo ${test}" with test 33# undefined crashes the shell') 34# ------------ snip ------------ 35# This is an odd one: 36# 37# $ ksh93 --version 38# version sh (AT&T Research) 93t 2008-11-04 39# $ ksh93 40# jl138328@gir:~$ echo $test 41# 42# jl138328@gir:~$ echo ${test} 43# Segmentation Fault (core dumped) 44# ------------ snip ------------ 45# 46# The bug originates from the ksh93 "type system" which allows 47# an application to define it's own types in ksh93. In such cases 48# the output of function "mytype.len" is used when type "mytype" 49# has no member variable "len" (note it requires the use of 50# ${foo} since the use of $foo does not allow "foo" to contain 51# a dot in the variable name). 52# The implementation in ast-ksh.2009-11-04 however does this 53# for _all_ types of variables and not only for those which 54# are a member of an application-defined type, therefore 55# causing this bug. 56# 57 58# test setup 59function err_exit 60{ 61 print -u2 -n "\t" 62 print -u2 -r ${Command}[$1]: "${@:2}" 63 (( Errors < 127 && Errors++ )) 64} 65alias err_exit='err_exit $LINENO' 66 67set -o nounset 68Command=${0##*/} 69integer Errors=0 70 71 72# Test 1: Test whether the shell crashes when looking for an empty 73# "shell" variable. 74# (note: return code 78 was just picked randomly) 75$SHELL -c 'unset test ; print ${test} ; exit 78' >/dev/null 2>&1 76(( $? == 78 )) || err_exit "expected return code is 78, got $?" 77 78 79# Test 2: Test whether the shell can reach a point (which prints 80# "#mark") after the use of ${test} in the script. 81out=$($SHELL -o errexit -c 'unset test ; print ${test} ; print "#mark"' 2>&1 ) || err_exit "Shell returned error code $?, expected 0." 82[[ "$out" == $'\n#mark' ]] || err_exit "Expected output \$'\n#mark', got '${out}'" 83 84 85# Test 3: Check whether the use of ${sleep} returns nothing 86# (ast-ksh.2008-11-04 will return the usage string of the sleep 87# builtin) 88out=$($SHELL -o errexit -c 'print ${sleep} ; print "#mark"' 2>&1 ) || err_exit "Shell returned error code $?, expected 0." 89[[ "$out" == $'\n#mark' ]] || err_exit "Expected output \$'\n#mark', got '${out}'" 90 91 92# tests done 93exit $((Errors)) 94