Created
July 29, 2018 04:56
-
-
Save tzickel/2ab09100ea21ca0e1e6709c337194bff to your computer and use it in GitHub Desktop.
A shell script that uses a recent strace to check for python 2 I/O error checking bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# You can replace the python version to check | |
PYTHON=${PYTHON:-`which python`} | |
TMPFILE=tmp.py | |
[ -x "`which strace`" ] || { echo strace not found; exit 1; } | |
[ -x "${PYTHON}" ] || { echo python not found; exit 1; } | |
set -e | |
# Check that the strace has the option for fault injection on read | |
strace -P just_checking -e trace=read -e fault=read ${PYTHON} -c exit 2>&1 || { echo strace could not check fault injection; exit 1; } | |
# Make a clean slate (since having the .pyc for example effects the results) | |
rm ${TMPFILE} 2> /dev/null || true | |
rm ${TMPFILE}c 2> /dev/null || true | |
# Make a script which exits with non 1 error level (to distinguish from an import error) | |
cat <<EOF >${TMPFILE} | |
import os | |
os._exit(5) | |
EOF | |
# This script should execute fine (note that -B is added so the bad .pyc won't be created) | |
${PYTHON} -B -c "import ${TMPFILE}" || [ $? -eq 5 ] || { echo Script failed too early...; exit 1; } | |
# This should fail because it could not read the .py file, if the bug exists, a bad .pyc will be produced | |
strace -P ${TMPFILE} -e trace=read -e fault=read ${PYTHON} -c "import ${TMPFILE}" || [ $? -eq 1 ] || { echo Script failed too early...; exit 1; } | |
# If the bug exists, this should fail since a bad .pyc was produced already | |
${PYTHON} -c "import ${TMPFILE}" || [ $? -eq 5 ] || { echo Bug exists an incorrect .pyc has been produced; exit 1; } | |
echo Script finished successfully |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment