summaryrefslogtreecommitdiff
path: root/tests/invalid-multibyte-infloop
blob: d7c6165d9dd8555bccce0c0e9a71891319569b7c (plain)
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
#!/bin/sh
# Ensure that we don't trigger a grep -F infloop.

. "${srcdir=.}/init.sh"; path_prepend_ ../src

require_en_utf8_locale_
require_compiled_in_MB_support
require_timeout_

encode() { echo "$1" | tr A '\202'; }

encode AA > input

fail=0

# Before 2.15, this would infloop.
LC_ALL=en_US.UTF-8 timeout 3 grep -aF $(encode A) input > out
status=$?
if test $status -eq 0; then
  compare input out
elif test $status -eq 1; then
  compare_dev_null_ /dev/null out
else
  test $status -eq 2
fi || fail=1

echo 'Binary file input matches' >binary-file-matches

LC_ALL=en_US.UTF-8 timeout 3 grep -F $(encode A) input > out
status=$?
if test $status -eq 0; then
  compare binary-file-matches out
elif test $status -eq 1; then
  compare_dev_null_ /dev/null out
else
  test $status -eq 2
fi || fail=1

Exit $fail