[2/3] rtld: Fix wrong errno check on open_path
Commit Message
At open_path code:
elf/dl-load.c
1982 if (here_any && (err = errno) != ENOENT && err != EACCES)
1983 /* The file exists and is readable, but something went wrong. */
1984 return -1;
This code checks the errno value without checking whether the previous
function call that changed 'err' actually has failed (in this specific
case the stat64 at line 1931). This due how we currently implemented
the y2038 support with INLINE_SYSCALL_CALL (since a function that
succeeds is allowed to change errno and it simplifies the resulting
y2038 support a bit).
In fact this check does not really make much sense, since either 'fd'
will be different than '0' (meaning it has being opened) or the 'stat64'
at line 1931 failed and 'here_any' will not be set (the stat64 at line
1951 already explicit sets errno in failure case). Also, git history
does not give much information on why it was added at fist place.
Checked on i686-linux-gnu, x86_64-linux-gnu, sparc64-linux-gnu,
sparcv9-linux-gnu, powerpc64-linux-gnu, powerpc64le-linux-gnu,
arm-linux-gnueabihf, and aarch64-linux-gnu.
---
elf/dl-load.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
@@ -1878,7 +1878,6 @@ open_path (const char *name, size_t namelen, int mode,
size_t cnt;
char *edp;
int here_any = 0;
- int err;
/* If we are debugging the search for libraries print the path
now if it hasn't happened now. */
@@ -1979,9 +1978,6 @@ open_path (const char *name, size_t namelen, int mode,
return -1;
}
}
- if (here_any && (err = errno) != ENOENT && err != EACCES)
- /* The file exists and is readable, but something went wrong. */
- return -1;
/* Remember whether we found anything. */
any |= here_any;
@@ -2002,6 +1998,8 @@ open_path (const char *name, size_t namelen, int mode,
sps->dirs = (void *) -1;
}
+ /* The errno is used by _dl_signal_error. */
+ __set_errno (ENOENT);
return -1;
}