[PATCH v4 01/14] elf: Default to ENOENT error in _dl_map_new_object
Florian Weimer
fweimer@redhat.com
Sun Feb 2 21:12:49 GMT 2025
The errno leak was originally observed as elf/tst-rtld-does-not-exist,
elf/tst-rtld-dash-dash test failures on an AArch64 system without
protection keys support: the ENOSPC error from the pkey_alloc system
call leaked into the printed error message, causing the test failure.
Without the pkey_alloc call, errno is 0.
Setting ENOENT unconditionally still changes the error message,
so update the test expectations accordingly.
---
elf/dl-load.c | 5 +++++
elf/tst-rtld-dash-dash.sh | 2 +-
elf/tst-rtld-does-not-exist.sh | 2 +-
3 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 4998652adf..e328d678b4 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1939,6 +1939,11 @@ _dl_map_new_object (struct link_map *loader, const char *name,
/* Will be true if we found a DSO which is of the other ELF class. */
bool found_other_class = false;
+ /* Default errno to ENOENT. The code may not end up doing any
+ system calls before setting fd to -1 because there are no search
+ paths. */
+ __set_errno (ENOENT);
+
#ifdef SHARED
/* Give the auditing libraries a chance to change the name before we
try anything. */
diff --git a/elf/tst-rtld-dash-dash.sh b/elf/tst-rtld-dash-dash.sh
index 5b00110d38..cf31552168 100644
--- a/elf/tst-rtld-dash-dash.sh
+++ b/elf/tst-rtld-dash-dash.sh
@@ -31,7 +31,7 @@ echo "output (with expected error):"
cat "$tmp_out"
if test $status -eq 127 \
- && grep -q "^--program-does-not-exist: error while loading shared libraries: --program-does-not-exist: cannot open shared object file$" "$tmp_out" \
+ && grep -q "^--program-does-not-exist: error while loading shared libraries: --program-does-not-exist: cannot open shared object file: No such file or directory$" "$tmp_out" \
&& test "$(wc -l < "$tmp_out")" -eq 1 ; then
status=0
else
diff --git a/elf/tst-rtld-does-not-exist.sh b/elf/tst-rtld-does-not-exist.sh
index 9f404aecbf..418cfb445e 100644
--- a/elf/tst-rtld-does-not-exist.sh
+++ b/elf/tst-rtld-does-not-exist.sh
@@ -31,7 +31,7 @@ echo "output (with expected error):"
cat "$tmp_out"
if test $status -eq 127 \
- && grep -q "^program-does-not-exist: error while loading shared libraries: program-does-not-exist: cannot open shared object file$" "$tmp_out" \
+ && grep -q "^program-does-not-exist: error while loading shared libraries: program-does-not-exist: cannot open shared object file: No such file or directory$" "$tmp_out" \
&& test "$(wc -l < "$tmp_out")" -eq 1 ; then
status=0
else
--
2.48.1
More information about the Libc-alpha
mailing list