Bug 344

Summary: Bogus dl test: elf/tst-dlopenrpath.c and elf/tst-dlopenrpathmod.c
Product: glibc Reporter: H.J. Lu <hjl.tools>
Component: libcAssignee: GOTO Masanori <gotom>
Severity: normal CC: glibc-bugs
Priority: P2 Flags: fweimer: security-
Version: unspecified   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:
Attachments: A testcase

Description H.J. Lu 2004-08-23 20:55:24 UTC
Either elf/tst-dlopenrpath.c is bogus or open_path in elf/dl-load.c is wrong.
open_path has

/* Try to open NAME in one of the directories in *DIRSP.
   Return the fd, or -1.  If successful, fill in *REALNAME
   with the malloc'd full directory name.  If it turns out
   that none of the directories in *DIRSP exists, *DIRSP is
   replaced with (void *) -1, and the old value is free()d
   if MAY_FREE_DIRS is true.  */
static int
open_path (const char *name, size_t namelen, int preloaded,
           struct r_search_path_struct *sps, char **realname,
           struct filebuf *fbp)

So when a DSO has a DT_RPATH which isn't used to locate a DT_NEEDED
entry, that DT_RPATH may be ignored for this DSO later on for any dlopen
calls made from the DSO. elf/tst-dlopenrpathmod.c has

xxxxx          (RPATH)              Library rpath: [$ORIGIN/test-subdir]

If DT_RPATH is searched when loading tst-dlopenrpathmod.so for some reason,
DT_RPATH will be ignored for dlopen calls in tst-dlopenrpathmod.so. I got

couldn't open in-subdir.so from foo
Comment 1 H.J. Lu 2004-08-23 20:56:39 UTC
Created attachment 172 [details]
A testcase

gcc -c -fPIC -g -O2 -D_LARGEFILE64_SOURCE tst-dlopenrpathmod.c
gcc -shared -o tst-dlopenrpathmod.so tst-dlopenrpathmod.o -ldl -lpopt
gcc -o foo -g -O2 -D_LARGEFILE64_SOURCE tst-dlopenrpath.c
/export/home/hjl/bugs/libc/dl/tst-dlopenrpathmod.so -ldl
rm -rf test-subdir
cp -af tst-dlopenrpathmod.so firstobj.so
couldn't open in-subdir.so from foo: in-subdir.so: cannot open shared object
file: No such file or directory
make: [all] Error 1 (ignored)
Comment 2 Ulrich Drepper 2004-09-12 19:28:46 UTC

*** This bug has been marked as a duplicate of 333 ***