Debian Codegraph @

tests/ftp-regressions.sh

raw
1 #!/bin/sh
2
3 # Copyright (C) 2022-2026 Free Software Foundation, Inc.
4 #
5 # This file is part of GNU Inetutils.
6 #
7 # GNU Inetutils is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or (at
10 # your option) any later version.
11 #
12 # GNU Inetutils is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see `http://www.gnu.org/licenses/'.
19
20 # Regression tests for the FTP client "ftp".
21
22 # Set tool variables (e.g., SED).
23 . ./tools.sh
24
25 # Handle VERBOSE environment variable.
26 if test -z "${VERBOSE+set}"; then
27 silence=:
28 bucket='>/dev/null'
29 fi
30 if test -n "$VERBOSE"; then
31 set -x
32 fi
33
34 # This script tests and thus requires the FTP client
35 FTP="${FTP:-../ftp/ftp$EXEEXT}"
36 if [ ! -x $FTP ]; then
37 echo "No FTP client '$FTP' present. Skipping test" >&2
38 exit 77
39 fi
40
41 # Print version of FTP client in VERBOSE mode.
42 if [ "$VERBOSE" ]; then
43 "$FTP" --version | $SED '1q'
44 fi
45
46 # Initialize test statistics.
47 SUCCESSES=0
48 EFFORTS=0
49 RESULT=0
50
51 # Check regression of crash reported in:
52 # https://lists.gnu.org/archive/html/bug-inetutils/2021-12/msg00003.html
53 # This bug is caused by signed integer overflow and insufficient bounds
54 # checking when using this integer for indexing into an array.
55 # First, use the original reproducer from the problem report.
56 EFFORTS=`expr $EFFORTS + 1`
57 $silence echo 'Checking ftp crash bug from message 2021-12/03...' >&2
58 "$FTP" < "$srcdir"/crash-ftp-msg2021-12_03.bin >/dev/null 2>&1
59 if test $? -ne 0; then
60 $silence echo 'Regression of ftp crash bug from message 2021-12/03.' >&2
61 RESULT=1
62 else
63 SUCCESSES=`expr $SUCCESSES + 1`
64 $silence echo 'Input from message 2021-12/03 did not crash ftp.' >&2
65 fi
66 # Second, use a simple reproducer for systems with 32 bit integers.
67 EFFORTS=`expr $EFFORTS + 1`
68 $silence echo 'Checking ftp crash bug from 32 bit integer overflow...' >&2
69 tell='macdef x
70 $2147483648
71
72 $ x'
73 echo "$tell" | "$FTP" >/dev/null 2>&1
74 if test $? -ne 0; then
75 $silence echo 'Regression of 32 bit integer overflow crash bug in ftp.' >&2
76 RESULT=1
77 else
78 SUCCESSES=`expr $SUCCESSES + 1`
79 $silence echo '32 bit integer overflow did not crash ftp.' >&2
80 fi
81
82 # Check regression of crash reported in:
83 # https://lists.gnu.org/archive/html/bug-inetutils/2021-12/msg00016.html
84 EFFORTS=`expr $EFFORTS + 1`
85 $silence echo 'Checking ftp crash bug from message 2021-12/16...' >&2
86 "$FTP" < "$srcdir"/crash-ftp-msg2021-12_16.bin >/dev/null 2>&1
87 if test $? -ne 0; then
88 $silence echo 'Regression of ftp crash bug from message 2021-12/16.' >&2
89 RESULT=1
90 else
91 SUCCESSES=`expr $SUCCESSES + 1`
92 $silence echo 'Input from message 2021-12/16 did not crash ftp.' >&2
93 fi
94
95 # Check regression of crash reported in:
96 # https://lists.gnu.org/archive/html/bug-inetutils/2021-12/msg00004.html
97 EFFORTS=`expr $EFFORTS + 1`
98 $silence echo 'Checking ftp crash bug from message 2021-12/04...' >&2
99 "$FTP" < "$srcdir"/crash-ftp-msg2021-12_04.bin >/dev/null 2>&1
100 if test $? -ne 0; then
101 $silence echo 'Regression of ftp crash bug from message 2021-12/04.' >&2
102 RESULT=1
103 else
104 SUCCESSES=`expr $SUCCESSES + 1`
105 $silence echo 'Input from message 2021-12/04 did not crash ftp.' >&2
106 fi
107
108 # Check regression of crash reported in:
109 # https://lists.gnu.org/archive/html/bug-inetutils/2021-12/msg00005.html
110 EFFORTS=`expr $EFFORTS + 1`
111 $silence echo 'Checking ftp crash bug from message 2021-12/05...' >&2
112 "$FTP" < "$srcdir"/crash-ftp-msg2021-12_05.bin >/dev/null 2>&1
113 if test $? -ne 0; then
114 $silence echo 'Regression of ftp crash bug from message 2021-12/05.' >&2
115 RESULT=1
116 else
117 SUCCESSES=`expr $SUCCESSES + 1`
118 $silence echo 'Input from message 2021-12/05 did not crash ftp.' >&2
119 fi
120 # Check trivial infinite macro recursion, too.
121 EFFORTS=`expr $EFFORTS + 1`
122 $silence echo 'Checking ftp crash via infinite macro recursion...' >&2
123 tell='macdef X
124 $ X
125
126 $ X'
127 echo "$tell" | "$FTP" >/dev/null 2>&1
128 if test $? -ne 0; then
129 $silence echo 'Regression of infinite macro recursion crash bug in ftp.' >&2
130 RESULT=1
131 else
132 SUCCESSES=`expr $SUCCESSES + 1`
133 $silence echo 'Infinite macro recursion did not crash ftp.' >&2
134 fi
135
136 # Print test statistics.
137 $silence echo
138 test "$RESULT" -eq 0 && test "$SUCCESSES" -eq "$EFFORTS" && $silence false \
139 || echo "Test had $SUCCESSES successes out of $EFFORTS cases".
140
141 # Report test result.
142 exit $RESULT