From: Wayne Davison Date: Fri, 5 Jun 2020 02:47:59 +0000 (-0700) Subject: Make use of O_NOFOLLOW if it is defined. X-Git-Tag: v3.2.0pre1~55 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5d7b71b7a7d76d334b104d2e5127a0d29d36d99c;p=thirdparty%2Frsync.git Make use of O_NOFOLLOW if it is defined. --- diff --git a/clientserver.c b/clientserver.c index d56f5d52..b6067ccb 100644 --- a/clientserver.c +++ b/clientserver.c @@ -1157,11 +1157,17 @@ static void create_pid_file(void) if (!pid_file || !*pid_file) return; +#ifdef O_NOFOLLOW +#define SAFE_OPEN_FLAGS (O_CREAT|O_NOFOLLOW) +#else +#define SAFE_OPEN_FLAGS (O_CREAT) +#endif + /* These tests make sure that a temp-style lock dir is handled safely. */ st1.st_mode = 0; if (do_lstat(pid_file, &st1) == 0 && !S_ISREG(st1.st_mode) && unlink(pid_file) < 0) fail = "unlink"; - else if ((pid_file_fd = do_open(pid_file, O_RDWR|O_CREAT, 0664)) < 0) + else if ((pid_file_fd = do_open(pid_file, O_RDWR|SAFE_OPEN_FLAGS, 0664)) < 0) fail = S_ISREG(st1.st_mode) ? "open" : "create"; else if (!lock_range(pid_file_fd, 0, 4)) fail = "lock";