Skip to content

Use of >/dev/null 2>&1 in called function causes "Abort(coredump)" #1485

Open
@xmnboy

Description

@xmnboy

Description of problem:
Use of >/dev/null 2>&1 within a called function causes function to terminate with an Abort(coredump) message.

ksh version:
Version A 2020.0.0

# ksh --version
  version         sh (AT&T Research) 2020.0.0

Linux distribution:

# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

How reproducible:
Discovered in a sourced script, but also reproducible within an executed script. No such problem with ksh93 version of ksh or with [lm]ksh fork. Not sure about earlier versions of ksh2020.

Steps to reproduce:
Source or execute this script from a ksh2020 prompt (testing was done as root user on an Ubuntu 20.04 system):

#!/bin/ksh
# generate coredump with ksh2020
# failure appears to be associated with '>/dev/null 2>&1' when inside a function
# set -x 
# path/to/this/script.sh

redirection() (
  { \unalias command; \unset -f command; } >/dev/null 2>&1 || :
  echo $1
)

echo ${.sh.version}
echo ${.sh.file}
echo ${.sh.file} >/dev/null
echo ${.sh.file} 2>&1
echo ${.sh.file} >/dev/null 2>&1

test=$(basename -- "$(redirection "${.sh.file}")")
echo "\$test =" $test

Actual results:

# ./test.sh
Version A 2020.0.0
/root/test.sh
/root/test.sh
./test.sh: line 18: 32761: Abort(coredump)
$test =

Expected results:

# ./test.sh
Version A 2020.0.0
/root/test.sh
/root/test.sh
$test = /root/test.sh

Additional info:
While initially debugging this issue I managed to also generate a free(): invalid pointer message along with the Abort(coredump) message. But I am not able to recall precisely what I did that resulted in that additional error message. Including it here because it may be of value regarding resolution of this problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions