Bug 344 - Bogus dl test: elf/tst-dlopenrpath.c and elf/tst-dlopenrpathmod.c
Summary: Bogus dl test: elf/tst-dlopenrpath.c and elf/tst-dlopenrpathmod.c
Status: RESOLVED DUPLICATE of bug 333
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: GOTO Masanori
Depends on:
Reported: 2004-08-23 20:55 UTC by H.J. Lu
Modified: 2019-04-10 11:39 UTC (History)
1 user (show)

See Also:
Last reconfirmed:
fweimer: security-

A testcase (1.49 KB, application/octet-stream)
2004-08-23 20:56 UTC, H.J. Lu

Note You need to log in before you can comment on or make changes to this bug.
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 ***