From eb0135a93adf28f9362932fcf5f7b1b30a450b40 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 1 Jun 2022 14:30:47 -0600 Subject: [PATCH] Simplify the check for when we can reuse the previous user and host specs. This makes the code easier to read and quiets a cppcheck false positive. --- plugins/sudoers/parse_ldif.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/sudoers/parse_ldif.c b/plugins/sudoers/parse_ldif.c index debdbf32e..15c56b81e 100644 --- a/plugins/sudoers/parse_ldif.c +++ b/plugins/sudoers/parse_ldif.c @@ -498,11 +498,12 @@ ldif_to_sudoers(struct sudoers_parse_tree *parse_tree, bool reuse_userspec = false; bool reuse_privilege = false; bool reuse_runas = false; + struct sudo_role *prev_role = role; role = role_array[n]; /* Check whether we can reuse the previous user and host specs */ - if (n > 0 && role->users == role_array[n - 1]->users) { + if (prev_role != NULL && role->users == prev_role->users) { reuse_userspec = true; /* @@ -511,12 +512,12 @@ ldif_to_sudoers(struct sudoers_parse_tree *parse_tree, * we are storing options. */ if (!store_options) { - if (role->hosts == role_array[n - 1]->hosts) { + if (role->hosts == prev_role->hosts) { reuse_privilege = true; /* Reuse runasusers and runasgroups if possible. */ - if (role->runasusers == role_array[n - 1]->runasusers && - role->runasgroups == role_array[n - 1]->runasgroups) + if (role->runasusers == prev_role->runasusers && + role->runasgroups == prev_role->runasgroups) reuse_runas = true; } }