Add reference counting to Defaults bindings.

Previously, we checked that the previous entry's binding pointer
was not the same while freeing.  However, to be able to merge
Defaults records we cannot rely on Defaults entries with the same
binding being immediately adjacent.  This removes the prev_binding
checks in favor of a reference count which allows us to plug the
memory leak in cvtsudoers when merging Defaults.
This commit is contained in:
Todd C. Miller
2021-11-20 08:01:37 -07:00
parent aed51033e1
commit e64a089aea
12 changed files with 131 additions and 107 deletions

View File

@@ -714,19 +714,19 @@ default_binding_matches(struct sudoers_parse_tree *parse_tree,
case DEFAULTS:
debug_return_bool(true);
case DEFAULTS_USER:
if (userlist_matches(parse_tree, sudo_user.pw, d->binding) == ALLOW)
if (userlist_matches(parse_tree, sudo_user.pw, &d->binding->members) == ALLOW)
debug_return_bool(true);
break;
case DEFAULTS_RUNAS:
if (runaslist_matches(parse_tree, d->binding, NULL, NULL, NULL) == ALLOW)
if (runaslist_matches(parse_tree, &d->binding->members, NULL, NULL, NULL) == ALLOW)
debug_return_bool(true);
break;
case DEFAULTS_HOST:
if (hostlist_matches(parse_tree, sudo_user.pw, d->binding) == ALLOW)
if (hostlist_matches(parse_tree, sudo_user.pw, &d->binding->members) == ALLOW)
debug_return_bool(true);
break;
case DEFAULTS_CMND:
if (cmndlist_matches(parse_tree, d->binding, NULL, NULL) == ALLOW)
if (cmndlist_matches(parse_tree, &d->binding->members, NULL, NULL) == ALLOW)
debug_return_bool(true);
break;
}