Fix serveral ltdl bugs related to searching for libraries, and what

to do if they cannot be found.

- in try_dlopen, after find_handle() is called and returns 0 over
  and over, it was ignoring the return value of tryall_dlopen.  As
  a result, sometimes the dlopen would fail and return 1 or more
  errors but nobody would notice.  The handle would be returned as
  if the open had succeed, then any use of the handle would segfault
  because handle->loader was NULL.  I have solved this problem by
  capturing the return value in errors, and then checking if errors>0
  in the next if statement.
- fix faulty boolean logic in lt_dlopenext that caused it to only
  search for libraries ending with .la.  Now it says: if try_dlopen
  created a nonzero handle, return it.  Otherwise, if there were
  any errors OTHER THAN file-not-found, return the NULL handle.  If
  the only errors were file-not-found, continue to search.
- just before loading the module in tryall_dlopen, do one final
  call to access() to check for existence of the file.  Without
  this check, you sometimes get the "can't load module" error
  when in fact the problem is "file not found".
This commit is contained in:
Bryce Denney 2002-10-16 02:08:02 +00:00
parent 5d29f481bd
commit f49ec8c71c

View File

@ -1911,6 +1911,15 @@ tryall_dlopen (handle, filename)
cur->info.filename = 0;
}
// Call access() to see if it exists first. If not return FILE_NOT_FOUND
// instead of CANNOT_OPEN.
if (access (cur->info.filename, R_OK) != 0) {
LT_DLFREE (cur->info.filename);
LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));
++errors;
goto done;
}
while (loader)
{
lt_user_data data = loader->dlloader_data;
@ -2875,10 +2884,12 @@ try_dlopen (phandle, filename)
#endif
)))
{
tryall_dlopen (&newhandle, filename);
// Directory component was specified, or all find_handle() calls
// failed to find the lib. This is our last try.
errors = tryall_dlopen (&newhandle, filename);
}
if (!newhandle)
if (!newhandle || errors>0)
{
LT_DLFREE (*phandle);
++errors;
@ -2994,7 +3005,7 @@ lt_dlopenext (filename)
failed, it is better to return an error message here than to
report FILE_NOT_FOUND when the alternatives (foo.so etc) are not
in the module search path. */
if (handle || ((errors > 0) && file_not_found ()))
if (handle || ((errors > 0) && !file_not_found ()))
{
LT_DLFREE (tmp);
@ -3028,7 +3039,7 @@ lt_dlopenext (filename)
/* As before, if the file was found but loading failed, return now
with the current error message. */
if (handle || ((errors > 0) && file_not_found ()))
if (handle || ((errors > 0) && !file_not_found ()))
{
LT_DLFREE (tmp);
// If we're going to return a handle, be sure that has its loader