[v4,01/14] elf: Default to ENOENT error in _dl_map_new_object

Message ID b8af950b2ffb80d5cda19e67ad89730236203b02.1738530302.git.fweimer@redhat.com (mailing list archive)
State New
Headers
Series RELRO link maps |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed

Commit Message

Florian Weimer Feb. 2, 2025, 9:12 p.m. UTC
  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(-)
  

Patch

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