From 9ab79822418a54c4dff03eefdc036f200e05d1d8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 3 Feb 2022 16:58:06 +0100 Subject: [PATCH] ext/opcache: check mkstemp() return value right after the call Don't call fchmod(-1), which is not only wrong, but also clobbers errno and sets it to EBADF, breaking the following errno access for the log message. --- ext/opcache/zend_shared_alloc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/opcache/zend_shared_alloc.c b/ext/opcache/zend_shared_alloc.c index 53c7b61ff3f3..ad6b69b34613 100644 --- a/ext/opcache/zend_shared_alloc.c +++ b/ext/opcache/zend_shared_alloc.c @@ -83,11 +83,12 @@ void zend_shared_alloc_create_lock(char *lockfile_path) snprintf(lockfile_name, sizeof(lockfile_name), "%s/%sXXXXXX", lockfile_path, SEM_FILENAME_PREFIX); lock_file = mkstemp(lockfile_name); - fchmod(lock_file, 0666); - if (lock_file == -1) { zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Unable to create lock file: %s (%d)", strerror(errno), errno); } + + fchmod(lock_file, 0666); + val = fcntl(lock_file, F_GETFD, 0); val |= FD_CLOEXEC; fcntl(lock_file, F_SETFD, val);