build: ensure make-prime-list doesn't access out of bounds memory
[platform/upstream/coreutils.git] / tests / misc / md5sum-bsd.sh
1 #!/bin/sh
2 # 'md5sum' tests for generation and checking of
3 # BSD traditional and alternate formats (md5 [-r])
4
5 # Copyright (C) 2011-2013 Free Software Foundation, Inc.
6
7 # This program 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
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU 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 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
21 print_ver_ md5sum
22
23 ## BSD alternate format tests ##
24
25 # Ensure we can --check BSD alternate format.
26 # Note we start this list with a name
27 # that's unambiguous in BSD format.
28 # I.E. one not starting with ' ' or '*'
29 for i in 'a' ' b' '*c' 'dd' ' '; do
30   echo "$i" > "$i"
31   md5sum "$i" >> check.md5sum
32 done
33 sed 's/  / /' check.md5sum > check.md5
34
35 # Note only a single format is supported per run
36 md5sum --strict -c check.md5sum || fail=1
37 md5sum --strict -c check.md5 || fail=1
38
39 # If we skip the first entry in the BSD format checksums
40 # then it'll be detected as standard format and error.
41 # This unlikely caveat was thought better than mandating
42 # an option to avoid the ambiguity.
43 tail -n+2 check.md5 | md5sum --strict -c && fail=1
44
45
46 ## BSD traditional format tests (--tag option) ##
47
48 # Ensure --tag and --check are mutually exclusive
49 md5sum --tag --check /dev/null && fail=1
50
51 # Ensure --tag and --text are mutually exclusive
52 # We don't support --text with BSD tradition format,
53 # as that would complicate the output format,
54 # while providing little benefit over --text processing
55 # available with the default md5sum output format.
56 md5sum --tag --text /dev/null && fail=1
57
58 # Ensure we can --check BSD traditional format we produce
59 rm check.md5
60 for i in 'a' ' b' '*c' 'dd' ' '; do
61   echo "$i" > "$i"
62   md5sum --tag "$i" >> check.md5
63 done
64 md5sum --strict -c check.md5 || fail=1
65
66 # Ensure we can --check BSD traditional format we produce
67 # with the GNU extension of escaped newlines
68 nl='
69 '
70 tab='   '
71 rm check.md5
72 for i in 'a\b' 'a\' "a${nl}b" "a${tab}b"; do
73   :> "$i"
74   md5sum --tag "$i" >> check.md5
75 done
76 md5sum --strict -c check.md5 || fail=1
77
78 # Ensure BSD traditional format with GNU extension escapes
79 # is in the expected format
80 ex_file='test
81 \\file'
82 ex_output='\MD5 (test\n\\\\file) = d41d8cd98f00b204e9800998ecf8427e'
83 touch "$ex_file"
84 printf "%s\n" "$ex_output" > exp
85 md5sum --tag "$ex_file" > out
86 compare exp out || fail=1
87
88 Exit $fail