hush: fix "set -o INVALID" affecting -e flag state

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2019-09-05 14:07:14 +02:00
parent 750137ef7c
commit 18a90ec846

View File

@ -9824,9 +9824,12 @@ static int set_mode(int state, char mode, const char *o_opt)
IF_HUSH_MODE_X(G_x_mode = state;) IF_HUSH_MODE_X(G_x_mode = state;)
IF_HUSH_MODE_X(if (G.x_mode_fd <= 0) G.x_mode_fd = dup_CLOEXEC(2, 10);) IF_HUSH_MODE_X(if (G.x_mode_fd <= 0) G.x_mode_fd = dup_CLOEXEC(2, 10);)
break; break;
case 'e':
G.o_opt[OPT_O_ERREXIT] = state;
break;
case 'o': case 'o':
if (!o_opt) { if (!o_opt) {
/* "set -+o" without parameter. /* "set -o" or "set +o" without parameter.
* in bash, set -o produces this output: * in bash, set -o produces this output:
* pipefail off * pipefail off
* and set +o: * and set +o:
@ -9847,9 +9850,7 @@ static int set_mode(int state, char mode, const char *o_opt)
G.o_opt[idx] = state; G.o_opt[idx] = state;
break; break;
} }
case 'e': /* fall through to error */
G.o_opt[OPT_O_ERREXIT] = state;
break;
default: default:
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -10931,8 +10932,10 @@ static int FAST_FUNC builtin_set(char **argv)
if (arg[0] != '+' && arg[0] != '-') if (arg[0] != '+' && arg[0] != '-')
break; break;
for (n = 1; arg[n]; ++n) { for (n = 1; arg[n]; ++n) {
if (set_mode((arg[0] == '-'), arg[n], argv[1])) if (set_mode((arg[0] == '-'), arg[n], argv[1])) {
goto error; bb_error_msg("%s: %s: invalid option", "set", arg);
return EXIT_FAILURE;
}
if (arg[n] == 'o' && argv[1]) if (arg[n] == 'o' && argv[1])
argv++; argv++;
} }
@ -10962,11 +10965,6 @@ static int FAST_FUNC builtin_set(char **argv)
G.global_argc = 1 + string_array_len(pp + 1); G.global_argc = 1 + string_array_len(pp + 1);
return EXIT_SUCCESS; return EXIT_SUCCESS;
/* Nothing known, so abort */
error:
bb_error_msg("%s: %s: invalid option", "set", arg);
return EXIT_FAILURE;
} }
#endif #endif