On Feb 8, 2008 11:23 AM, Sergey Poznyakoff <[EMAIL PROTECTED]> wrote:
> Hello,
>
> The alpha version of GNU cpio is available from:
>
>   ftp://alpha.gnu.org/gnu/cpio/cpio-2.9.90.tar.bz2
>
> Regards,
> Sergey


Hello.

I  check the code against patches which we in openSUSE distribution.
I think you forgot to change the type of some variables. You use type
"off_t" elsewhere for variables which represents number of bytes/ file
size.
Attaching patch as cpio-2.9-variable_type.patch.

There are also some patches which you can consider to apply.
For example cpio-2.9-use_new_ascii_format.patch is widely used in
distros like Mandriva, Red Hat and openSUSE.
cpio-2.9-doc_typo.patch: This patch appeared in this mailing list some
time ago.
cpio-2.9-avoid_overflow_warning.patch: Gcc complaints about overflow.
I don't know why this hack in the code was used, but IMHO it can be
done in way which is more clear what is written where.
Last but not least:
cpio-2.9-chmodRaceC.patch:  This one comes from Red Hat and fixes
security issue connected to CAN-2005-1111 in cpio version 2.9.

Thank you.
Regards Ladislav.
--- src/extern.h
+++ src/extern.h
@@ -166,7 +166,7 @@
 void copy_files_tape_to_disk (int in_des, int out_des, off_t num_bytes);
 void copy_files_disk_to_tape (int in_des, int out_des, off_t num_bytes, char *filename);
 void copy_files_disk_to_disk (int in_des, int out_des, off_t num_bytes, char *filename);
