Skip to content

Commit ae7dc39

Browse files
committed
Fix evaluation of a tuple used in "true" boolean context.
Previously, a tuple in boolean context was always treated as a negated entry, which doesn't match the documentation. We assume that there are at least two tuple entries where the first maps to boolean false and the second maps to boolean true. --HG-- branch : 1.9
1 parent 80a2794 commit ae7dc39

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

plugins/sudoers/defaults.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static int store_str(const char *str, struct sudo_defs_types *def);
6767
static bool store_syslogfac(const char *str, struct sudo_defs_types *def);
6868
static bool store_syslogpri(const char *str, struct sudo_defs_types *def);
6969
static bool store_timeout(const char *str, struct sudo_defs_types *def);
70-
static bool store_tuple(const char *str, struct sudo_defs_types *def);
70+
static bool store_tuple(const char *str, struct sudo_defs_types *def, int op);
7171
static bool store_uint(const char *str, struct sudo_defs_types *def);
7272
static bool store_timespec(const char *str, struct sudo_defs_types *def);
7373
static bool store_rlimit(const char *str, struct sudo_defs_types *def);
@@ -303,7 +303,7 @@ parse_default_entry(const struct sudoers_context *ctx,
303303
rc = store_timeout(val, def);
304304
break;
305305
case T_TUPLE:
306-
rc = store_tuple(val, def);
306+
rc = store_tuple(val, def, op);
307307
break;
308308
case T_TIMESPEC:
309309
rc = store_timespec(val, def);
@@ -593,8 +593,8 @@ init_defaults(void)
593593
#endif
594594

595595
/* Password flags also have a string and integer component. */
596-
(void) store_tuple("any", &sudo_defs_table[I_LISTPW]);
597-
(void) store_tuple("all", &sudo_defs_table[I_VERIFYPW]);
596+
(void) store_tuple("any", &sudo_defs_table[I_LISTPW], 0);
597+
(void) store_tuple("all", &sudo_defs_table[I_VERIFYPW], 0);
598598

599599
/* Then initialize the int-like things. */
600600
#ifdef SUDO_UMASK
@@ -1013,18 +1013,28 @@ store_timespec(const char *str, struct sudo_defs_types *def)
10131013
}
10141014

10151015
static bool
1016-
store_tuple(const char *str, struct sudo_defs_types *def)
1016+
store_tuple(const char *str, struct sudo_defs_types *def, int op)
10171017
{
10181018
struct def_values *v;
10191019
debug_decl(store_tuple, SUDOERS_DEBUG_DEFAULTS);
10201020

10211021
/*
10221022
* Look up tuple value by name to find enum def_tuple value.
1023-
* For negation to work the first element of enum def_tuple
1024-
* must be equivalent to boolean false.
1023+
* A tuple must have at least two possible values.
10251024
*/
10261025
if (str == NULL) {
1027-
def->sd_un.ival = 0;
1026+
/*
1027+
* Boolean context: true maps to values[1], false maps to values[0].
1028+
*/
1029+
if (op == true) {
1030+
v = &def->values[1];
1031+
def->sd_un.ival = v->nval;
1032+
} else if (op == false) {
1033+
v = &def->values[0];
1034+
def->sd_un.ival = v->nval;
1035+
} else {
1036+
debug_return_bool(false);
1037+
}
10281038
} else {
10291039
for (v = def->values; v->sval != NULL; v++) {
10301040
if (strcmp(v->sval, str) == 0) {

0 commit comments

Comments
 (0)