From 26fb0778627329180a84b06a1b0504a66474f514 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Fri, 24 Nov 2017 03:04:35 +0000 Subject: [PATCH] Filesystem: Use a more unique filename in `wp_tempnam()` and `get_filesystem_method()`. Using a filename which was generated from `time()` could cause two processes to try to use the same filename, causing unexpected behaviour. Props jrchamp, bikecrazyy. Fixes #42265. git-svn-id: https://develop.svn.wordpress.org/trunk@42224 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/file.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/includes/file.php b/src/wp-admin/includes/file.php index ddee18c687..ccd1a2e240 100644 --- a/src/wp-admin/includes/file.php +++ b/src/wp-admin/includes/file.php @@ -624,7 +624,7 @@ function wp_tempnam( $filename = '', $dir = '' ) { } if ( empty( $filename ) || '.' == $filename || '/' == $filename || '\\' == $filename ) { - $filename = time(); + $filename = uniqid(); } // Use the basename of the given file without the extension as the name for the temporary directory @@ -1466,7 +1466,7 @@ function get_filesystem_method( $args = array(), $context = '', $allow_relaxed_f if ( ! $method ) { - $temp_file_name = $context . 'temp-write-test-' . time(); + $temp_file_name = $context . 'temp-write-test-' . str_replace( '.', '-', uniqid( '', true ) ); $temp_handle = @fopen($temp_file_name, 'w'); if ( $temp_handle ) {