-void warn_if_file_changed (char *file_name, unsigned long old_file_size,
+void warn_if_file_changed (char *file_name, off_t old_file_size,
                            time_t old_file_mtime);
 void create_all_directories (char *name);
 void prepare_append (int out_file_des);
--- src/util.c
+++ src/util.c
@@ -527,8 +527,8 @@
 copy_files_disk_to_disk (int in_des, int out_des, off_t num_bytes,
 			 char *filename)
 {
-  long size;
-  long k;
+  off_t size;
+  off_t k;
   off_t original_num_bytes;
   int rc;
 
@@ -569,7 +569,7 @@
 /* Warn if file changed while it was being copied.  */
 
 void
-warn_if_file_changed (char *file_name, unsigned long old_file_size,
+warn_if_file_changed (char *file_name, off_t old_file_size,
 		      time_t old_file_mtime)
 {
   struct stat new_file_stat;
--- doc/cpio.info
+++ doc/cpio.info	2005/04/25 12:11:02
@@ -262,7 +262,8 @@
      Set the I/O block size to BLOCK-SIZE * 512 bytes.
 
 `-c'
-     Use the old portable (ASCII) archive format.
+     Identical to "-H newc", use the new (SVR4) portable format.
+     If you wish the old portable (ASCII) archive format, use "-H odc" instead.
 
 `-C IO-SIZE, --io-size=IO-SIZE'
      Set the I/O block size to IO-SIZE bytes.
--- src/main.c
+++ src/main.c
@@ -337,6 +337,7 @@
     case 'c':		/* Use the old portable ASCII format.  */
       if (archive_format != arf_unknown)
 	error (0, EXIT_FAILURE, _("Archive format multiply defined"));
+#define        SVR4_COMPAT
 #ifdef SVR4_COMPAT
       archive_format = arf_newascii; /* -H newc.  */
 #else
--- doc/cpio.texi
+++ doc/cpio.texi
@@ -234,7 +234,7 @@ unreadable.
 cpio @{-o|[EMAIL PROTECTED] [-0acvABLV] [-C bytes] [-H format]
 [-M message] [-O [[user@@]host:]archive] [-F [[user@@]host:]archive]
 [--file=[[user@@]host:]archive] [--format=format]
-[--message=message][--null] [--reset-access-time] [--verbose]
+[--message=message] [--null] [--reset-access-time] [--verbose]
 [--dot] [--append] [--block-size=blocks] [--dereference]
 [--io-size=bytes] [--rsh-command=command] [--help] [--version]
 < name-list [> archive]
--- src/tar.c
+++ src/tar.c
@@ -217,7 +217,7 @@
       char *name;
 
       strncpy (tar_hdr->magic, TMAGIC, TMAGLEN);
-      strncpy (tar_hdr->magic + TMAGLEN, TVERSION, TVERSLEN);
+      strncpy (tar_hdr->version, TVERSION, TVERSLEN);
 
       name = getuser (file_hdr->c_uid);
       if (name)
--- src/copypass.c
+++ src/copypass.c
@@ -239,15 +239,23 @@ process_copy_pass ()
 		  cdf_flag = 1;
 		}
 #endif
-	      res = mkdir (output_name.ds_string, in_file_stat.st_mode);
+	      res = mkdir (output_name.ds_string, in_file_stat.st_mode & ~077);
 
 	    }
 	  else
-	    res = 0;
+            {
+              if (!no_chown_flag && (out_file_stat.st_mode & 077) != 0
+                  && chmod (output_name.ds_string, out_file_stat.st_mode & 07700) < 0)
+                {
+                  error (0, errno, "%s: chmod", output_name.ds_string);
+                  continue;
+                }
+              res = 0;
+            }
 	  if (res < 0 && create_dir_flag)
 	    {
 	      create_all_directories (output_name.ds_string);
-	      res = mkdir (output_name.ds_string, in_file_stat.st_mode);
+	      res = mkdir (output_name.ds_string, in_file_stat.st_mode & ~077);
 	    }
 	  if (res < 0)
 	    {
@@ -290,12 +298,12 @@ process_copy_pass ()
 
 	  if (link_res < 0)
 	    {
-	      res = mknod (output_name.ds_string, in_file_stat.st_mode,
+	      res = mknod (output_name.ds_string, in_file_stat.st_mode & ~077,
 			   in_file_stat.st_rdev);
 	      if (res < 0 && create_dir_flag)
 		{
 		  create_all_directories (output_name.ds_string);
-		  res = mknod (output_name.ds_string, in_file_stat.st_mode,
+		  res = mknod (output_name.ds_string, in_file_stat.st_mode & ~077,
 			       in_file_stat.st_rdev);
 		}
 	      if (res < 0)
--- src/copyin.c
+++ src/copyin.c
@@ -186,11 +186,12 @@ list_file(struct cpio_file_stat* file_hd
 
 static int
 try_existing_file (struct cpio_file_stat* file_hdr, int in_file_des,
-		   int *existing_dir)
+		   int *existing_dir, mode_t *existing_mode)
 {
   struct stat file_stat;
 
   *existing_dir = false;
+  *existing_mode = 0;
   if (lstat (file_hdr->c_name, &file_stat) == 0)
     {
       if (S_ISDIR (file_stat.st_mode)
@@ -200,6 +201,7 @@ try_existing_file (struct cpio_file_stat
 	     we are trying to create, don't complain about
 	     it.  */
 	  *existing_dir = true;
+	  *existing_mode = file_stat.st_mode;
 	  return 0;
 	}
       else if (!unconditional_flag
@@ -567,7 +569,7 @@ copyin_regular_file (struct cpio_file_st
 }
 
 static void
-copyin_directory (struct cpio_file_stat *file_hdr, int existing_dir)
+copyin_directory (struct cpio_file_stat *file_hdr, int existing_dir, mode_t existing_mode)
 {
   int res;			/* Result of various function calls.  */
 #ifdef HPUX_CDF
@@ -610,14 +612,22 @@ copyin_directory (struct cpio_file_stat 
 	  cdf_flag = 1;
 	}
 #endif
-      res = mkdir (file_hdr->c_name, file_hdr->c_mode);
+      res = mkdir (file_hdr->c_name, file_hdr->c_mode & ~077);
     }
   else
-    res = 0;
+    {
+      if (!no_chown_flag && (existing_mode & 077) != 0
+         && chmod (file_hdr->c_name, existing_mode & 07700) < 0)
+       {
+         error (0, errno, "%s: chmod", file_hdr->c_name);
+         return;
+       }
+      res = 0;
+    }
   if (res < 0 && create_dir_flag)
     {
       create_all_directories (file_hdr->c_name);
-      res = mkdir (file_hdr->c_name, file_hdr->c_mode);
+      res = mkdir (file_hdr->c_name, file_hdr->c_mode & ~077);
     }
   if (res < 0)
     {
@@ -692,12 +702,12 @@ copyin_device (struct cpio_file_stat* fi
       return;
     }
   
-  res = mknod (file_hdr->c_name, file_hdr->c_mode,
+  res = mknod (file_hdr->c_name, file_hdr->c_mode & ~077,
 	    makedev (file_hdr->c_rdev_maj, file_hdr->c_rdev_min));
   if (res < 0 && create_dir_flag)
     {
       create_all_directories (file_hdr->c_name);
-      res = mknod (file_hdr->c_name, file_hdr->c_mode,
+      res = mknod (file_hdr->c_name, file_hdr->c_mode & ~077,
 	    makedev (file_hdr->c_rdev_maj, file_hdr->c_rdev_min));
     }
   if (res < 0)
@@ -772,9 +782,10 @@ static void
 copyin_file (struct cpio_file_stat* file_hdr, int in_file_des)
 {
   int existing_dir=0;
+  mode_t existing_mode;
 
   if (!to_stdout_option
-      && try_existing_file (file_hdr, in_file_des, &existing_dir) < 0)
+      && try_existing_file (file_hdr, in_file_des, &existing_dir, &existing_mode) < 0)
     return;
 
   /* Do the real copy or link.  */
@@ -785,7 +796,7 @@ copyin_file (struct cpio_file_stat* file
       break;
 
     case CP_IFDIR:
-      copyin_directory (file_hdr, existing_dir);
+      copyin_directory(file_hdr, existing_dir, existing_mode);
       break;
 
     case CP_IFCHR:
_______________________________________________
Bug-cpio mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-cpio

Reply via email to