From e38c62d68d2615ea8761cb40a62bdbe751ca7751 Mon Sep 17 00:00:00 2001 From: John Marino Date: Wed, 12 Jun 2013 14:06:58 +0200 Subject: [PATCH] rtld: Sync 3/7 - LD_PRELOAD and z_nodeflib fix Do not reference z_nodeflib for !objgiven case in order to fix LD_PRELOAD for a non-absolute path. Taken from: FreeBSD SVN 240686 (18 SEP 2012) --- libexec/rtld-elf/rtld.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 0a83c3fd2d..4763eba09b 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -1521,8 +1521,9 @@ find_library(const char *xname, const Obj_Entry *refobj) { char *pathname; char *name; - bool objgiven = (refobj != NULL); + bool nodeflib, objgiven; + objgiven = refobj != NULL; if (strchr(xname, '/') != NULL) { /* Hard coded pathname */ if (xname[0] != '/' && !trust) { _rtld_error("Absolute pathname required for shared object \"%s\"", @@ -1541,20 +1542,20 @@ find_library(const char *xname, const Obj_Entry *refobj) dbg(" Searching for \"%s\"", name); + nodeflib = objgiven ? refobj->z_nodeflib : false; if ((objgiven && (pathname = search_library_path(name, refobj->rpath)) != NULL) || - (objgiven && (refobj->runpath == NULL) && (refobj != obj_main) && + (objgiven && refobj->runpath == NULL && refobj != obj_main && (pathname = search_library_path(name, obj_main->rpath)) != NULL) || (pathname = search_library_path(name, ld_library_path)) != NULL || (objgiven && (pathname = search_library_path(name, refobj->runpath)) != NULL) || - (pathname = search_library_path(name, gethints(refobj->z_nodeflib))) - != NULL || - (objgiven && !refobj->z_nodeflib && + (pathname = search_library_path(name, gethints(nodeflib))) != NULL || + (objgiven && !nodeflib && (pathname = search_library_path(name, STANDARD_LIBRARY_PATH)) != NULL)) - return pathname; + return (pathname); - if(objgiven && refobj->path != NULL) { + if (objgiven && refobj->path != NULL) { _rtld_error("Shared object \"%s\" not found, required by \"%s\"", name, basename(refobj->path)); } else { @@ -3791,7 +3792,7 @@ symlook_obj(SymLook *req, const Obj_Entry *obj) int flags, res, mres; /* - * If there is at least one valid hash at this point, and we prefer to + * If there is at least one valid hash at this point, we prefer to * use the faster GNU version if available. */ if (obj->valid_hash_gnu) -- 2.41.0