This is the mail archive of the cygwin-developers@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

dlopen() & get_full_path_of_dll()


Hi,

First, is there a certain reason, why get_full_path_of_dll() doesn't lookup up
the application directory?

The comment above the function tells me, that it should behave like
LoadLibrary() and this function searches the application directory in the
first place.

If this feature doesn't break with any cygwin philosophy, please apply the
attached patch.

Second, if get_full_path_of_dll() returns NULL, then the variable fullpath in
dlopen() is NULL too. This variable is then passed to LoadLibrary(), which
causes a crash.

The attached patch addresses this issue too, by adding a simple if-statement
around LoadLibrary().

BTW: the patch is against cygwin-1.1.8-2. I know, that this is not 100% what
you expect for suppling a patch, but I was too lazy to look for more recent
source package.

Motivation:
I triggered this bug, while playing with cdrtools-1.10a17. cdrecord want's to
load wnaspi32.dll and has crashed, when the library was not available on the
system, or when the library was not in one of the directories, that were
searched by get_full_path_of_dll().

As I share cdrtools with other people on our local network, I'd like to put
wnaspi32.dll into the directory, where cdrecord.exe resides. After my patch,
cdrecord can be used easily without the need to configure anyones system in a
certain way (setup environment variables, copy libraries, change current
directory, etc.).

Bye.
--
Dipl.-Inform. (FH) Reinhard Nissl
mailto:rnissl@gmx.de
--- dlfcn.cc.orig	Tue Oct 10 01:00:50 2000
+++ dlfcn.cc	Sun Mar 25 21:56:30 2001
@@ -102,6 +102,24 @@
   if (isabspath (str))
     ret = name;
 
+  /* application directory */
+  if (!ret)
+    {
+      if (GetModuleFileName (NULL, buf, MAX_PATH) == 0)
+	small_printf ("WARNING: get_full_path_of_dll can't get module file name win32 %E\n");
+      else
+	{
+	  char *p = strrchr (buf, '\\');
+	  if (!p)
+	    small_printf ("WARNING: get_full_path_of_dll can't extract module path name\n");
+	  else
+	    {
+	      *p = '\0';
+	      ret = check_access (buf, name);
+	    }
+	}
+    }
+
   /* current directory */
   if (!ret)
     {
@@ -177,7 +195,8 @@
     {
       /* handle for the named library */
       const char *fullpath = get_full_path_of_dll (name);
-      ret = (void *) LoadLibrary (fullpath);
+      if (fullpath)
+	ret = (void *) LoadLibrary (fullpath);
     }
 
   if (!ret)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]