1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#!/bin/sh
# Copyright (C) 2021-2026 Free Software Foundation, Inc.
# Copyright (C) 2019 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PARSER="${PARSER:-../src/asn1Parser${EXEEXT}}"
srcdir="${srcdir:-.}"
FGREP=${FGREP:-fgrep}
TMPFILE=pkix.asn.$$.tmp
TMPFILEOUTPUT=parser.out.$$.tmp
if ! test -z "${VALGRIND}"; then
VALGRIND="${LIBTOOL:-libtool} --mode=execute valgrind --leak-check=full"
fi
echo "Test: PKIX file generation"
${VALGRIND} "${PARSER}" "${srcdir}"/pkix.asn -o ${TMPFILE}
if test $? != 0;then
echo "Cannot generate C file!"
exit 1
fi
# Find out how to remove carriage returns from output. Solaris /usr/ucb/tr
# does not understand '\r'.
if echo solaris | tr -d '\r' | grep solais > /dev/null; then
cr='\015'
else
cr='\r'
fi
# normalize output
LC_ALL=C tr -d "$cr" < $TMPFILE > x$TMPFILE
mv x$TMPFILE $TMPFILE
cmp ${TMPFILE} ${srcdir}/pkix.asn.out || \
diff ${TMPFILE} ${srcdir}/pkix.asn.out
if test $? != 0;then
echo "Generated C file differs!"
cat ${TMPFILE}
exit 1
fi
rm -f ${TMPFILE}
# Test invalid command line option
${VALGRIND} "${PARSER}" --asdf > $TMPFILEOUTPUT 2>&1
if test $? != 1; then
echo "Invalid command line arg - incorrect return code!"
exit 1
fi
# Look for "--help" in the output, make grep quiet.
# "--" to avoid grep trying to interpret "--help" as an option.
if ! $FGREP -q -- "--help" $TMPFILEOUTPUT; then
echo "Invalid command line arg - incorrect command output!"
exit 1
fi
# Test help command line option
${VALGRIND} "${PARSER}" --help > $TMPFILEOUTPUT 2>&1
if test $? != 0; then
echo "Help command line arg - incorrect return code!"
exit 1
fi
# Look for "--help" in the output, make grep quiet.
# "--" to avoid grep trying to interpret "--help" as an option.
if ! $FGREP -q -- "--help" $TMPFILEOUTPUT; then
echo "Help command line arg - incorrect command output!"
exit 1
fi
# Test no options
${VALGRIND} "${PARSER}" > $TMPFILEOUTPUT 2>&1
if test $? != 0; then
echo "No command line arg - incorrect return code!"
exit 1
fi
# Look for "--help" in the output, make grep quiet.
# "--" to avoid grep trying to interpret "--help" as an option.
if ! $FGREP -q -- "--help" $TMPFILEOUTPUT; then
echo "No command line arg - incorrect command output!"
exit 1
fi
# Test version option
${VALGRIND} "${PARSER}" --version
if test $? != 0; then
echo "Version command line arg - incorrect return code!"
exit 1
fi
# Test check option - valid case
${VALGRIND} "${PARSER}" -c "${srcdir}"/Test_tree.asn > $TMPFILEOUTPUT 2>&1
if test $? != 0; then
echo "Check command line arg (valid case) - incorrect return code!"
exit 1
fi
# Look for actual version in the output
if $FGREP -q "Error:" $TMPFILEOUTPUT; then
echo "Check command line arg (valid case) - incorrect command output!"
exit 1
fi
# Test check option - invalid case
${VALGRIND} "${PARSER}" -c "${srcdir}"/Test_parser_ERROR.asn > $TMPFILEOUTPUT 2>&1
if test $? = 0; then
echo "Check command line arg (invalid case)- incorrect return code!"
exit 1
fi
# Test passing an invalid filename
${VALGRIND} "${PARSER}" this_isnt_a_real_file.asn > $TMPFILEOUTPUT 2>&1
if test $? = 0; then
echo "Test invalid filename - incorrect return code!"
exit 1
fi
# Another error case, causes "recursion" which falls to a default
# case in asn1Parser.c
${VALGRIND} "${PARSER}" -c "${srcdir}"/CVE-2018-1000654-2.asn > $TMPFILEOUTPUT 2>&1
if test $? = 0; then
echo "Check recursion - incorrect return code!"
exit 1
fi
rm -f ${TMPFILEOUTPUT}
exit 0
|