changeset 12011:d8660f7d216a

canonicalize: don't lose errno canonicalize-lgpl was already immune; glibc has the same bug: http://sources.redhat.com/bugzilla/show_bug.cgi?id=10635 * lib/canonicalize.c (canonicalize_filename_mode): Protect errno over calls to free. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Wed, 16 Sep 2009 13:51:50 -0600
parents e5fd78d17104
children 556a7580132e
files ChangeLog lib/canonicalize.c
diffstat 2 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2009-09-17  Eric Blake  <ebb9@byu.net>
 
+	canonicalize: don't lose errno
+	* lib/canonicalize.c (canonicalize_filename_mode): Protect errno
+	over calls to free.
+
 	canonicalize: simplify errno handling
 	* lib/canonicalize.c (__set_errno): Delete macro, and use direct
 	assignment.
--- a/lib/canonicalize.c
+++ b/lib/canonicalize.c
@@ -152,6 +152,7 @@
   char const *rname_limit;
   size_t extra_len = 0;
   Hash_table *ht = NULL;
+  int saved_errno;
 
   if (name == NULL)
     {
@@ -239,6 +240,7 @@
 
 	  if (lstat (rname, &st) != 0)
 	    {
+	      saved_errno = errno;
 	      if (can_mode == CAN_EXISTING)
 		goto error;
 	      if (can_mode == CAN_ALL_BUT_LAST && *end)
@@ -259,7 +261,7 @@
 		{
 		  if (can_mode == CAN_MISSING)
 		    continue;
-		  errno = ELOOP;
+		  saved_errno = ELOOP;
 		  goto error;
 		}
 
@@ -268,6 +270,7 @@
 		{
 		  if (can_mode == CAN_MISSING && errno != ENOMEM)
 		    continue;
+		  saved_errno = errno;
 		  goto error;
 		}
 
@@ -303,7 +306,7 @@
 	    {
 	      if (!S_ISDIR (st.st_mode) && *end && (can_mode != CAN_MISSING))
 		{
-		  errno = ENOTDIR;
+		  saved_errno = ENOTDIR;
 		  goto error;
 		}
 	    }
@@ -323,5 +326,6 @@
   free (rname);
   if (ht)
     hash_free (ht);
+  errno = saved_errno;
   return NULL;
 }