Patch Name: PHCO_20018 Patch Description: s700_800 10.20 ksh(1) cumulative patch Creation Date: 99/10/20 Post Date: 99/10/29 Repost: 01/09/30 The patch documentation was modified to remove references to here-document related defects that are not fully addressed. The defects described in Service Request 1653182162 (DSDe430660) and 1653264812 (DSDe443517) are not fully addressed in the patch so references to these defect fixes were removed from the patch documentation. Hardware Platforms - OS Releases: s700: 10.20 s800: 10.20 Products: N/A Filesets: OS-Core.UX-CORE OS-Core.CORE-ENG-A-MAN Automatic Reboot?: No Status: General Superseded Critical: No Path Name: /hp-ux_patches/s700_800/10.X/PHCO_20018 Symptoms: PHCO_20018: 1. ksh(1) manpage does not have information about history file trimming. 2. ksh(1) getopts OPTARG is trashed. 3. ksh(1) fails to login when the history file is >4k and older than 10 min. 4. ksh(1) coredump with history in heterogenous environment. 5. ksh: read not interrupted by a SIGINT. Works fine with MR ksh. 6. After trapping SIGHUP, ksh exits. 7. ksh does not trap SIGHUP if received within a function. PHCO_17691: ksh(1) coredumps with script using many heredocs. PHCO_16363: 1. A return statement in a do-while loop inside a function exits only the do-while loop, not the function. PHCO_16065: 2. ksh does not handle command substitution of variables of length 2047, 3071, etc. correctly. When a variable is assigned a string of length equal to 2047/3071/..., the result of command substitution using this variable retains only the last 1023 bytes of the variable. PHCO_15648: 10.20 ksh subshell exits prematurely on a uniprocessor. When ksh is executed from a script on a uniprocessor, the shell exits by itself, without the user typing an explicit . PHCO_13698: 1) ksh dies after sourcing . ./script using while loop and command redirect. Scripts like the following, when sourced cause the shell to exit. echo test | while read r do a=$(date) done 2) POSIX and Korn shell do not wait(2) for zombies while in vi input mode PHCO_13655: Problem with set -e in ksh: When set -e is on, ksh does not exit on encountering error while expanding the word list in a for statement. This happens even in a case statement and a pipe list. PHCO_11347: 1) Korn shell does not source a script if stderr is closed. $cat prog . sprog $cat sprog echo hello $prog 2>&- <--- does not source 'sprog' $ 2) trap DEBUG does not behave consistently with command substitution. 3) Shell builtin ':' (: > file) does not truncate file when called second time from a function. 4) Korh shell dumps core due to memory fault when function is defined in a loop. 5) Korn shell adds character when parsing input for trap action name $cat prog #!/usr/bin/ksh trap $1 EXIT echo t (d ) $./prog ate prog[2]: syntax error at line 3 : `(' unexpected Fri Jun 13 18:01:14 IST 1997 <-- 'd' from line 3 is added to action name 'ate' PHCO_11010: 1) Korn shell dumps core during command substitution if standard input is closed. 2) Korn shell does not remove the temporary files when it exits due to receipt of a signal. PHCO_10719: 1) When ksh sees history file (using old internal magic cookies) of pre-10.10 release, it simply unlinks (discards) that history file. 2) When any shell-builtin command returns NULL in command substitution and the execution trace flag -x is on, then the output of the next shell-builtin in command substition is affected. PHCO_9484: 1) While using in-line command editing, characters would sometimes appear that had not been typed by the user, most commonly ^B. Also, in editing long history lines, especially near the end of the lines, garbage characters would appear and the line couldn't be edited properly. 2) ksh was leaving fd 10 [used for history file] always open. File descriptor 10 was being reserved for use by the shell, but the file descriptor was opened in a way that it would remain open across an exec(2) system call. 3) ksh returns incorrect exit-status when it executes 'exit' command on trap. For Example, When you run the following script "trap.sh" #! /usr/bin/ksh trap "_Exit" 0 1 2 3 15 _Exit(){ exit } rm FOOOOOOOO ls FOOOOOOOO $trap.sh $echo $? 0 The exit-value of the above script should be of last command executed that is 2 (exit value of ls FOOOOOOOO), rather it will return 0. PHCO_9088: 1) Trap on EXIT set outside a function is not executed. For example, trap 'echo exiting shell' EXIT f() { exit } f should output "exiting shell" but instead produces no output. 3) cd -P and pwd -P can fail when current directory path includes symbolic links where the link starts with ../ For example: cd /tmp mkdir test cd test ln -s ../../usr lnk cd lnk pwd -P will produce the error "pwd: permission denied". 4) ksh hangs when processing "cat bigfile | while read ..." The right side of the pipe can be any shell command (while, if, for, etc.) Defect Description: PHCO_20018: 1. ksh manpage does not say anything about the history file trimming. Resolution: The necessery information regarding the trimming of history file is added in the manpage. 2. When getopts is executed it reads the option argument from the command line and stores it in the static memory. If we execute some other command before using the value of OPTARG, the memory will be overwritten and the argument is lost. Resolution: To avoid this the argument that is read from the command line is stored in the heap so that it will not be corrupted. 3. When the history file size is more than 4K and the file is older than 10 minutes, there is some unwanted recursion between the function which opens the history file and the function which trims the history file. Resolution: The resolution involves avoiding this unwanted recursion by using a global flag. 4. The problem was due to a corrupt .sh_history file which was causing the shell to core dump. The problem was due to an array buffer overflow. Resolution: Now this array allocation has been changed to dynamic allocation & this fixes the problem. 5. When a script was executing a read command and a signal was sent to it, the signal was not delivered until after the completion of read. Resolution: Now checking of trap has been introduced so as to catch signals even during input processing. 6. If SIGHUP is trapped and a SIGHUP signal received, ksh(1) exits after executing the trap. It should continue to run instead. Resolution: ksh(1) was deliberately exiting after executing the trap for SIGHUP. This part of the code has now been eliminated, so that it continues to execute. 7. The trap set for signal SIGHUP is not executed by ksh(1), if it is received while a function is being executed. Resolution: When executing a function, ksh(1) resets all traps to their default action. If SIGHUP was received while executing a function, ksh(1) used to exit without executing the trap set. This specific check for SIGHUP has been now removed so that ksh(1) does not exit immediately, but instead executes the trap set and then exits. PHCO_17691: ksh(1) dumps core while executing scripts having large number of heredocs. Resolution: ksh(1) had limited the number of open files at any time to 20, which was not sufficient in the case of the script which used a large number of heredocs. ksh(1) didn't handle the case when this limit was exceeded, and hence it coredumped. ksh(1) now allows as many number of open files as the system allows, i.e. it retrieves the system configured value for the number of open files per process and allocates sufficient memory to the various data structures. Now, ksh(1) does not have internal restriction on the number of open files and handles the situation correctly by displaying appropriate error messages, when the number of open files is exceeded. PHCO_16363: A return statement within a do-while loop that is in a function, does not return from the function, but exits only the do-while loop. Running the following script demonstrates this fact. #!/usr/bin/ksh fxn() { cat /etc/passwd | while read line do echo $line return done echo after fxn return, still in fxn } fxn echo after fxn We see the message "after fxn return, still in fxn" even after the return statement is executed. PHCO_16065: 2) ksh does not handle command substitution of variables of length 2047, 3071, etc. correctly. In the following command, where variable "stuff" is assigned a string of length 2047, the contents of resulting string "str" will be the last 1023 bytes of "stuff". str=`echo $stuff` PHCO_15648: 10.20 Ksh subshell exits prematurely on a uniprocessor. On uniprocessor machines running one of 10.20, 10.10, 10.01 and 10.0 HP-UX'es, the subshell run through a script exits by itself without entering the exit routine. PHCO_13698: 1) Scripts like the following when sourced, cause the shell to exit. echo test | while read r do a=$(date) done 2) POSIX and Korn shell do not wait(2) for zombies while in vi input mode. Jobs which are started in the background and exit show up as zombies (defunct) until the user presses the return key in the xterm where the job was started. PHCO_13655: If set -e is ON, ksh should exit on encountering errors during processing the word list in a for statement, and case statement. When the last command in a pipe list fails also, it should exit if set -e is on. Currently it is not happening. Scripts like the following should exit on error. set -e for i in `sort a_non_existant_file` do echo Hello $i done echo "return code is " $? " -> Should not display this." PHCO_11347: 1) Since file descriptor ERRIO (2) is used in parser, it resets the i/o stream established with fd=2 when stderr is closed. This indirectly leads to syntax error while parsing and hence aborts. 2) trap DEBUG does not behave consistently with command substitution. 3) Shell builtin ':' (: > file) does not truncate file when called second time from a function. 4) Korh shell dumps core due to memory fault when function is defined in a loop. 5) Unread (undo read) character in lexical analyser is stored in shell data structure and this is added to input for trap action name is read. PHCO_11010: 1) When standard input is closed, the i/o channel established using the file descriptor 0 for the command substitution is not closed. This further leads ksh to bus error and hence make ksh dump core when it refers invalid location in the memory. 2) Korn shell does not clean up temporary files created when it exits due to receipt of a signal. PHCO_10719: 1) Since the internal magic cookies (H_UNDO & H_CMDNO) used in history file were valid multibyte characters, the cookies were changed to and hence aviod ambiguity when a history file is read in multibyte locales, the old history files were simply discarded. 2) When any shell-builtin command returns NULL in command substitution and the execution trace flag -x is on, then it takes incorrect output from the I/O stream for next shell-builtin command substition. set -x FOO=$(whence non_existing_file) FOO=$(whence ls) echo $FOO PHCO_9484: 1) While using in-line command editing, untyped characters would sometimes appear, most often ^B. These occurred most typically when very long command lines had been created. Also, in editing long history lines, especially near the end of the lines, garbage characters would appear and the line couldn't be edited properly. 2) File descriptor 10 was being reserved for use by the shell, but the file descriptor was opened in a way that it would remain open across an exec(2) system call. 3) ksh returns incorrect exit-status when it executes 'exit' command on trap. PHCO_9088: 1) A trap on EXIT set outside of a function is not executed if an exit is called from within a function. 3) cd -P and pwd -P generate nonexistent path names when the logical path uses symbolic links containing .. 4) ksh hangs when processing "cat bigfile | while read ..." The right side of the pipe can be any shell command (while, if, for, etc.) SR: 8606104865 1653298927 8606101547 8606103328 1653299891 5003442533 5003455519 1653302570 1653298422 4701413922 5003428490 5003424754 5003417931 1653239947 1653236851 1653240390 1653240408 4701339309 1653164350 1653174615 5003295741 5003340166 5003359547 1653210948 5003366856 1653205088 1653152892 1653216481 Patch Files: /usr/bin/ksh /usr/bin/rksh /usr/share/man/man1.Z/ksh.1 what(1) Output: /usr/bin/ksh: $Revision: 78.5.1.45 $ Version 11/16/88 PATCH_10_20: arith.o blok.o ctype.o defs.o edit.o ec ho.o expand.o fault.o io.o string.o stak.o w ord.o emacs.o vi.o hpux_rel.o args.o builtin .o cmd.o main.o msg.o print.o xec.o name.o m acro.o error.o service.o test.o jobs.o histo ry.o 99/10/18 /usr/bin/rksh: $Revision: 78.5.1.45 $ Version 11/16/88 PATCH_10_20: arith.o blok.o ctype.o defs.o edit.o ec ho.o expand.o fault.o io.o string.o stak.o w ord.o emacs.o vi.o hpux_rel.o args.o builtin .o cmd.o main.o msg.o print.o xec.o name.o m acro.o error.o service.o test.o jobs.o histo ry.o 99/10/18 /usr/share/man/man1.Z/ksh.1: None cksum(1) Output: 3552933687 159744 /usr/bin/ksh 3552933687 159744 /usr/bin/rksh 3561129141 40993 /usr/share/man/man1.Z/ksh.1 Patch Conflicts: None Patch Dependencies: s700: 10.20: PHCO_10718 s800: 10.20: PHCO_10718 Hardware Dependencies: None Other Dependencies: Since the POSIX sh(1) and the ksh(1) by default share the same history file it is advised to install the corresponding patches on all systems that access these. This is of particular interest in environments that mount home directories from a central NFS server. s700: 9.0X: PHCO_12193 s700: 10.00: PHCO_10730 PHCO_10731 s700: 10.01: PHCO_10728 PHCO_10729 s700: 10.10: PHCO_10720 PHCO_10721 s800: 9.0X: PHCO_12193 s800: 10.00: PHCO_10730 PHCO_10731 s800: 10.01: PHCO_10728 PHCO_10729 s800: 10.10: PHCO_10720 PHCO_10721 Supersedes: PHCO_9088 PHCO_9484 PHCO_10719 PHCO_11010 PHCO_11347 PHCO_13655 PHCO_13698 PHCO_15648 PHCO_16065 PHCO_16363 PHCO_17691 Equivalent Patches: None Patch Package Size: 260 KBytes Installation Instructions: Please review all instructions and the Hewlett-Packard SupportLine User Guide or your Hewlett-Packard support terms and conditions for precautions, scope of license, restrictions, and, limitation of liability and warranties, before installing this patch. ------------------------------------------------------------ 1. Back up your system before installing a patch. 2. Login as root. 3. Copy the patch to the /tmp directory. 4. Move to the /tmp directory and unshar the patch: cd /tmp sh PHCO_20018 5a. For a standalone system, run swinstall to install the patch: swinstall -x autoreboot=true -x match_target=true \ -s /tmp/PHCO_20018.depot By default swinstall will archive the original software in /var/adm/sw/patch/PHCO_20018. If you do not wish to retain a copy of the original software, you can create an empty file named /var/adm/sw/patch/PATCH_NOSAVE. WARNING: If this file exists when a patch is installed, the patch cannot be deinstalled. Please be careful when using this feature. It is recommended that you move the PHCO_20018.text file to /var/adm/sw/patch for future reference. To put this patch on a magnetic tape and install from the tape drive, use the command: dd if=/tmp/PHCO_20018.depot of=/dev/rmt/0m bs=2k Special Installation Instructions: None