Fix: error handling for invalid autounlock value
Because the existing error was the default case in a switch/case statement only reachable if the option matched one of the expected ones in the list, it wasn't actually reachable: something totally out of left-field wouldn't match one of the expected options so never hit the switch, and something that did match one of the expected options would by definition have a first character handled by one of the cases in the switch/case. Do it a slightly different way that should successfully raise an unexpected value error for 'OPTIONS=autounlock:foobar'. I didn't remove the default case entirely, because it could still catch an error if some new value is added to unlocktypes[] without a corresponding case being added to the switch statement.
This commit is contained in:
+11
-5
@@ -775,6 +775,7 @@ optfn_autounlock(
|
|||||||
newflags = 0;
|
newflags = 0;
|
||||||
sep = index(op, '+') ? '+' : ' ';
|
sep = index(op, '+') ? '+' : ' ';
|
||||||
while (op) {
|
while (op) {
|
||||||
|
boolean matched = FALSE;
|
||||||
op = trimspaces(op); /* might have leading space */
|
op = trimspaces(op); /* might have leading space */
|
||||||
if ((nxt = index(op, sep)) != 0) {
|
if ((nxt = index(op, sep)) != 0) {
|
||||||
*nxt++ = '\0';
|
*nxt++ = '\0';
|
||||||
@@ -782,13 +783,14 @@ optfn_autounlock(
|
|||||||
* plus sign removal */
|
* plus sign removal */
|
||||||
}
|
}
|
||||||
if (str_start_is("none", op, TRUE))
|
if (str_start_is("none", op, TRUE))
|
||||||
negated = TRUE;
|
negated = TRUE, matched = TRUE;
|
||||||
for (i = 0; i < SIZE(unlocktypes); ++i) {
|
for (i = 0; i < SIZE(unlocktypes) && !matched; ++i) {
|
||||||
if (str_start_is(unlocktypes[i][0], op, TRUE)
|
if (str_start_is(unlocktypes[i][0], op, TRUE)
|
||||||
/* fuzzymatch() doesn't match leading substrings but
|
/* fuzzymatch() doesn't match leading substrings but
|
||||||
this allows "apply_key" and "applykey" to match
|
this allows "apply_key" and "applykey" to match
|
||||||
"apply-key"; "apply key" too if part of foo+bar */
|
"apply-key"; "apply key" too if part of foo+bar */
|
||||||
|| fuzzymatch(op, unlocktypes[i][0], " -_", TRUE)) {
|
|| fuzzymatch(op, unlocktypes[i][0], " -_", TRUE)) {
|
||||||
|
matched = TRUE;
|
||||||
switch (*op) {
|
switch (*op) {
|
||||||
case 'n':
|
case 'n':
|
||||||
negated = TRUE;
|
negated = TRUE;
|
||||||
@@ -806,12 +808,16 @@ optfn_autounlock(
|
|||||||
newflags |= AUTOUNLOCK_FORCE;
|
newflags |= AUTOUNLOCK_FORCE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
config_error_add("Invalid value for \"%s\": \"%s\"",
|
matched = FALSE;
|
||||||
allopt[optidx].name, op);
|
break;
|
||||||
return optn_silenterr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!matched) {
|
||||||
|
config_error_add("Invalid value for \"%s\": \"%s\"",
|
||||||
|
allopt[optidx].name, op);
|
||||||
|
return optn_silenterr;
|
||||||
|
}
|
||||||
op = nxt;
|
op = nxt;
|
||||||
}
|
}
|
||||||
if (negated && newflags != 0) {
|
if (negated && newflags != 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user