diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-11 17:00:39 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-11 17:00:39 +0200 |
commit | 129e1ce72c28ec14aee459cceffc25ed9d5cae85 (patch) | |
tree | 533c3003e9324d4c35762c1f4ccf2d3d56215927 | |
parent | d16e612c93d1a698c1a9d931b786cf3500996ae3 (diff) | |
download | busybox-w32-129e1ce72c28ec14aee459cceffc25ed9d5cae85.tar.gz busybox-w32-129e1ce72c28ec14aee459cceffc25ed9d5cae85.tar.bz2 busybox-w32-129e1ce72c28ec14aee459cceffc25ed9d5cae85.zip |
hush: add a test which fails due to uclibc bug in getopt()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
4 files changed, 128 insertions, 0 deletions
diff --git a/shell/ash_test/ash-getopts/getopt_test_libc_bug.right b/shell/ash_test/ash-getopts/getopt_test_libc_bug.right new file mode 100644 index 000000000..f6ad4602d --- /dev/null +++ b/shell/ash_test/ash-getopts/getopt_test_libc_bug.right | |||
@@ -0,0 +1,26 @@ | |||
1 | *** optstring:'ac' args:-a -b -c -d e | ||
2 | 1 rc:0 var:'a' OPTIND:2 OPTARG:'' | ||
3 | Illegal option -b | ||
4 | 2 rc:0 var:'?' OPTIND:3 OPTARG:'' | ||
5 | 3 rc:0 var:'c' OPTIND:4 OPTARG:'' | ||
6 | Illegal option -d | ||
7 | 4 rc:0 var:'?' OPTIND:5 OPTARG:'' | ||
8 | 5 rc:1 var:'?' OPTIND:5 OPTARG:'' | ||
9 | |||
10 | *** optstring:'ac' args:-a -b -c -d e | ||
11 | 1 rc:0 var:'a' OPTIND:2 OPTARG:'' | ||
12 | Illegal option -b | ||
13 | 2 rc:0 var:'?' OPTIND:3 OPTARG:'' | ||
14 | 3 rc:0 var:'c' OPTIND:4 OPTARG:'' | ||
15 | Illegal option -d | ||
16 | 4 rc:0 var:'?' OPTIND:5 OPTARG:'' | ||
17 | 5 rc:1 var:'?' OPTIND:5 OPTARG:'' | ||
18 | |||
19 | *** optstring:'ac' args:-a -b -c -d e | ||
20 | 1 rc:0 var:'a' OPTIND:2 OPTARG:'' | ||
21 | Illegal option -b | ||
22 | 2 rc:0 var:'?' OPTIND:3 OPTARG:'' | ||
23 | 3 rc:0 var:'c' OPTIND:4 OPTARG:'' | ||
24 | Illegal option -d | ||
25 | 4 rc:0 var:'?' OPTIND:5 OPTARG:'' | ||
26 | 5 rc:1 var:'?' OPTIND:5 OPTARG:'' | ||
diff --git a/shell/ash_test/ash-getopts/getopt_test_libc_bug.tests b/shell/ash_test/ash-getopts/getopt_test_libc_bug.tests new file mode 100755 index 000000000..6c0781f20 --- /dev/null +++ b/shell/ash_test/ash-getopts/getopt_test_libc_bug.tests | |||
@@ -0,0 +1,38 @@ | |||
1 | # This test can fail with libc with buggy getopt() implementation. | ||
2 | # If getopt() wants to parse multi-option args (-abc), | ||
3 | # it needs to remember a position withit current arg. | ||
4 | # | ||
5 | # If this position is kept as a POINTER, not an offset, | ||
6 | # and if argv[] ADDRESSES (not contents!) change, it blows up. | ||
7 | |||
8 | echo "*** optstring:'ac' args:-a -b -c -d e" | ||
9 | getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
10 | getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
11 | getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
12 | getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
13 | getopts "ac" var -a -b -c -d e; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
14 | |||
15 | # Above: args are (usually) in the same locations in memory. | ||
16 | # Below: variable allocations change the location. | ||
17 | |||
18 | echo | ||
19 | echo "*** optstring:'ac' args:-a -b -c -d e" | ||
20 | unset OPTIND | ||
21 | OPTARG=QWERTY; getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
22 | NEWVAR=NEWVAL; getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
23 | VAR111=NEWVAL; getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
24 | VAR222=NEWVAL; getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
25 | VAR333=NEWVAL; getopts "ac" var -a -b -c -d e; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
26 | |||
27 | # Sligntly different attempts to force reallocations | ||
28 | |||
29 | echo | ||
30 | echo "*** optstring:'ac' args:-a -b -c -d e" | ||
31 | unset OPTIND | ||
32 | export OPTARG; getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
33 | export NEWVAR; getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
34 | export VAR111; getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
35 | export VAR222; getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
36 | export VAR333; getopts "ac" var -a -b -c -d e; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
37 | |||
38 | # All copies of code above should generate identical output | ||
diff --git a/shell/hush_test/hush-getopts/getopt_test_libc_bug.right b/shell/hush_test/hush-getopts/getopt_test_libc_bug.right new file mode 100644 index 000000000..6694e8f0c --- /dev/null +++ b/shell/hush_test/hush-getopts/getopt_test_libc_bug.right | |||
@@ -0,0 +1,26 @@ | |||
1 | *** optstring:'ac' args:-a -b -c -d e | ||
2 | 1 rc:0 var:'a' OPTIND:2 OPTARG:'' | ||
3 | ./getopt_test_libc_bug.tests: invalid option -- b | ||
4 | 2 rc:0 var:'?' OPTIND:3 OPTARG:'' | ||
5 | 3 rc:0 var:'c' OPTIND:4 OPTARG:'' | ||
6 | ./getopt_test_libc_bug.tests: invalid option -- d | ||
7 | 4 rc:0 var:'?' OPTIND:5 OPTARG:'' | ||
8 | 5 rc:1 var:'?' OPTIND:5 OPTARG:'' | ||
9 | |||
10 | *** optstring:'ac' args:-a -b -c -d e | ||
11 | 1 rc:0 var:'a' OPTIND:2 OPTARG:'' | ||
12 | ./getopt_test_libc_bug.tests: invalid option -- b | ||
13 | 2 rc:0 var:'?' OPTIND:3 OPTARG:'' | ||
14 | 3 rc:0 var:'c' OPTIND:4 OPTARG:'' | ||
15 | ./getopt_test_libc_bug.tests: invalid option -- d | ||
16 | 4 rc:0 var:'?' OPTIND:5 OPTARG:'' | ||
17 | 5 rc:1 var:'?' OPTIND:5 OPTARG:'' | ||
18 | |||
19 | *** optstring:'ac' args:-a -b -c -d e | ||
20 | 1 rc:0 var:'a' OPTIND:2 OPTARG:'' | ||
21 | ./getopt_test_libc_bug.tests: invalid option -- b | ||
22 | 2 rc:0 var:'?' OPTIND:3 OPTARG:'' | ||
23 | 3 rc:0 var:'c' OPTIND:4 OPTARG:'' | ||
24 | ./getopt_test_libc_bug.tests: invalid option -- d | ||
25 | 4 rc:0 var:'?' OPTIND:5 OPTARG:'' | ||
26 | 5 rc:1 var:'?' OPTIND:5 OPTARG:'' | ||
diff --git a/shell/hush_test/hush-getopts/getopt_test_libc_bug.tests b/shell/hush_test/hush-getopts/getopt_test_libc_bug.tests new file mode 100755 index 000000000..6c0781f20 --- /dev/null +++ b/shell/hush_test/hush-getopts/getopt_test_libc_bug.tests | |||
@@ -0,0 +1,38 @@ | |||
1 | # This test can fail with libc with buggy getopt() implementation. | ||
2 | # If getopt() wants to parse multi-option args (-abc), | ||
3 | # it needs to remember a position withit current arg. | ||
4 | # | ||
5 | # If this position is kept as a POINTER, not an offset, | ||
6 | # and if argv[] ADDRESSES (not contents!) change, it blows up. | ||
7 | |||
8 | echo "*** optstring:'ac' args:-a -b -c -d e" | ||
9 | getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
10 | getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
11 | getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
12 | getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
13 | getopts "ac" var -a -b -c -d e; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
14 | |||
15 | # Above: args are (usually) in the same locations in memory. | ||
16 | # Below: variable allocations change the location. | ||
17 | |||
18 | echo | ||
19 | echo "*** optstring:'ac' args:-a -b -c -d e" | ||
20 | unset OPTIND | ||
21 | OPTARG=QWERTY; getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
22 | NEWVAR=NEWVAL; getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
23 | VAR111=NEWVAL; getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
24 | VAR222=NEWVAL; getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
25 | VAR333=NEWVAL; getopts "ac" var -a -b -c -d e; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
26 | |||
27 | # Sligntly different attempts to force reallocations | ||
28 | |||
29 | echo | ||
30 | echo "*** optstring:'ac' args:-a -b -c -d e" | ||
31 | unset OPTIND | ||
32 | export OPTARG; getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
33 | export NEWVAR; getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
34 | export VAR111; getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
35 | export VAR222; getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
36 | export VAR333; getopts "ac" var -a -b -c -d e; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" | ||
37 | |||
38 | # All copies of code above should generate identical output | ||