[PATCHv2 1/3] nss: Handle __tsearch out of memory case in __nss_lookup_function

Jiri Olsa jolsa@redhat.com
Sun Sep 25 14:48:00 GMT 2011


When tsearch fails to allocate memory, it returns NULL.
Fixing __nss_lookup_function to properly handle this case.

---
2011-09-25  Jiri Olsa  <jolsa@redhat.com>

	* nss/nsswitch.c (__nss_lookup_function): Handle __tsearch
	out of memory case.

diff --git a/nss/nsswitch.c b/nss/nsswitch.c
index 6c15c3a..7f8900e 100644
--- a/nss/nsswitch.c
+++ b/nss/nsswitch.c
@@ -384,7 +384,9 @@ __nss_lookup_function (service_user *ni, const char *fct_name)
      will be passed to `known_compare' (above).  */
 
   found = __tsearch (&fct_name, &ni->known, &known_compare);
-  if (*found != &fct_name)
+  if (found == NULL)
+      result = NULL;
+  else if (*found != &fct_name)
     {
       /* The search found an existing structure in the tree.  */
       result = ((known_function *) *found)->fct_ptr;
-- 
1.7.4.4



More information about the Libc-alpha mailing list