aboutsummaryrefslogtreecommitdiff
path: root/elf/dl-error.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2005-06-12 16:29:51 +0000
committerUlrich Drepper <drepper@redhat.com>2005-06-12 16:29:51 +0000
commit74780cf659d1e5cd91e82b6e5314dcfc7bba033b (patch)
treed71a5f1c94a7b7ac1a117760f2f3bd45ab1eea1d /elf/dl-error.c
parent6dffebd8b4ef0e3310ac97cade0d5dc33c49dadc (diff)
downloadglibc-74780cf659d1e5cd91e82b6e5314dcfc7bba033b.tar
glibc-74780cf659d1e5cd91e82b6e5314dcfc7bba033b.tar.gz
glibc-74780cf659d1e5cd91e82b6e5314dcfc7bba033b.tar.bz2
glibc-74780cf659d1e5cd91e82b6e5314dcfc7bba033b.zip
* elf/dl-error.c (_dl_signal_error): Store information about use of
real malloc in the catch object. (_dl_catch_error): Forward information about malloc use to caller in new parameter. (_dl_out_of_memory): Make static. * elf/dl-deps.c: Adjust callers of _dl_catch_error. * elf/dl-libc.c: Likewise. * elf/dl-open.c: Likewise. * elf/rtld.c: Likewise. Add new --audit option. * sysdeps/generic/ldsodefs.h: Remove _dl_out_of_memory declaration. (rtld_global_ro._dl_signal_error): Add new parameter. * include/dlfcn.h (_dl_catch_error): Add new parameter. * dlfcn/dlfcn.c (_dlerror_run): Pass additional parameter to _dl_catch_error. Only free if the returned newly value says so.
Diffstat (limited to 'elf/dl-error.c')
-rw-r--r--elf/dl-error.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/elf/dl-error.c b/elf/dl-error.c
index 993b7c29ab..a63d801411 100644
--- a/elf/dl-error.c
+++ b/elf/dl-error.c
@@ -19,6 +19,7 @@
#include <libintl.h>
#include <setjmp.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -30,6 +31,8 @@ struct catch
{
const char *objname; /* Object/File name. */
const char *errstring; /* Error detail filled in here. */
+ bool malloced; /* Nonzero if the string is malloced
+ by the libc malloc. */
jmp_buf env; /* longjmp here on error. */
};
@@ -44,8 +47,7 @@ struct catch
/* This message we return as a last resort. We define the string in a
variable since we have to avoid freeing it and so have to enable
a pointer comparison. See below and in dlfcn/dlerror.c. */
-const char _dl_out_of_memory[] = "out of memory";
-rtld_hidden_data_def (_dl_out_of_memory)
+static const char _dl_out_of_memory[] = "out of memory";
/* This points to a function which is called when an continuable error is
@@ -87,15 +89,27 @@ _dl_signal_error (int errcode, const char *objname, const char *occation,
lcatch->errstring = (char *) malloc (len_objname + len_errstring);
if (lcatch->errstring != NULL)
- /* Make a copy of the object file name and the error string. */
- lcatch->objname = memcpy (__mempcpy ((char *) lcatch->errstring,
- errstring, len_errstring),
- objname, len_objname);
+ {
+ /* Make a copy of the object file name and the error string. */
+ lcatch->objname = memcpy (__mempcpy ((char *) lcatch->errstring,
+ errstring, len_errstring),
+ objname, len_objname);
+
+ /* If the main executable is relocated it means the libc's malloc
+ is used. */
+#ifdef SHARED
+ lcatch->malloced = (GL(dl_ns)[LM_ID_BASE]._ns_loaded->l_relocated
+ != 0);
+#else
+ lcatch->malloced = true;
+#endif
+ }
else
{
/* This is better than nothing. */
lcatch->objname = "";
lcatch->errstring = _dl_out_of_memory;
+ lcatch->malloced = false;
}
longjmp (lcatch->env, errcode ?: -1);
}
@@ -140,7 +154,7 @@ _dl_signal_cerror (int errcode, const char *objname, const char *occation,
int
internal_function
_dl_catch_error (const char **objname, const char **errstring,
- void (*operate) (void *), void *args)
+ bool *mallocedp, void (*operate) (void *), void *args)
{
int errcode;
struct catch *volatile old;
@@ -162,6 +176,7 @@ _dl_catch_error (const char **objname, const char **errstring,
*catchp = old;
*objname = NULL;
*errstring = NULL;
+ *mallocedp = false;
return 0;
}
@@ -169,6 +184,7 @@ _dl_catch_error (const char **objname, const char **errstring,
*catchp = old;
*objname = c.objname;
*errstring = c.errstring;
+ *mallocedp = c.malloced;
return errcode == -1 ? 0 : errcode;
}