- fix race condition (#155749)

- use find_lang macro (#155726)
This commit is contained in:
Peter Vrabec 2005-04-25 12:57:44 +00:00
parent a8f28be90f
commit 0005073327
2 changed files with 131 additions and 4 deletions

121
cpio-2.6-chmodRaceC.patch Normal file
View File

@ -0,0 +1,121 @@
--- cpio-2.6/src/copyin.c.chmodRaceC 2005-04-25 13:19:34.079310381 +0200
+++ cpio-2.6/src/copyin.c 2005-04-25 14:09:32.514889697 +0200
@@ -389,19 +389,26 @@
continue;
}
- if (close (out_file_des) < 0)
- error (0, errno, "%s", d->header.c_name);
-
+ /*
+ * Avoid race condition.
+ * Set chown and chmod before closing the file desc.
+ * pvrabec@redhat.com
+ */
+
/* File is now copied; set attributes. */
if (!no_chown_flag)
- if ((chown (d->header.c_name,
+ if ((fchown (out_file_des,
set_owner_flag ? set_owner : d->header.c_uid,
set_group_flag ? set_group : d->header.c_gid) < 0)
&& errno != EPERM)
error (0, errno, "%s", d->header.c_name);
/* chown may have turned off some permissions we wanted. */
- if (chmod (d->header.c_name, (int) d->header.c_mode) < 0)
+ if (fchmod (out_file_des, (int) d->header.c_mode) < 0)
+ error (0, errno, "%s", d->header.c_name);
+
+ if (close (out_file_des) < 0)
error (0, errno, "%s", d->header.c_name);
+
if (retain_time_flag)
{
times.actime = times.modtime = d->header.c_mtime;
@@ -557,6 +564,25 @@
write (out_file_des, "", 1);
delayed_seek_count = 0;
}
+
+ /*
+ * Avoid race condition.
+ * Set chown and chmod before closing the file desc.
+ * pvrabec@redhat.com
+ */
+
+ /* File is now copied; set attributes. */
+ if (!no_chown_flag)
+ if ((fchown (out_file_des,
+ set_owner_flag ? set_owner : file_hdr->c_uid,
+ set_group_flag ? set_group : file_hdr->c_gid) < 0)
+ && errno != EPERM)
+ error (0, errno, "%s", file_hdr->c_name);
+
+ /* chown may have turned off some permissions we wanted. */
+ if (fchmod (out_file_des, (int) file_hdr->c_mode) < 0)
+ error (0, errno, "%s", file_hdr->c_name);
+
if (close (out_file_des) < 0)
error (0, errno, "%s", file_hdr->c_name);
@@ -567,18 +593,6 @@
file_hdr->c_name, crc, file_hdr->c_chksum);
}
- /* File is now copied; set attributes. */
- if (!no_chown_flag)
- if ((chown (file_hdr->c_name,
- set_owner_flag ? set_owner : file_hdr->c_uid,
- set_group_flag ? set_group : file_hdr->c_gid) < 0)
- && errno != EPERM)
- error (0, errno, "%s", file_hdr->c_name);
-
- /* chown may have turned off some permissions we wanted. */
- if (chmod (file_hdr->c_name, (int) file_hdr->c_mode) < 0)
- error (0, errno, "%s", file_hdr->c_name);
-
if (retain_time_flag)
{
struct utimbuf times; /* For setting file times. */
@@ -589,7 +603,7 @@
if (utime (file_hdr->c_name, &times) < 0)
error (0, errno, "%s", file_hdr->c_name);
}
-
+
tape_skip_padding (in_file_des, file_hdr->c_filesize);
if (file_hdr->c_nlink > 1
&& (archive_format == arf_newascii || archive_format == arf_crcascii) )
--- cpio-2.6/src/copypass.c.chmodRaceC 2004-09-06 14:09:04.000000000 +0200
+++ cpio-2.6/src/copypass.c 2005-04-25 14:09:38.135076926 +0200
@@ -181,19 +181,25 @@
}
if (close (in_file_des) < 0)
error (0, errno, "%s", input_name.ds_string);
- if (close (out_file_des) < 0)
- error (0, errno, "%s", output_name.ds_string);
-
+ /*
+ * Avoid race condition.
+ * Set chown and chmod before closing the file desc.
+ * pvrabec@redhat.com
+ */
/* Set the attributes of the new file. */
if (!no_chown_flag)
- if ((chown (output_name.ds_string,
+ if ((fchown (out_file_des,
set_owner_flag ? set_owner : in_file_stat.st_uid,
set_group_flag ? set_group : in_file_stat.st_gid) < 0)
&& errno != EPERM)
error (0, errno, "%s", output_name.ds_string);
/* chown may have turned off some permissions we wanted. */
- if (chmod (output_name.ds_string, in_file_stat.st_mode) < 0)
+ if (fchmod (out_file_des, in_file_stat.st_mode) < 0)
+ error (0, errno, "%s", output_name.ds_string);
+
+ if (close (out_file_des) < 0)
error (0, errno, "%s", output_name.ds_string);
+
if (reset_time_flag)
{
times.actime = in_file_stat.st_atime;

View File

@ -6,7 +6,7 @@
Summary: A GNU archiving program. Summary: A GNU archiving program.
Name: cpio Name: cpio
Version: 2.6 Version: 2.6
Release: 5 Release: 6
License: GPL License: GPL
Group: Applications/Archiving Group: Applications/Archiving
URL: http://www.gnu.org/software/cpio/ URL: http://www.gnu.org/software/cpio/
@ -16,6 +16,7 @@ Patch13: cpio-2.5-nolibnsl.patch
Patch14: cpio-2.6-lfs.patch Patch14: cpio-2.6-lfs.patch
Patch16: cpio-2.6-lstat.patch Patch16: cpio-2.6-lstat.patch
Patch17: cpio-2.6-umask.patch Patch17: cpio-2.6-umask.patch
Patch18: cpio-2.6-chmodRaceC.patch
%ifnos linux %ifnos linux
Prereq: /sbin/rmt Prereq: /sbin/rmt
@ -45,6 +46,7 @@ Install cpio if you need a program to manage file archives.
%patch14 -p1 -b .lfs %patch14 -p1 -b .lfs
%patch16 -p1 -b .lstat %patch16 -p1 -b .lstat
%patch17 -p1 -b .umask %patch17 -p1 -b .umask
%patch18 -p1 -b .chmodRaceC
autoheader autoheader
@ -57,6 +59,7 @@ make
rm -rf ${RPM_BUILD_ROOT} rm -rf ${RPM_BUILD_ROOT}
%makeinstall %makeinstall
%find_lang %{name}
{ cd ${RPM_BUILD_ROOT} { cd ${RPM_BUILD_ROOT}
@ -81,8 +84,8 @@ if [ $1 = 0 ]; then
/sbin/install-info --delete %{_infodir}/cpio.info.gz %{_infodir}/dir /sbin/install-info --delete %{_infodir}/cpio.info.gz %{_infodir}/dir
fi fi
%files %files -f %{name}.lang
%defattr(-,root,root) %defattr(-,root,root,0755)
%doc AUTHORS ChangeLog NEWS README THANKS TODO %doc AUTHORS ChangeLog NEWS README THANKS TODO
%ifnos linux %ifnos linux
@ -92,9 +95,12 @@ fi
%{_mandir}/man*/* %{_mandir}/man*/*
%{_infodir}/*.info* %{_infodir}/*.info*
%{_datadir}/locale/*
%changelog %changelog
* Mon Apr 25 2005 Peter Vrabec <pvrabec@redhat.com> 2.6-6
- fix race condition (#155749)
- use find_lang macro
* Thu Mar 17 2005 Peter Vrabec <pvrabec@redhat.com> * Thu Mar 17 2005 Peter Vrabec <pvrabec@redhat.com>
- rebuild 2.6-5 - rebuild 2.6-5