build: ensure make-prime-list doesn't access out of bounds memory
[platform/upstream/coreutils.git] / tests / misc / stty-pairs.sh
1 #!/bin/sh
2 # Make sure stty can parse most of its options - in pairs [expensive].
3
4 # Copyright (C) 1998-2013 Free Software Foundation, Inc.
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ stty
21
22 expensive_
23
24 # Make sure there's a tty on stdin.
25 require_controlling_input_terminal_
26 trap '' TTOU # Ignore SIGTTOU
27
28 # Get the reversible settings from stty.c.
29 stty_reversible_init_
30
31 saved_state=.saved-state
32 stty --save > $saved_state || fail=1
33 stty $(cat $saved_state) || fail=1
34
35 # Build a list of all boolean options stty accepts on this system.
36 # Don't depend on terminal width.  Put each option on its own line,
37 # remove all non-boolean ones, remove 'parenb' and 'cread' explicitly,
38 # then remove any leading hyphens.
39 sed_del='/^speed/d;/^rows/d;/^columns/d;/ = /d;s/parenb//;s/cread//'
40 options=$(stty -a | tr -s ';' '\n' | sed "s/^ //;$sed_del;s/-//g")
41
42 # Take them in pairs, with and without the leading '-'.
43 for opt1 in $options; do
44   for opt2 in $options; do
45
46     stty $opt1 $opt2 || fail=1
47
48     if stty_reversible_query_ "$opt1" ; then
49       stty -$opt1 $opt2 || fail=1
50     fi
51     if stty_reversible_query_ "$opt2" ; then
52       stty $opt1 -$opt2 || fail=1
53     fi
54     if stty_reversible_query_ "$opt1" \
55         && stty_reversible_query_ "$opt2" ; then
56       stty -$opt1 -$opt2 || fail=1
57     fi
58   done
59 done
60
61 stty $(cat $saved_state)
62
63 Exit $fail