hush: add a test which fails due to uclibc bug in getopt()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
d16e612c93
commit
129e1ce72c
26
shell/ash_test/ash-getopts/getopt_test_libc_bug.right
Normal file
26
shell/ash_test/ash-getopts/getopt_test_libc_bug.right
Normal file
@ -0,0 +1,26 @@
|
||||
*** optstring:'ac' args:-a -b -c -d e
|
||||
1 rc:0 var:'a' OPTIND:2 OPTARG:''
|
||||
Illegal option -b
|
||||
2 rc:0 var:'?' OPTIND:3 OPTARG:''
|
||||
3 rc:0 var:'c' OPTIND:4 OPTARG:''
|
||||
Illegal option -d
|
||||
4 rc:0 var:'?' OPTIND:5 OPTARG:''
|
||||
5 rc:1 var:'?' OPTIND:5 OPTARG:''
|
||||
|
||||
*** optstring:'ac' args:-a -b -c -d e
|
||||
1 rc:0 var:'a' OPTIND:2 OPTARG:''
|
||||
Illegal option -b
|
||||
2 rc:0 var:'?' OPTIND:3 OPTARG:''
|
||||
3 rc:0 var:'c' OPTIND:4 OPTARG:''
|
||||
Illegal option -d
|
||||
4 rc:0 var:'?' OPTIND:5 OPTARG:''
|
||||
5 rc:1 var:'?' OPTIND:5 OPTARG:''
|
||||
|
||||
*** optstring:'ac' args:-a -b -c -d e
|
||||
1 rc:0 var:'a' OPTIND:2 OPTARG:''
|
||||
Illegal option -b
|
||||
2 rc:0 var:'?' OPTIND:3 OPTARG:''
|
||||
3 rc:0 var:'c' OPTIND:4 OPTARG:''
|
||||
Illegal option -d
|
||||
4 rc:0 var:'?' OPTIND:5 OPTARG:''
|
||||
5 rc:1 var:'?' OPTIND:5 OPTARG:''
|
38
shell/ash_test/ash-getopts/getopt_test_libc_bug.tests
Executable file
38
shell/ash_test/ash-getopts/getopt_test_libc_bug.tests
Executable file
@ -0,0 +1,38 @@
|
||||
# This test can fail with libc with buggy getopt() implementation.
|
||||
# If getopt() wants to parse multi-option args (-abc),
|
||||
# it needs to remember a position withit current arg.
|
||||
#
|
||||
# If this position is kept as a POINTER, not an offset,
|
||||
# and if argv[] ADDRESSES (not contents!) change, it blows up.
|
||||
|
||||
echo "*** optstring:'ac' args:-a -b -c -d e"
|
||||
getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
getopts "ac" var -a -b -c -d e; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
|
||||
# Above: args are (usually) in the same locations in memory.
|
||||
# Below: variable allocations change the location.
|
||||
|
||||
echo
|
||||
echo "*** optstring:'ac' args:-a -b -c -d e"
|
||||
unset OPTIND
|
||||
OPTARG=QWERTY; getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
NEWVAR=NEWVAL; getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
VAR111=NEWVAL; getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
VAR222=NEWVAL; getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
VAR333=NEWVAL; getopts "ac" var -a -b -c -d e; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
|
||||
# Sligntly different attempts to force reallocations
|
||||
|
||||
echo
|
||||
echo "*** optstring:'ac' args:-a -b -c -d e"
|
||||
unset OPTIND
|
||||
export OPTARG; getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
export NEWVAR; getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
export VAR111; getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
export VAR222; getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
export VAR333; getopts "ac" var -a -b -c -d e; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
|
||||
# All copies of code above should generate identical output
|
26
shell/hush_test/hush-getopts/getopt_test_libc_bug.right
Normal file
26
shell/hush_test/hush-getopts/getopt_test_libc_bug.right
Normal file
@ -0,0 +1,26 @@
|
||||
*** optstring:'ac' args:-a -b -c -d e
|
||||
1 rc:0 var:'a' OPTIND:2 OPTARG:''
|
||||
./getopt_test_libc_bug.tests: invalid option -- b
|
||||
2 rc:0 var:'?' OPTIND:3 OPTARG:''
|
||||
3 rc:0 var:'c' OPTIND:4 OPTARG:''
|
||||
./getopt_test_libc_bug.tests: invalid option -- d
|
||||
4 rc:0 var:'?' OPTIND:5 OPTARG:''
|
||||
5 rc:1 var:'?' OPTIND:5 OPTARG:''
|
||||
|
||||
*** optstring:'ac' args:-a -b -c -d e
|
||||
1 rc:0 var:'a' OPTIND:2 OPTARG:''
|
||||
./getopt_test_libc_bug.tests: invalid option -- b
|
||||
2 rc:0 var:'?' OPTIND:3 OPTARG:''
|
||||
3 rc:0 var:'c' OPTIND:4 OPTARG:''
|
||||
./getopt_test_libc_bug.tests: invalid option -- d
|
||||
4 rc:0 var:'?' OPTIND:5 OPTARG:''
|
||||
5 rc:1 var:'?' OPTIND:5 OPTARG:''
|
||||
|
||||
*** optstring:'ac' args:-a -b -c -d e
|
||||
1 rc:0 var:'a' OPTIND:2 OPTARG:''
|
||||
./getopt_test_libc_bug.tests: invalid option -- b
|
||||
2 rc:0 var:'?' OPTIND:3 OPTARG:''
|
||||
3 rc:0 var:'c' OPTIND:4 OPTARG:''
|
||||
./getopt_test_libc_bug.tests: invalid option -- d
|
||||
4 rc:0 var:'?' OPTIND:5 OPTARG:''
|
||||
5 rc:1 var:'?' OPTIND:5 OPTARG:''
|
38
shell/hush_test/hush-getopts/getopt_test_libc_bug.tests
Executable file
38
shell/hush_test/hush-getopts/getopt_test_libc_bug.tests
Executable file
@ -0,0 +1,38 @@
|
||||
# This test can fail with libc with buggy getopt() implementation.
|
||||
# If getopt() wants to parse multi-option args (-abc),
|
||||
# it needs to remember a position withit current arg.
|
||||
#
|
||||
# If this position is kept as a POINTER, not an offset,
|
||||
# and if argv[] ADDRESSES (not contents!) change, it blows up.
|
||||
|
||||
echo "*** optstring:'ac' args:-a -b -c -d e"
|
||||
getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
getopts "ac" var -a -b -c -d e; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
|
||||
# Above: args are (usually) in the same locations in memory.
|
||||
# Below: variable allocations change the location.
|
||||
|
||||
echo
|
||||
echo "*** optstring:'ac' args:-a -b -c -d e"
|
||||
unset OPTIND
|
||||
OPTARG=QWERTY; getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
NEWVAR=NEWVAL; getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
VAR111=NEWVAL; getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
VAR222=NEWVAL; getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
VAR333=NEWVAL; getopts "ac" var -a -b -c -d e; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
|
||||
# Sligntly different attempts to force reallocations
|
||||
|
||||
echo
|
||||
echo "*** optstring:'ac' args:-a -b -c -d e"
|
||||
unset OPTIND
|
||||
export OPTARG; getopts "ac" var -a -b -c -d e; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
export NEWVAR; getopts "ac" var -a -b -c -d e; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
export VAR111; getopts "ac" var -a -b -c -d e; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
export VAR222; getopts "ac" var -a -b -c -d e; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
export VAR333; getopts "ac" var -a -b -c -d e; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
|
||||
|
||||
# All copies of code above should generate identical output
|
Loading…
Reference in New Issue
Block a user