mrsh icon indicating copy to clipboard operation
mrsh copied to clipboard

Hard fail on undefined behaviour

Open emersion opened this issue 6 years ago • 0 comments

  1. Go through the spec and enumerate undefined behaviour (grep for "undefined" and "unspecified")
  2. Change mrsh to hard fail in these cases
# 2.1
# This as the first line (but let's just ignore it…):
#!whatever

# 2.2.3
echo `echo "abc`
echo `echo 'abc`
echo "`echo a" # but this could be a continuation?

# 2.4
[[ ]] function select
name:

# 2.5.2
# When the expansion occurs within double-quotes, the behavior is unspecified unless one of the following is true […]

# 2.5.3
ENV=./thing # not an absolute pathname
IFS=`python -c 'print(chr(0))'`; read # not a valid character
echo $LINENO # not executing a script or a function
# […] then it is unspecified whether the shell sets PWD to the value from the environment or sets PWD to the pathname that would be output by pwd -P.
# In cases where PWD is set to the pathname that would be output by pwd -P, if there is insufficient permission on the current working directory, or on any parent of that directory, to determine what that pathname would be, the value of PWD is unspecified.
PWD=whatever; cd, pwd

# 2.6
echo $  # unescaped $ with a space or anything that isn't allowed

# 2.6.1
unset HOME; echo ~
echo ~idontexist

# 2.6.2
echo ${ } # not a digit nor one of the special params
echo ${#*}; echo ${#@}
echo ${#%whatever}; echo ${@%whatever}; echo ${@%whatever} # and more…

# TODO: incomplete from here

# 2.6.3
echo `$(echo `echo a`)`
echo `echo # `
`
echo `echo "a b c `echo d`"`
# Same within here-doc
# Plus the same cases as 2.2.3…

# Plus a bunch of undefined behaviour in builtins

emersion avatar Jun 30 '19 14:06 emersion