summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbapt <bapt@FreeBSD.org>2015-12-04 20:41:44 +0000
committerbapt <bapt@FreeBSD.org>2015-12-04 20:41:44 +0000
commit6dbd460022de1cfef40392bcf6220c28674a0a62 (patch)
tree5c3d64ed56284dcd81482690d72ab9ec7ec02ce9
parent8e2550bfa6e2a38ada5b8e583dab62b0f3eb22d9 (diff)
downloadFreeBSD-src-6dbd460022de1cfef40392bcf6220c28674a0a62.zip
FreeBSD-src-6dbd460022de1cfef40392bcf6220c28674a0a62.tar.gz
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
-rw-r--r--usr.bin/xinstall/xinstall.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c
index 15b115a..ae2ab79 100644
--- a/usr.bin/xinstall/xinstall.c
+++ b/usr.bin/xinstall/xinstall.c
@@ -748,10 +748,7 @@ install(const char *from_name, const char *to_name, u_long fset, u_int flags)
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 char *to_name, u_long fset, u_int flags)
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 char *to_name, u_long fset, u_int flags)
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 char *to_name, u_long fset, u_int flags)
/*
* 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 char *to_name, u_long fset, u_int flags)
}
(void) close(temp_fd);
}
- }
-
- if (dostrip && (!docompare || !target))
+ } else if (dostrip)
digestresult = digest_file(tempfile);
/*
OpenPOWER on IntegriCloud