This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[patch/rfc] don't try to load directories when searching for an ELF
- From: Mike Frysinger <vapier at gentoo dot org>
- To: libc-alpha at sourceware dot org
- Date: Fri, 6 Jan 2006 23:29:11 -0500
- Subject: [patch/rfc] don't try to load directories when searching for an ELF
a user noted that if he had a directory that was named the same as a library
that was trying to be loaded, glibc's ldso would abort
a [stupid] example to reproduce would be:
$ mkdir -p /tmp/lib/libc.so.6
$ export LD_LIBRARY_PATH=/tmp/lib
$ ls
ls: error while loading shared libraries: /tmp/lib/libc.so.6: cannot read file
data: Error 21
i'm pretty sure this is the intended behavior as the comment above
open_verify() reads:
/* Open a file and verify it is an ELF file for this architecture. We
ignore only ELF files for other architectures. Non-ELF files and
ELF files with different header information cause fatal errors since
this could mean there is something wrong in the installation and the
user might want to know about this. */
but in the off chance this change may be accepted, and i do enjoy witty
sarcasm, a patch is attached which tweaks open_verify() to return -1 instead
of aborting when encountering a directory
-mike
2006-01-06 Mike Frysinger <vapier@gentoo.org>
* elf/dl-load.c (open_verify): Skip directories.
--- elf/dl-load.c
+++ elf/dl-load.c
@@ -1,5 +1,5 @@
/* Map in a shared object's segments from the file.
- Copyright (C) 1995-2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1995-2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -1631,6 +1631,15 @@ open_verify (const char *name, struct fi
/* Now run the tests. */
if (__builtin_expect (fbp->len < (ssize_t) sizeof (ElfW(Ehdr)), 0))
{
+ /* Make sure this isn't a directory. */
+ struct stat64 st;
+ if (__fxstat64 (_STAT_VER, fd, &st) == 0
+ && S_ISDIR(st.st_mode))
+ {
+ __close (fd);
+ return -1;
+ }
+
errval = errno;
errstring = (errval == 0
? N_("file too short") : N_("cannot read file data"));