libtool-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

libtool-1.4.2: some bugfixes in ltdl.c


From: Alexander Bluhm
Subject: libtool-1.4.2: some bugfixes in ltdl.c
Date: Thu, 7 Mar 2002 19:51:28 +0100
User-agent: Mutt/1.3.16i

Hi, 

I have discovered some bugs in ltdl.c of libtool-1.4.2. All patches
are against version 1.4.2. They can be applied in any order as they 
do not depend on each other. If you have any questions feel free to
mail me as I am not on this mailing list.

Alexander



2002-03-07  Alexander Bluhm  <address@hidden>
        * libltdl/ltdl.c (find_module): tryall_dlopen_module 
          must not be called with an invalid dirname argument.
          If dir is 0 use tryall_dlopen instead of tryall_dlopen_module

diff -ru libtool-1.4.2.orig/libltdl/ltdl.c libtool-1.4.2/libltdl/ltdl.c
--- libtool-1.4.2.orig/libltdl/ltdl.c   Tue Sep 11 04:02:07 2001
+++ libtool-1.4.2/libltdl/ltdl.c        Fri Mar  1 23:14:30 2002
@@ -2020,11 +2020,17 @@
        }
 
       /* maybe it was moved to another directory */
-      {
+      if( dir )
+       {
          if (tryall_dlopen_module (handle,
                                    (const char *) 0, dir, dlname) == 0)
            return 0;
-      }
+       }
+      else
+       {
+         if (tryall_dlopen (handle, dlname) == 0)
+           return 0;
+       }
     }
 
   return 1;



2002-03-07  Alexander Bluhm  <address@hidden>
        * libltdl/ltdl.c (lt_dlloader_add): Fixed error handling.
          If place does not exist in loaders list the for loop
          terminates and the error is reported.

