aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-11 17:00:39 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-11 17:00:39 +0200
commit129e1ce72c28ec14aee459cceffc25ed9d5cae85 (patch)
tree533c3003e9324d4c35762c1f4ccf2d3d56215927
parentd16e612c93d1a698c1a9d931b786cf3500996ae3 (diff)
downloadbusybox-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>
-rw-r--r--shell/ash_test/ash-getopts/getopt_test_libc_bug.right26
-rwxr-xr-xshell/ash_test/ash-getopts/getopt_test_libc_bug.tests38
-rw-r--r--shell/hush_test/hush-getopts/getopt_test_libc_bug.right26
-rwxr-xr-xshell/hush_test/hush-getopts/getopt_test_libc_bug.tests38
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
21 rc:0 var:'a' OPTIND:2 OPTARG:''
3Illegal option -b
42 rc:0 var:'?' OPTIND:3 OPTARG:''
53 rc:0 var:'c' OPTIND:4 OPTARG:''
6Illegal option -d
74 rc:0 var:'?' OPTIND:5 OPTARG:''
85 rc:1 var:'?' OPTIND:5 OPTARG:''
9
10*** optstring:'ac' args:-a -b -c -d e
111 rc:0 var:'a' OPTIND:2 OPTARG:''
12Illegal option -b
132 rc:0 var:'?' OPTIND:3 OPTARG:''
143 rc:0 var:'c' OPTIND:4 OPTARG:''
15Illegal option -d
164 rc:0 var:'?' OPTIND:5 OPTARG:''
175 rc:1 var:'?' OPTIND:5 OPTARG:''
18
19*** optstring:'ac' args:-a -b -c -d e
201 rc:0 var:'a' OPTIND:2 OPTARG:''
21Illegal option -b
222 rc:0 var:'?' OPTIND:3 OPTARG:''
233 rc:0 var:'c' OPTIND:4 OPTARG:''
24Illegal option -d
254 rc:0 var:'?' OPTIND:5 OPTARG:''
265 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
8echo "*** optstring:'ac' args:-a -b -c -d e"
9getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
10getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
11getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
12getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
13getopts "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
18echo
19echo "*** optstring:'ac' args:-a -b -c -d e"
20unset OPTIND
21OPTARG=QWERTY; getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
22NEWVAR=NEWVAL; getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
23VAR111=NEWVAL; getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
24VAR222=NEWVAL; getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
25VAR333=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
29echo
30echo "*** optstring:'ac' args:-a -b -c -d e"
31unset OPTIND
32export OPTARG; getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
33export NEWVAR; getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
34export VAR111; getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
35export VAR222; getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
36export 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
21 rc:0 var:'a' OPTIND:2 OPTARG:''
3./getopt_test_libc_bug.tests: invalid option -- b
42 rc:0 var:'?' OPTIND:3 OPTARG:''
53 rc:0 var:'c' OPTIND:4 OPTARG:''
6./getopt_test_libc_bug.tests: invalid option -- d
74 rc:0 var:'?' OPTIND:5 OPTARG:''
85 rc:1 var:'?' OPTIND:5 OPTARG:''
9
10*** optstring:'ac' args:-a -b -c -d e
111 rc:0 var:'a' OPTIND:2 OPTARG:''
12./getopt_test_libc_bug.tests: invalid option -- b
132 rc:0 var:'?' OPTIND:3 OPTARG:''
143 rc:0 var:'c' OPTIND:4 OPTARG:''
15./getopt_test_libc_bug.tests: invalid option -- d
164 rc:0 var:'?' OPTIND:5 OPTARG:''
175 rc:1 var:'?' OPTIND:5 OPTARG:''
18
19*** optstring:'ac' args:-a -b -c -d e
201 rc:0 var:'a' OPTIND:2 OPTARG:''
21./getopt_test_libc_bug.tests: invalid option -- b
222 rc:0 var:'?' OPTIND:3 OPTARG:''
233 rc:0 var:'c' OPTIND:4 OPTARG:''
24./getopt_test_libc_bug.tests: invalid option -- d
254 rc:0 var:'?' OPTIND:5 OPTARG:''
265 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
8echo "*** optstring:'ac' args:-a -b -c -d e"
9getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
10getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
11getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
12getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
13getopts "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
18echo
19echo "*** optstring:'ac' args:-a -b -c -d e"
20unset OPTIND
21OPTARG=QWERTY; getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
22NEWVAR=NEWVAL; getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
23VAR111=NEWVAL; getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
24VAR222=NEWVAL; getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
25VAR333=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
29echo
30echo "*** optstring:'ac' args:-a -b -c -d e"
31unset OPTIND
32export OPTARG; getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
33export NEWVAR; getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
34export VAR111; getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
35export VAR222; getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
36export 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