1 --- cpio-2.6/src/copyin.c.chmodRaceC 2005-04-25 13:19:34.079310381 +0200
2 +++ cpio-2.6/src/copyin.c 2005-04-25 14:09:32.514889697 +0200
7 - if (close (out_file_des) < 0)
8 - error (0, errno, "%s", d->header.c_name);
11 + * Avoid race condition.
12 + * Set chown and chmod before closing the file desc.
13 + * pvrabec@redhat.com
16 /* File is now copied; set attributes. */
18 - if ((chown (d->header.c_name,
19 + if ((fchown (out_file_des,
20 set_owner_flag ? set_owner : d->header.c_uid,
21 set_group_flag ? set_group : d->header.c_gid) < 0)
23 error (0, errno, "%s", d->header.c_name);
24 /* chown may have turned off some permissions we wanted. */
25 - if (chmod (d->header.c_name, (int) d->header.c_mode) < 0)
26 + if (fchmod (out_file_des, (int) d->header.c_mode) < 0)
27 + error (0, errno, "%s", d->header.c_name);
29 + if (close (out_file_des) < 0)
30 error (0, errno, "%s", d->header.c_name);
34 times.actime = times.modtime = d->header.c_mtime;
36 write (out_file_des, "", 1);
37 delayed_seek_count = 0;
41 + * Avoid race condition.
42 + * Set chown and chmod before closing the file desc.
43 + * pvrabec@redhat.com
46 + /* File is now copied; set attributes. */
48 + if ((fchown (out_file_des,
49 + set_owner_flag ? set_owner : file_hdr->c_uid,
50 + set_group_flag ? set_group : file_hdr->c_gid) < 0)
52 + error (0, errno, "%s", file_hdr->c_name);
54 + /* chown may have turned off some permissions we wanted. */
55 + if (fchmod (out_file_des, (int) file_hdr->c_mode) < 0)
56 + error (0, errno, "%s", file_hdr->c_name);
58 if (close (out_file_des) < 0)
59 error (0, errno, "%s", file_hdr->c_name);
62 file_hdr->c_name, crc, file_hdr->c_chksum);
65 - /* File is now copied; set attributes. */
67 - if ((chown (file_hdr->c_name,
68 - set_owner_flag ? set_owner : file_hdr->c_uid,
69 - set_group_flag ? set_group : file_hdr->c_gid) < 0)
71 - error (0, errno, "%s", file_hdr->c_name);
73 - /* chown may have turned off some permissions we wanted. */
74 - if (chmod (file_hdr->c_name, (int) file_hdr->c_mode) < 0)
75 - error (0, errno, "%s", file_hdr->c_name);
79 struct utimbuf times; /* For setting file times. */
81 if (utime (file_hdr->c_name, ×) < 0)
82 error (0, errno, "%s", file_hdr->c_name);
86 tape_skip_padding (in_file_des, file_hdr->c_filesize);
87 if (file_hdr->c_nlink > 1
88 && (archive_format == arf_newascii || archive_format == arf_crcascii) )
89 --- cpio-2.6/src/copypass.c.chmodRaceC 2004-09-06 14:09:04.000000000 +0200
90 +++ cpio-2.6/src/copypass.c 2005-04-25 14:09:38.135076926 +0200
93 if (close (in_file_des) < 0)
94 error (0, errno, "%s", input_name.ds_string);
95 - if (close (out_file_des) < 0)
96 - error (0, errno, "%s", output_name.ds_string);
99 + * Avoid race condition.
100 + * Set chown and chmod before closing the file desc.
101 + * pvrabec@redhat.com
103 /* Set the attributes of the new file. */
105 - if ((chown (output_name.ds_string,
106 + if ((fchown (out_file_des,
107 set_owner_flag ? set_owner : in_file_stat.st_uid,
108 set_group_flag ? set_group : in_file_stat.st_gid) < 0)
110 error (0, errno, "%s", output_name.ds_string);
111 /* chown may have turned off some permissions we wanted. */
112 - if (chmod (output_name.ds_string, in_file_stat.st_mode) < 0)
113 + if (fchmod (out_file_des, in_file_stat.st_mode) < 0)
114 + error (0, errno, "%s", output_name.ds_string);
116 + if (close (out_file_des) < 0)
117 error (0, errno, "%s", output_name.ds_string);
121 times.actime = in_file_stat.st_atime;