Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:lmich:SLE
cpio-2.6
cpio-2.6-chmodRaceC.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File cpio-2.6-chmodRaceC.patch of Package cpio-2.6
--- cpio-2.6/src/copyin.c +++ cpio-2.6/src/copyin.c @@ -186,11 +186,12 @@ static int try_existing_file(struct new_cpio_header* 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 @@ 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 @@ -391,19 +393,20 @@ continue; } - if (close (out_file_des) < 0) - error (0, errno, "%s", d->header.c_name); - /* 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; @@ -559,6 +562,19 @@ write (out_file_des, "", 1); delayed_seek_count = 0; } + + /* 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); @@ -569,18 +585,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. */ @@ -591,7 +595,7 @@ if (utime (file_hdr->c_name, ×) < 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) ) @@ -605,7 +609,7 @@ } static void -copyin_directory(struct new_cpio_header* file_hdr, int existing_dir) +copyin_directory(struct new_cpio_header* file_hdr, int existing_dir, mode_t existing_mode) { int res; /* Result of various function calls. */ #ifdef HPUX_CDF @@ -648,14 +652,23 @@ 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; + else + { + 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) { @@ -744,12 +757,12 @@ 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) @@ -828,9 +841,10 @@ copyin_file (struct new_cpio_header* 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. */ @@ -841,7 +855,7 @@ break; case CP_IFDIR: - copyin_directory(file_hdr, existing_dir); + copyin_directory(file_hdr, existing_dir, existing_mode); break; case CP_IFCHR: --- cpio-2.6/src/copypass.c +++ cpio-2.6/src/copypass.c @@ -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; @@ -240,15 +246,24 @@ 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) { @@ -311,12 +326,12 @@ 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)
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor