Skip to content

Commit

Permalink
Fix NULL pointer deref on memory allocation failure
Browse files Browse the repository at this point in the history
This fixes a NULL pointer dereference when a call to malloc() failed.

Closes #70
  • Loading branch information
arthurdejong committed Aug 27, 2024
1 parent b7841fc commit 91bb8c9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions nslcd/passwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Copyright (C) 1997-2005 Luke Howard
Copyright (C) 2006 West Consulting
Copyright (C) 2006-2017 Arthur de Jong
Copyright (C) 2006-2024 Arthur de Jong
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -293,8 +293,16 @@ char *dn2uid(MYLDAP_SESSION *session, const char *dn, char *buf, size_t buflen)
/* see if we have a cached entry */
pthread_mutex_lock(&dn2uid_cache_mutex);
if (dn2uid_cache == NULL)
{
dn2uid_cache = dict_new();
if ((dn2uid_cache != NULL) && ((cacheentry = dict_get(dn2uid_cache, dn)) != NULL))
if (dn2uid_cache == NULL)
{
log_log(LOG_ERR, "dict_new() failed to allocate memory");
pthread_mutex_unlock(&dn2uid_cache_mutex);
return NULL;
}
}
if ((cacheentry = dict_get(dn2uid_cache, dn)) != NULL)
{
if ((cacheentry->uid != NULL) && (strlen(cacheentry->uid) < buflen))
{
Expand Down

0 comments on commit 91bb8c9

Please sign in to comment.