This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 3/3] nss: Handle nss_load_library out of memory case
- From: Jiri Olsa <jolsa at redhat dot com>
- To: libc-alpha at sourceware dot org
- Cc: drepper at gmail dot com
- Date: Thu, 15 Sep 2011 15:56:33 +0200
- Subject: [PATCH 3/3] nss: Handle nss_load_library out of memory case
- References: <1316094993-8086-1-git-send-email-jolsa@redhat.com>
If nss_load_library function fails with out of memory error,
the current code frees the key and then removes it from the tree,
which ends up with the crash.
We need to remove the key from the tree first and then free it.
I'm not sure we want to keep the key in tree in case:
'ni->library->lib_handle == (void *) -1'
but since it seems to be current behaviour I kept it.
---
2011-09-15 Jiri Olsa <jolsa@redhat.com>
* nss/nsswitch.c (__nss_lookup_function): Handle
nss_load_library out of memory case.
diff --git a/nss/nsswitch.c b/nss/nsswitch.c
index 2646d9a..a60a67f 100644
--- a/nss/nsswitch.c
+++ b/nss/nsswitch.c
@@ -402,7 +402,6 @@ __nss_lookup_function (service_user *ni, const char *fct_name)
known_function *known = malloc (sizeof *known);
if (! known)
{
- remove_from_tree:
/* Oops. We can't instantiate this node properly.
Remove it from the tree. */
__tdelete (&fct_name, &ni->known, &known_compare);
@@ -419,11 +418,11 @@ __nss_lookup_function (service_user *ni, const char *fct_name)
if (nss_load_library (ni) != 0)
{
/* This only happens when out of memory. */
+ __tdelete (&fct_name, &ni->known, &known_compare);
free (known);
- goto remove_from_tree;
+ result = NULL;
}
-
- if (ni->library->lib_handle == (void *) -1l)
+ else if (ni->library->lib_handle == (void *) -1l)
/* Library not found => function not found. */
result = NULL;
else
--
1.7.4.4