Skip to content

Commit 41c4b82

Browse files
committed
sudo_ldap_get_first_rdn: Fix memory leak when ldap_str2dn is missing
This assumes that ldap_memfree() simply calls free(), which appears to be the case with all Linux/UNIX LDAP client libraries. Thanks to Joshua Rogers for finding this.
1 parent 3498d6a commit 41c4b82

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

plugins/sudoers/ldap.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ sudo_ldap_get_first_rdn(LDAP *ld, LDAPMessage *entry, int *rc)
378378
ldap_memfree(dn);
379379
debug_return_str(rdn);
380380
#else
381-
char *dn, **edn;
381+
char *dn, **edn, *rdn;
382382
debug_decl(sudo_ldap_get_first_rdn, SUDOERS_DEBUG_LDAP);
383383

384384
if ((dn = ldap_get_dn(ld, entry)) == NULL) {
@@ -393,8 +393,10 @@ sudo_ldap_get_first_rdn(LDAP *ld, LDAPMessage *entry, int *rc)
393393
*rc = LDAP_NO_MEMORY;
394394
debug_return_str(NULL);
395395
}
396-
*rc = LDAP_SUCCESS;
397-
debug_return_str(edn[0]);
396+
rdn = strdup(edn[0]);
397+
*rc = rdn ? LDAP_SUCCESS : LDAP_NO_MEMORY;
398+
ldap_value_free(edn);
399+
debug_return_str(rdn);
398400
#endif
399401
}
400402

0 commit comments

Comments
 (0)