diff -ru libtool-1.4.2.orig/libltdl/ltdl.c libtool-1.4.2/libltdl/ltdl.c
--- libtool-1.4.2.orig/libltdl/ltdl.c   Tue Sep 11 04:02:07 2001
+++ libtool-1.4.2/libltdl/ltdl.c        Fri Mar  1 19:28:31 2002
@@ -3812,7 +3812,7 @@
   else
     {
       /* Find the node immediately preceding PLACE. */
-      for (ptr = loaders; ptr->next != place; ptr = ptr->next)
+      for (ptr = loaders; ptr->next && ptr->next != place; ptr = ptr->next)
        {
          /*NOWORK*/;
        }



2002-03-07  Alexander Bluhm  <address@hidden>
        * libltdl/ltdl.c (lt_dlopenext): try_dlopen does not set the handle
          to 0 in case of an error. So it is replaced it with lt_dlopen.
        * libltdl/ltdl.c (lt_dlopenext): According to the comment 
          searching should be stopped if the error is not FILE_NOT_FOUND. 

diff -ru libtool-1.4.2.orig/libltdl/ltdl.c libtool-1.4.2/libltdl/ltdl.c
--- libtool-1.4.2.orig/libltdl/ltdl.c   Tue Sep 11 04:02:07 2001
+++ libtool-1.4.2/libltdl/ltdl.c        Thu Mar  7 17:06:09 2002
@@ -2922,8 +2922,6 @@
   char *       tmp             = 0;
   char *       ext             = 0;
   int          len;
-  int          errors          = 0;
-  int          file_found      = 1; /* until proven otherwise */
 
   if (!filename)
     {
@@ -2953,14 +2951,14 @@
 
   strcpy (tmp, filename);
   strcat (tmp, archive_ext);
-  errors = try_dlopen (&handle, tmp);
+  handle = lt_dlopen (tmp);
 
   /* If we found FILENAME, stop searching -- whether we were able to
      load the file as a module or not.  If the file exists but loading
      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 || !file_not_found ())
     {
       LT_DLFREE (tmp);
       return handle;
@@ -2983,11 +2981,11 @@
     }
 
   strcat(tmp, shlib_ext);
-  errors = try_dlopen (&handle, tmp);
+  handle = lt_dlopen (tmp);
 
   /* 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 || !file_not_found ())
     {
       LT_DLFREE (tmp);
       return handle;



2002-03-07  Alexander Bluhm  <address@hidden>
        * libltdl/ltdl.c (lt_dlpath_insertdir): It is important
          that only the canonicalized dir is added to ppath.
          Although dir gets canonicalized the original was added.

diff -ru libtool-1.4.2.orig/libltdl/ltdl.c libtool-1.4.2/libltdl/ltdl.c
--- libtool-1.4.2.orig/libltdl/ltdl.c   Tue Sep 11 04:02:07 2001
+++ libtool-1.4.2/libltdl/ltdl.c        Sun Mar  3 03:43:02 2002
@@ -3465,7 +3465,7 @@
       before = before - *ppath + argz;
     }
 
-  if (lt_argz_insert (&argz, &argz_len, before, dir) != 0)
+  if (lt_argz_insert (&argz, &argz_len, before, canonical) != 0)
     {
       ++errors;
       goto cleanup;



2002-03-07  Alexander Bluhm  <address@hidden>
        * libltdl/ltdl.c (trim): Fixed string length calculation.

diff -ru libtool-1.4.2.orig/libltdl/ltdl.c libtool-1.4.2/libltdl/ltdl.c
--- libtool-1.4.2.orig/libltdl/ltdl.c   Tue Sep 11 04:02:07 2001
+++ libtool-1.4.2/libltdl/ltdl.c        Mon Mar  4 17:39:42 2002
@@ -2473,19 +2473,18 @@
   /* remove the leading and trailing "'" from str
      and store the result in dest */
   const char *end   = strrchr (str, '\'');
-  int  len         = LT_STRLEN (str);
   char *tmp;
 
   LT_DLFREE (*dest);
 
-  if (len > 3 && str[0] == '\'')
+  if (end && end-str > 1 && str[0] == '\'')
     {
       tmp = LT_EMALLOC (char, end - str);
       if (!tmp)
        return 1;
 
       strncpy(tmp, &str[1], (end - str) - 1);
-      tmp[len-3] = LT_EOS_CHAR;
+      tmp[(end - str) - 1] = LT_EOS_CHAR;
       *dest = tmp;
     }
   else



2002-03-07  Alexander Bluhm  <address@hidden>
        * libltdl/ltdl.c (try_dlopen): Replaced LT_DLREALLOC 
          with LT_EREALLOC and added error handling.

diff -ru libtool-1.4.2.orig/libltdl/ltdl.c libtool-1.4.2/libltdl/ltdl.c
--- libtool-1.4.2.orig/libltdl/ltdl.c   Tue Sep 11 04:02:07 2001
+++ libtool-1.4.2/libltdl/ltdl.c        Wed Mar  6 17:19:58 2002
@@ -2698,7 +2698,16 @@
             that is longer than the initial buffer size.  */
          while (line[LT_STRLEN(line) -1] != '\n')
            {
-             line = LT_DLREALLOC (char, line, line_len *2);
+             char* p = LT_EREALLOC (char, line, line_len *2);
+             if (!p)
+               {
+                 fclose (file);
+                 LT_DLFREE (line);
+                 free_vars (dlname, old_name, libdir, deplibs);
+                 ++errors;
+                 goto cleanup;
+               }
+             line = p;
              if (!fgets (&line[line_len -1], line_len +1, file))
                {
                  break;



2002-03-07  Alexander Bluhm  <address@hidden>
        * libltdl/ltdl.c (try_dlopen): Fixed memory and 
          file handle leak in case 'goto cleanup;' is executed.

diff -ru libtool-1.4.2.orig/libltdl/ltdl.c libtool-1.4.2/libltdl/ltdl.c
--- libtool-1.4.2.orig/libltdl/ltdl.c   Tue Sep 11 04:02:07 2001
+++ libtool-1.4.2/libltdl/ltdl.c        Wed Mar  6 19:23:50 2002
@@ -2762,6 +2762,9 @@
                  last_libname = lt_estrdup (last_libname + 1);
                  if (!last_libname)
                    {
+                     fclose (file);
+                     LT_DLFREE (line);
+                     free_vars (dlname, old_name, libdir, deplibs);
                      ++errors;
                      goto cleanup;
                    }



2002-03-07  Alexander Bluhm  <address@hidden>
        * libltdl/ltdl.c (try_dlopen): Set newhandle to 0 in case of 
          an error. This provides correct error detection.

diff -ru libtool-1.4.2.orig/libltdl/ltdl.c libtool-1.4.2/libltdl/ltdl.c
--- libtool-1.4.2.orig/libltdl/ltdl.c   Tue Sep 11 04:02:07 2001
+++ libtool-1.4.2/libltdl/ltdl.c        Wed Mar  6 20:12:59 2002
@@ -2523,7 +2523,7 @@
   char *       dir             = 0;
   char *       name            = 0;
   int          errors          = 0;
-  lt_dlhandle  newhandle;
+  lt_dlhandle  newhandle       = 0;
 
   assert (phandle);
   assert (*phandle == 0);
@@ -2847,7 +2847,10 @@
 #endif
                   )))
        {
-         tryall_dlopen (&newhandle, filename);
+         if (tryall_dlopen (&newhandle, filename) != 0)
+           {
+             newhandle = 0;
+           }
        }
 
       if (!newhandle)



2002-03-07  Alexander Bluhm  <address@hidden>
        * libltdl/ltdl.c (try_dlopen): Simplified search_path calculation.

diff -ru libtool-1.4.2.orig/libltdl/ltdl.c libtool-1.4.2/libltdl/ltdl.c
--- libtool-1.4.2.orig/libltdl/ltdl.c   Tue Sep 11 04:02:07 2001
+++ libtool-1.4.2/libltdl/ltdl.c        Mon Mar  4 18:57:52 2002
@@ -2633,17 +2633,14 @@
        yet found) try opening just the module name as passed.  */
       if (!dir)
        {
-         const char *search_path;
-
          LT_DLMUTEX_LOCK ();
-         search_path = user_search_path;
-         if (search_path)
+         if (user_search_path)
            file = find_file (user_search_path, base_name, &dir);
          LT_DLMUTEX_UNLOCK ();
 
          if (!file)
            {
-             search_path = getenv (LTDL_SEARCHPATH_VAR);
+             const char *search_path = getenv (LTDL_SEARCHPATH_VAR);
              if (search_path)
                file = find_file (search_path, base_name, &dir);
            }
@@ -2651,7 +2648,7 @@
 #ifdef LTDL_SHLIBPATH_VAR
          if (!file)
            {
-             search_path = getenv (LTDL_SHLIBPATH_VAR);
+             const char *search_path = getenv (LTDL_SHLIBPATH_VAR);
              if (search_path)
                file = find_file (search_path, base_name, &dir);
            }



2002-03-07  Alexander Bluhm  <address@hidden>
        * libltdl/ltdl.c (tryall_dlopen_module): Too much memory was allocated.
          Now LT_EMALLOC is called with correctly calculated value.

diff -ru libtool-1.4.2.orig/libltdl/ltdl.c libtool-1.4.2/libltdl/ltdl.c
--- libtool-1.4.2.orig/libltdl/ltdl.c   Tue Sep 11 04:02:07 2001
+++ libtool-1.4.2/libltdl/ltdl.c        Fri Mar  1 22:56:26 2002
@@ -1961,7 +1961,7 @@
 
   /* Allocate memory, and combine DIRNAME and MODULENAME into it.
      The PREFIX (if any) is handled below.  */
-  filename  = LT_EMALLOC (char, dirname_len + 1 + filename_len + 1);
+  filename  = LT_EMALLOC (char, filename_len + 1);
   if (!filename)
     return 1;
 



2002-03-07  Alexander Bluhm  <address@hidden>
        * libltdl/ltdl.c (unload_deplibs): Replaced redundant if clause
          with null pointer check.

diff -ru libtool-1.4.2.orig/libltdl/ltdl.c libtool-1.4.2/libltdl/ltdl.c
--- libtool-1.4.2.orig/libltdl/ltdl.c   Tue Sep 11 04:02:07 2001
+++ libtool-1.4.2/libltdl/ltdl.c        Mon Mar  4 12:43:06 2002
@@ -2451,7 +2451,7 @@
   int i;
   int errors = 0;
 
-  if (handle->depcount)
+  if (handle->deplibs)
     {
       for (i = 0; i < handle->depcount; ++i)
        {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]