From a40110756483b66ec69cd0e204d54afb62a65777 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 26 Oct 2016 13:49:05 -0600 Subject: [PATCH] Check for sudo_ldap_result_last_search() returning NULL. This can't happen in practice because we always call sudo_ldap_result_add_search() first which guarantees there is a result to be found. Quiets a PVS-Studio warning. --- plugins/sudoers/ldap.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/plugins/sudoers/ldap.c b/plugins/sudoers/ldap.c index 20c5605df..c85efe2d0 100644 --- a/plugins/sudoers/ldap.c +++ b/plugins/sudoers/ldap.c @@ -3375,19 +3375,22 @@ sudo_ldap_result_add_entry(struct ldap_result *lres, LDAPMessage *entry) /* Determine whether the entry has the sudoOrder attribute. */ last = sudo_ldap_result_last_search(lres); - bv = ldap_get_values_len(last->ldap, entry, "sudoOrder"); - if (bv != NULL) { - if (ldap_count_values_len(bv) > 0) { - /* Get the value of this attribute, 0 if not present. */ - DPRINTF2("order attribute raw: %s", (*bv)->bv_val); - order = strtod((*bv)->bv_val, &ep); - if (ep == (*bv)->bv_val || *ep != '\0') { - sudo_warnx(U_("invalid sudoOrder attribute: %s"), (*bv)->bv_val); - order = 0.0; + if (last != NULL) { + bv = ldap_get_values_len(last->ldap, entry, "sudoOrder"); + if (bv != NULL) { + if (ldap_count_values_len(bv) > 0) { + /* Get the value of this attribute, 0 if not present. */ + DPRINTF2("order attribute raw: %s", (*bv)->bv_val); + order = strtod((*bv)->bv_val, &ep); + if (ep == (*bv)->bv_val || *ep != '\0') { + sudo_warnx(U_("invalid sudoOrder attribute: %s"), + (*bv)->bv_val); + order = 0.0; + } + DPRINTF2("order attribute: %f", order); } - DPRINTF2("order attribute: %f", order); + ldap_value_free_len(bv); } - ldap_value_free_len(bv); } /* -- 2.40.0