From b64119bc54791809b9fc3a225761b1c913fe66bc Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 1 Dec 2007 10:09:57 +0100 Subject: Fix a security race with "cp -p A B" when B already exists. * src/copy.h (struct cp_options): New member owner_privileges. * src/copy.c (USE_ACL): Define to 0 if not defined, for convenience. (owner_failure_ok): New function. (set_owner): Avoid a security-related race by doing an extra chmod first if it looks like there might be trouble right after a chown. Accept a source struct stat rather than a uid and gid, and accept a boolean NEW_DST and destination struct stat. All callers changed. * src/copy.h (cp_options_default): New function, replacing the old chown_privileges. * src/copy.c (cp_options_default): Likewise. * src/cp.c (cp_option_init): Use it. * src/install.c (cp_option_init): Likewise. * src/mv.c (cp_option_init): Likewise. --- src/install.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/install.c') diff --git a/src/install.c b/src/install.c index 802dfcf77..db08751e4 100644 --- a/src/install.c +++ b/src/install.c @@ -163,6 +163,7 @@ static struct option const long_options[] = static void cp_option_init (struct cp_options *x) { + cp_options_default (x); x->copy_as_regular = true; x->dereference = DEREF_ALWAYS; x->unlink_dest_before_opening = true; @@ -170,7 +171,6 @@ cp_option_init (struct cp_options *x) x->hard_link = false; x->interactive = I_UNSPECIFIED; x->move_mode = false; - x->chown_privileges = chown_privileges (); x->one_file_system = false; x->preserve_ownership = false; x->preserve_links = false; -- cgit v1.2.3-54-g00ecf