diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2014-07-01 14:16:28 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-07-01 14:16:28 +0200 |
| commit | 98654b995bb460733d94eba9ff2ee3d746c1e344 (patch) | |
| tree | b20090196560f2c762ae9813b513ddf7fe64e899 /coreutils | |
| parent | d32fc647d7da1923a91750ae937bf9b517195c8f (diff) | |
| download | busybox-w32-98654b995bb460733d94eba9ff2ee3d746c1e344.tar.gz busybox-w32-98654b995bb460733d94eba9ff2ee3d746c1e344.tar.bz2 busybox-w32-98654b995bb460733d94eba9ff2ee3d746c1e344.zip | |
test: fix mishandling of "test '(' = '('" and similar
function old new delta
test_main 246 350 +104
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/test.c | 69 |
1 files changed, 35 insertions, 34 deletions
diff --git a/coreutils/test.c b/coreutils/test.c index 4df505a05..88cc55050 100644 --- a/coreutils/test.c +++ b/coreutils/test.c | |||
| @@ -826,7 +826,6 @@ int test_main(int argc, char **argv) | |||
| 826 | { | 826 | { |
| 827 | int res; | 827 | int res; |
| 828 | const char *arg0; | 828 | const char *arg0; |
| 829 | // bool negate = 0; | ||
| 830 | 829 | ||
| 831 | arg0 = bb_basename(argv[0]); | 830 | arg0 = bb_basename(argv[0]); |
| 832 | if (arg0[0] == '[') { | 831 | if (arg0[0] == '[') { |
| @@ -844,6 +843,7 @@ int test_main(int argc, char **argv) | |||
| 844 | } | 843 | } |
| 845 | argv[argc] = NULL; | 844 | argv[argc] = NULL; |
| 846 | } | 845 | } |
| 846 | /* argc is unused after this point */ | ||
| 847 | 847 | ||
| 848 | /* We must do DEINIT_S() prior to returning */ | 848 | /* We must do DEINIT_S() prior to returning */ |
| 849 | INIT_S(); | 849 | INIT_S(); |
| @@ -862,43 +862,45 @@ int test_main(int argc, char **argv) | |||
| 862 | */ | 862 | */ |
| 863 | /*ngroups = 0; - done by INIT_S() */ | 863 | /*ngroups = 0; - done by INIT_S() */ |
| 864 | 864 | ||
| 865 | //argc--; | ||
| 866 | argv++; | 865 | argv++; |
| 866 | args = argv; | ||
| 867 | 867 | ||
| 868 | /* Implement special cases from POSIX.2, section 4.62.4 */ | 868 | /* Implement special cases from POSIX.2, section 4.62.4. |
| 869 | if (!argv[0]) { /* "test" */ | 869 | * Testcase: "test '(' = '('" |
| 870 | res = 1; | 870 | * The general parser would misinterpret '(' as group start. |
| 871 | goto ret; | 871 | */ |
| 872 | } | 872 | if (1) { |
| 873 | #if 0 | 873 | int negate = 0; |
| 874 | // Now it's fixed in the parser and should not be needed | 874 | again: |
| 875 | if (LONE_CHAR(argv[0], '!') && argv[1]) { | 875 | if (!argv[0]) { |
| 876 | negate = 1; | 876 | /* "test" */ |
| 877 | //argc--; | 877 | res = 1; |
| 878 | argv++; | 878 | goto ret_special; |
| 879 | } | 879 | } |
| 880 | if (!argv[1]) { /* "test [!] arg" */ | 880 | if (!argv[1]) { |
| 881 | res = (*argv[0] == '\0'); | 881 | /* "test [!] arg" */ |
| 882 | goto ret; | 882 | res = (argv[0][0] == '\0'); |
| 883 | } | 883 | goto ret_special; |
| 884 | if (argv[2] && !argv[3]) { | 884 | } |
| 885 | check_operator(argv[1]); | 885 | if (argv[2] && !argv[3]) { |
| 886 | if (last_operator->op_type == BINOP) { | 886 | check_operator(argv[1]); |
| 887 | /* "test [!] arg1 <binary_op> arg2" */ | 887 | if (last_operator->op_type == BINOP) { |
| 888 | args = argv; | 888 | /* "test [!] arg1 <binary_op> arg2" */ |
| 889 | res = (binop() == 0); | 889 | args = argv; |
| 890 | goto ret; | 890 | res = (binop() == 0); |
| 891 | ret_special: | ||
| 892 | /* If there was leading "!" op... */ | ||
| 893 | res ^= negate; | ||
| 894 | goto ret; | ||
| 895 | } | ||
| 896 | } | ||
| 897 | if (LONE_CHAR(argv[0], '!')) { | ||
| 898 | argv++; | ||
| 899 | negate ^= 1; | ||
| 900 | goto again; | ||
| 891 | } | 901 | } |
| 892 | } | 902 | } |
| 893 | 903 | ||
| 894 | /* Some complex expression. Undo '!' removal */ | ||
| 895 | if (negate) { | ||
| 896 | negate = 0; | ||
| 897 | //argc++; | ||
| 898 | argv--; | ||
| 899 | } | ||
| 900 | #endif | ||
| 901 | args = argv; | ||
| 902 | res = !oexpr(check_operator(*args)); | 904 | res = !oexpr(check_operator(*args)); |
| 903 | 905 | ||
| 904 | if (*args != NULL && *++args != NULL) { | 906 | if (*args != NULL && *++args != NULL) { |
| @@ -911,6 +913,5 @@ int test_main(int argc, char **argv) | |||
| 911 | } | 913 | } |
| 912 | ret: | 914 | ret: |
| 913 | DEINIT_S(); | 915 | DEINIT_S(); |
| 914 | // return negate ? !res : res; | ||
| 915 | return res; | 916 | return res; |
| 916 | } | 917 | } |
