From owner-svn-src-all@freebsd.org Fri Dec 4 20:41:46 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 53DE8A41F67; Fri, 4 Dec 2015 20:41:46 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 086A1193A; Fri, 4 Dec 2015 20:41:45 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tB4Kfj9T063935; Fri, 4 Dec 2015 20:41:45 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tB4Kfj7T063934; Fri, 4 Dec 2015 20:41:45 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201512042041.tB4Kfj7T063934@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Fri, 4 Dec 2015 20:41:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r291823 - stable/10/usr.bin/xinstall X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Dec 2015 20:41:46 -0000 Author: bapt Date: Fri Dec 4 20:41:44 2015 New Revision: 291823 URL: https://svnweb.freebsd.org/changeset/base/291823 Log: MFC: r291091 install: do not follow symlinks In case the target of install is a dead symlink, install(1) used to not consider it as "existing" because of the usage of stat(2) instead of lstat(2). meaning the old file (the symlink) is not removed before the new file is created. The symlink is being followed and the new file becoming the target of the symlink instead of the target of install(1) Reviewed by: jhb, brooks Differential Revision: https://reviews.freebsd.org/D4191 Modified: stable/10/usr.bin/xinstall/xinstall.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.bin/xinstall/xinstall.c ============================================================================== --- stable/10/usr.bin/xinstall/xinstall.c Fri Dec 4 20:12:49 2015 (r291822) +++ stable/10/usr.bin/xinstall/xinstall.c Fri Dec 4 20:41:44 2015 (r291823) @@ -748,10 +748,7 @@ install(const char *from_name, const cha devnull = 1; } - if (!dolink) - target = (stat(to_name, &to_sb) == 0); - else - target = (lstat(to_name, &to_sb) == 0); + target = (lstat(to_name, &to_sb) == 0); if (dolink) { if (target && !safecopy) { @@ -766,8 +763,7 @@ install(const char *from_name, const cha return; } - /* Only install to regular files. */ - if (target && !S_ISREG(to_sb.st_mode)) { + if (target && !S_ISREG(to_sb.st_mode) && !S_ISLNK(to_sb.st_mode)) { errno = EFTYPE; warn("%s", to_name); return; @@ -780,7 +776,7 @@ install(const char *from_name, const cha err(EX_OSERR, "%s", from_name); /* If we don't strip, we can compare first. */ - if (docompare && !dostrip && target) { + if (docompare && !dostrip && target && S_ISREG(to_sb.st_mode)) { if ((to_fd = open(to_name, O_RDONLY, 0)) < 0) err(EX_OSERR, "%s", to_name); if (devnull) @@ -832,7 +828,7 @@ install(const char *from_name, const cha /* * Compare the stripped temp file with the target. */ - if (docompare && dostrip && target) { + if (docompare && dostrip && target && S_ISREG(to_sb.st_mode)) { temp_fd = to_fd; /* Re-open to_fd using the real target name. */ @@ -866,9 +862,7 @@ install(const char *from_name, const cha } (void) close(temp_fd); } - } - - if (dostrip && (!docompare || !target)) + } else if (dostrip) digestresult = digest_file(tempfile); /*