public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug dynamic-link/25991] New: ldd should print "insufficient memory" in certain cases
@ 2020-05-14 14:33 carlos at redhat dot com
0 siblings, 0 replies; only message in thread
From: carlos at redhat dot com @ 2020-05-14 14:33 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=25991
Bug ID: 25991
Summary: ldd should print "insufficient memory" in certain
cases
Product: glibc
Version: 2.29
Status: NEW
Severity: normal
Priority: P2
Component: dynamic-link
Assignee: unassigned at sourceware dot org
Reporter: carlos at redhat dot com
Target Milestone: ---
The dynamic loader when used as ldd, and when it runs out of memory, should
return a unique error code that causes ldd to print "insufficient memory" in
those cases.
For example:
diff --git a/elf/ldd.bash.in b/elf/ldd.bash.in
index 4ff140d..6c1144c 100644
--- a/elf/ldd.bash.in
+++ b/elf/ldd.bash.in
@@ -186,6 +186,9 @@ warning: you do not have execution permission for"
"\`$file'" >&2
2)
try_trace "$RTLD" "$file" || result=1
;;
+ 3)
+ echo 'ldd:' ${RTLD} $" insufficient memory" >&2
+ ;;
*)
echo 'ldd:' ${RTLD} $"exited with unknown exit code" "($ret)" >&2
exit 1
diff --git a/elf/rtld.c b/elf/rtld.c
index 9d121dc..90b8ab7 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -44,6 +44,9 @@
#include <assert.h>
+/* Exit with a value of 3 if we ran out of memory while tracing. */
+#define EXIT_ENOMEM 3
+
/* Avoid PLT use for our local calls at startup. */
extern __typeof (__mempcpy) __mempcpy attribute_hidden;
@@ -1060,18 +1063,23 @@ of this helper program; chances are you did not intend
to run this program.\n\
{
const char *objname;
const char *err_str = NULL;
+ int errcode;
struct map_args args;
bool malloced;
args.str = rtld_progname;
args.loader = NULL;
args.mode = __RTLD_OPENEXEC;
- (void) _dl_catch_error (&objname, &err_str, &malloced, map_doit,
- &args);
+ errcode = _dl_catch_error (&objname, &err_str, &malloced, map_doit,
+ &args);
if (__glibc_unlikely (err_str != NULL))
- /* We don't free the returned string, the programs stops
- anyway. */
- _exit (EXIT_FAILURE);
+ {
+ /* We don't free the returned string, the programs stops
+ anyway. */
+ if (errcode == ENOMEM)
+ _exit (EXIT_ENOMEM);
+ _exit (EXIT_FAILURE);
+ }
}
else
{
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-05-14 14:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14 14:33 [Bug dynamic-link/25991] New: ldd should print "insufficient memory" in certain cases carlos at redhat dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).