7024876 Harden shell scripts in X
authorAlan Coopersmith <Alan.Coopersmith@Oracle.COM>
Thu, 30 Jun 2011 16:38:19 -0700
changeset 1155 4ef9f4d0b8de
parent 1154 941fbafb8c39
child 1156 973b7daad782
7024876 Harden shell scripts in X
open-src/app/xmakemap/sun-src/xmakemap
open-src/data/ogl-select/ogl-select
open-src/xserver/xserver-common/x11-server
--- a/open-src/app/xmakemap/sun-src/xmakemap	Wed Jun 29 16:04:11 2011 -0700
+++ b/open-src/app/xmakemap/sun-src/xmakemap	Thu Jun 30 16:38:19 2011 -0700
@@ -1,6 +1,6 @@
 #! /bin/sh
 #
-# Copyright (c) 1992, 1995, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 1992, 2011, Oracle and/or its affiliates. All rights reserved.
 #
 # Permission is hereby granted, free of charge, to any person obtaining a
 # copy of this software and associated documentation files (the "Software"),
@@ -28,11 +28,13 @@
 # Usage: xmakemap > $HOME/.xmodmaprc
 #
 # Notes:
-#    OpenWindows (i.e., an X server) must be running to use xmakemap.
+#    An X server must be running to use xmakemap.
 #    Run xmakemap and edit $HOME/.xmodmaprc to customize it as desired
 #    (read "Notes" in $HOME/.xmodmaprc).
 #
 
+PATH=/usr/bin ; export PATH
+
 echo '! File:
 !    .xmodmaprc
 !
@@ -46,7 +48,7 @@
 !    xmodmap $HOME/.xmodmaprc
 !
 ! Notes:
-!  - If you would like your keytable to be customized each time OW
+!  - If you would like your keytable to be customized each time X
 !    is run, you should place the appropriate command in $HOME/.xinitrc.
 !    For example:
 !
--- a/open-src/data/ogl-select/ogl-select	Wed Jun 29 16:04:11 2011 -0700
+++ b/open-src/data/ogl-select/ogl-select	Thu Jun 30 16:38:19 2011 -0700
@@ -1,6 +1,6 @@
 #!/bin/ksh93
 #
-# Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
 #
 # Permission is hereby granted, free of charge, to any person obtaining a
 # copy of this software and associated documentation files (the "Software"),
@@ -23,12 +23,12 @@
 #
 #
 
+PATH=/usr/bin:/usr/sbin
+
 . /lib/svc/share/smf_include.sh
 
 USAGE="Usage: $0 <method>"
 
-PATH=/usr/bin:/usr/sbin
-
 DRIVER=""
 OGL_SELECT_DIR=/lib/opengl/ogl_select
 
@@ -100,14 +100,13 @@
 # Get the driver attached to the console
 DRIVER="$(/usr/bin/constype)"
 
-REGISTRY=/tmp/ogl_select$$
-if [[ -e ${REGISTRY} ]]; then
-	rm -f ${REGISTRY}
+REGISTRY="$(mktemp /tmp/ogl_select.XXXXXX)"
+if [[ -z "${REGISTRY}" ]]; then
+    print -u2 "$0: Can't create temporary file"
+    exit $SMF_EXIT_ERR_FATAL
 fi
-touch ${REGISTRY}
 
-for x in ${OGL_SELECT_DIR}/*_vendor_select
-do
+for x in ${OGL_SELECT_DIR}/*_vendor_select ; do
 	if [[ -x "$x" ]]; then
 		($x identify >> ${REGISTRY})
 	fi
@@ -129,10 +128,12 @@
 # Build vendor script name
 SELECT_SCRIPT="${OGL_SELECT_DIR}/${VENDOR}_vendor_select"
 if [[ ! -x "${SELECT_SCRIPT}" ]]; then
-        print $0 "Can't execute vendor select script:" $SELECT_SCRIPT
+        print -u2 "$0: Can't execute vendor select script:" $SELECT_SCRIPT
         exit $SMF_EXIT_ERR_FATAL
 fi
 
 ($SELECT_SCRIPT)
 
+rm -f "${REGISTRY}"
+
 exit $SMF_ERR_OK
--- a/open-src/xserver/xserver-common/x11-server	Wed Jun 29 16:04:11 2011 -0700
+++ b/open-src/xserver/xserver-common/x11-server	Thu Jun 30 16:38:19 2011 -0700
@@ -1,6 +1,6 @@
-#!/bin/ksh
+#!/bin/ksh93
 #
-# Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
 #
 # Permission is hereby granted, free of charge, to any person obtaining a
 # copy of this software and associated documentation files (the "Software"),
@@ -24,7 +24,7 @@
 
 USAGE="Usage: $0 [-d <display>] [-c <class>] <method> [-- <X server arguments>]"
 
-PATH=/usr/bin:/usr/sbin:/usr/openwin/bin:/usr/X11/bin
+PATH=/usr/bin:/usr/sbin
 
 #########
 #
@@ -38,7 +38,7 @@
 
 while getopts c:d: opt; do
     case $opt in
-	c)	if [ "$OPTARG" != "default" ] ; then
+	c)	if [[ "$OPTARG" != "default" ]] ; then
 		    CLASSES="$CLASSES -c $OPTARG"
 		fi ;;
 	d)	DISPLAY="$OPTARG";;
@@ -49,8 +49,8 @@
 shift `expr $OPTIND - 1`
 
 METHOD=$1
-if [ $# -lt 1 ] ; then
-    echo $USAGE
+if [[ $# -lt 1 ]] ; then
+    print -u2 $USAGE
     exit 2
 fi
 shift
@@ -65,10 +65,10 @@
 	;;
 esac
 
-if [ "$1" = "--" ] ; then
+if [[ "$1" = "--" ]] ; then
     shift
 else
-    if [ "$1" != "" ] ; then
+    if [[ "$1" != "" ]] ; then
 	echo $USAGE
 	exit 2
     fi