diff --git a/ChangeLog b/ChangeLog index a0cc91b..da81541 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-06-25 Paolo Bonzini + + * execute.c: Do not copy ACLs until the file is copied. + * utils.c (ck_mkstemp): Set a restrictive umask on temporary files. + 2009-06-25 Paolo Bonzini * autoboot.conf: Add selinux-h. diff --git a/sed/execute.c b/sed/execute.c index 14f8ccc..bfa6388 100644 --- a/sed/execute.c +++ b/sed/execute.c @@ -769,9 +769,6 @@ open_next_file(name, input) if (fchown (output_fd, st.st_uid, st.st_gid) == -1) fchown (output_fd, -1, st.st_gid); #endif - copy_acl (input->in_file_name, input_fd, - input->out_file_name, output_fd, - st.st_mode); } else output_file.fp = stdout; @@ -791,9 +788,17 @@ closedown(input) if (in_place_extension && output_file.fp != NULL) { const char *target_name; - ck_fclose (output_file.fp); + int input_fd, output_fd; target_name = input->in_file_name; + input_fd = fileno (input->fp); + output_fd = fileno (output_file.fp); + copy_acl (input->in_file_name, input_fd, + input->out_file_name, output_fd, + st.st_mode); + + ck_fclose (input->fp); + ck_fclose (output_file.fp); if (strcmp(in_place_extension, "*") != 0) { char *backup_file_name = get_backup_file_name(target_name); @@ -804,8 +809,9 @@ closedown(input) ck_rename (input->out_file_name, target_name, input->out_file_name); free (input->out_file_name); } + else + ck_fclose (input->fp); - ck_fclose (input->fp); input->fp = NULL; } diff --git a/sed/utils.c b/sed/utils.c index bf6c6f9..37ec491 100644 --- a/sed/utils.c +++ b/sed/utils.c @@ -200,6 +200,7 @@ ck_mkstemp (p_filename, tmpdir, base) char *template; FILE *fp; int fd; + int save_umask; if (tmpdir == NULL) tmpdir = getenv("TMPDIR"); @@ -217,7 +218,11 @@ ck_mkstemp (p_filename, tmpdir, base) template = xmalloc (strlen (tmpdir) + strlen (base) + 8); sprintf (template, "%s/%sXXXXXX", tmpdir, base); + /* The ownership might change, so omit some permissions at first + so unauthorized users cannot nip in before the file is ready. */ + save_umask = umask (8r700); fd = mkstemp (template); + umask (save_umask); if (fd == -1) panic(_("couldn't open temporary file %s: %s"), template, strerror(errno));