bab9bb6b69
Create new directories: ceph config config-files filesystem kernel kernel/kernel-modules ldap logging strorage-drivers tools utilities virt Retire directories: connectivity core devtools support extended Delete two packages: tgt irqbalance Relocated packages: base/ dhcp initscripts libevent lighttpd linuxptp memcached net-snmp novnc ntp openssh pam procps sanlock shadow sudo systemd util-linux vim watchdog ceph/ python-cephclient config/ facter puppet-4.8.2 puppet-modules filesystem/ e2fsprogs nfs-utils nfscheck kernel/ kernel-std kernel-rt kernel/kernel-modules/ mlnx-ofa_kernel ldap/ nss-pam-ldapd openldap logging/ syslog-ng logrotate networking/ lldpd iproute mellanox python-ryu mlx4-config python/ python-2.7.5 python-django python-gunicorn python-setuptools python-smartpm python-voluptuous security/ shim-signed shim-unsigned tboot strorage-drivers/ python-3parclient python-lefthandclient virt/ cloud-init libvirt libvirt-python qemu tools/ storage-topology vm-topology utilities/ tis-extensions namespace-utils nova-utils update-motd Change-Id: I37ade764d873c701b35eac5881eb40412ba64a86 Story: 2002801 Task: 22687 Signed-off-by: Scott Little <scott.little@windriver.com>
51 lines
1.5 KiB
Diff
51 lines
1.5 KiB
Diff
From aff4a30807218a52b6b5f200c5aa0eea335547ba Mon Sep 17 00:00:00 2001
|
|
From: Kamil Dudka <kdudka@redhat.com>
|
|
Date: Mon, 17 Oct 2016 17:59:31 +0200
|
|
Subject: [PATCH] createOutputFile: eliminate stat/open TOCTOU race
|
|
|
|
---
|
|
logrotate.c | 15 ++++++++++-----
|
|
1 file changed, 10 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/logrotate.c b/logrotate.c
|
|
index 10f4b52..79f4755 100644
|
|
--- a/logrotate.c
|
|
+++ b/logrotate.c
|
|
@@ -366,11 +366,18 @@ static int runScript(struct logInfo *log, char *logfn, char *script)
|
|
|
|
int createOutputFile(char *fileName, int flags, struct stat *sb, acl_type acl, int force_mode)
|
|
{
|
|
- int fd;
|
|
+ int fd = -1;
|
|
struct stat sb_create;
|
|
int acl_set = 0;
|
|
+ int i;
|
|
+
|
|
+ for (i = 0; i < 2; ++i) {
|
|
+ fd = open(fileName, (flags | O_EXCL | O_NOFOLLOW),
|
|
+ (S_IRUSR | S_IWUSR) & sb->st_mode);
|
|
+
|
|
+ if ((fd >= 0) || (errno != EEXIST))
|
|
+ break;
|
|
|
|
- if (stat(fileName, &sb_create) == 0) {
|
|
/* the destination file already exists, while it should not */
|
|
struct tm now = *localtime(&nowSecs);
|
|
size_t fileName_size = strlen(fileName);
|
|
@@ -384,11 +391,9 @@ int createOutputFile(char *fileName, int flags, struct stat *sb, acl_type acl, i
|
|
fileName, backupName, strerror(errno));
|
|
return -1;
|
|
}
|
|
+ /* existing file renamed, try it once again */
|
|
}
|
|
|
|
- fd = open(fileName, (flags | O_EXCL | O_NOFOLLOW),
|
|
- (S_IRUSR | S_IWUSR) & sb->st_mode);
|
|
-
|
|
if (fd < 0) {
|
|
message(MESS_ERROR, "error creating output file %s: %s\n",
|
|
fileName, strerror(errno));
|
|
--
|
|
1.8.3.1
|
|
|