]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cp --parents: don't use uninitialized memory when restoring permissions
authorJan Blunck <jblunck@suse.de>
Mon, 7 Jan 2008 11:13:42 +0000 (12:13 +0100)
committerJim Meyering <meyering@redhat.com>
Mon, 7 Jan 2008 11:13:42 +0000 (12:13 +0100)
* src/cp.c (make_dir_parents_private): Always stat each source
directory, in case its permissions are required in re_protect,
when setting permissions of a just-created destination directory.

ChangeLog
src/cp.c

index 29ae607aa3be216dae2d2143f5af566e2b0759dc..435ef43f80402ad01fbe0151aff133a7402e8e8d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-01-07  Jan Blunck  <jblunck@suse.de>
+
+       cp --parents: don't use uninitialized memory when restoring permissions
+       * src/cp.c (make_dir_parents_private): Always stat each source
+       directory, in case its permissions are required in re_protect,
+       when setting permissions of a just-created destination directory.
+
 2008-01-07  Jim Meyering  <meyering@redhat.com>
 
        cp: add a test for today's bug fix.
index 99e1f73ec10dbf92020223b6ae2f45808cd6f9be..be3701fc8c18aa876328acde8eb4cbb039bc67f6 100644 (file)
--- a/src/cp.c
+++ b/src/cp.c
@@ -403,6 +403,7 @@ make_dir_parents_private (char const *const_dir, size_t src_offset,
        slash++;
       while ((slash = strchr (slash, '/')))
        {
+         int src_errno;
          /* Add this directory to the list of directories whose modes need
             fixing later. */
          struct dir_attr *new = xmalloc (sizeof *new);
@@ -412,12 +413,22 @@ make_dir_parents_private (char const *const_dir, size_t src_offset,
          *attr_list = new;
 
          *slash = '\0';
+         src_errno = (stat (src, &new->st) != 0
+                      ? errno
+                      : S_ISDIR (new->st.st_mode)
+                      ? 0
+                      : ENOTDIR);
+         if (src_errno)
+           {
+             error (0, src_errno, _("failed to get attributes of %s"),
+                    quote (src));
+             return false;
+           }
          if (stat (dir, &stats) != 0)
            {
              mode_t src_mode;
              mode_t omitted_permissions;
              mode_t mkdir_mode;
-             int src_errno;
 
              /* This component does not exist.  We must set
                 *new_dst and new->st.st_mode inside this loop because,
@@ -425,17 +436,6 @@ make_dir_parents_private (char const *const_dir, size_t src_offset,
                 make_dir_parents_private creates only e_dir/../a if
                 ./b already exists. */
              *new_dst = true;
-             src_errno = (stat (src, &new->st) != 0
-                          ? errno
-                          : S_ISDIR (new->st.st_mode)
-                          ? 0
-                          : ENOTDIR);
-             if (src_errno)
-               {
-                 error (0, src_errno, _("failed to get attributes of %s"),
-                        quote (src));
-                 return false;
-               }
              src_mode = new->st.st_mode;
 
              /* If the ownership or special mode bits might change,