From 15f633fbd397d2bd253bc010fe449a1728e6473e Mon Sep 17 00:00:00 2001 From: nathanw Date: Thu, 14 Nov 2002 21:07:46 +0000 Subject: In _rtld_load_library(), ensure that the old _rtld_error state (a message from a previous error, or NULL) is preserved if the search eventually succeeds. Addresses the problem pointed out in PR pkg/19024. --- libexec/ld.elf_so/search.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'libexec') diff --git a/libexec/ld.elf_so/search.c b/libexec/ld.elf_so/search.c index f858bce5cc3..43076f1ded3 100644 --- a/libexec/ld.elf_so/search.c +++ b/libexec/ld.elf_so/search.c @@ -1,4 +1,4 @@ -/* $NetBSD: search.c,v 1.15 2002/10/05 11:59:04 mycroft Exp $ */ +/* $NetBSD: search.c,v 1.16 2002/11/14 21:07:46 nathanw Exp $ */ /* * Copyright 1996 Matt Thomas @@ -116,6 +116,7 @@ _rtld_load_library(name, refobj, mode) const Obj_Entry *refobj; int mode; { + char tmperror[512], *tmperrorp; Search_Path *sp; char *pathname; int namelen; @@ -133,27 +134,47 @@ _rtld_load_library(name, refobj, mode) } dbg((" Searching for \"%s\" (%p)", name, refobj)); + tmperrorp = _rtld_dlerror(); + if (tmperrorp != NULL) { + strncpy(tmperror, tmperrorp, sizeof tmperror); + tmperrorp = tmperror; + } + namelen = strlen(name); for (sp = _rtld_paths; sp != NULL; sp = sp->sp_next) if ((obj = _rtld_search_library_path(name, namelen, sp->sp_path, sp->sp_pathlen, mode)) != NULL) - return obj; + goto pathfound; if (refobj != NULL) for (sp = refobj->rpaths; sp != NULL; sp = sp->sp_next) if ((obj = _rtld_search_library_path(name, namelen, sp->sp_path, sp->sp_pathlen, mode)) != NULL) - return obj; + goto pathfound; for (sp = _rtld_default_paths; sp != NULL; sp = sp->sp_next) if ((obj = _rtld_search_library_path(name, namelen, sp->sp_path, sp->sp_pathlen, mode)) != NULL) - return obj; + goto pathfound; _rtld_error("Shared object \"%s\" not found", name); return NULL; +pathfound: + /* + * Successfully found a library; restore the dlerror state as it was + * before _rtld_load_library() was called (any failed call to + * _rtld_search_library_path() will set the dlerror state, but if the + * library was eventually found, then the error state should not + * change. + */ + if (tmperrorp) + _rtld_error("%s", tmperror); + else + (void)_rtld_dlerror(); + return obj; + found: obj = _rtld_load_object(pathname, mode); if (obj == NULL) -- cgit lass='logsubject'>Fix up some lint.dholland 2011-08-06Fix up still more casts; use NULL instead of (char *)0.dholland 2011-05-23Correctly print variables as strings, not as format string.joerg 2009-06-07ANSIfy function declarations. All object file diffs inspected.dholland 2007-12-15convert __attribute__s to applicable cdefs.h macrosperry 2004-01-27Remove uses of __P.jsm 2003-04-02Hack is now BSD-licensed. Thanks to Andries Brouwer, Jay Fenlason andjsm CWI <http://www.cwi.nl/~aeb/games/hack/hack.html>. Via OpenBSD. Addresses part of PR bin/5850.