Make WordPress Core

Ticket #34938: wp_tempnam-too-long-file-name.patch

File wp_tempnam-too-long-file-name.patch, 793 bytes (added by kollega007, 8 years ago)
  • wp-admin/includes/file.php

    diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php
    index e527b2e..536c89d 100644
    a b function wp_tempnam( $filename = '', $dir = '' ) { 
    184184        // Suffix some random data to avoid filename conflicts
    185185        $temp_filename .= '-' . wp_generate_password( 6, false );
    186186        $temp_filename .= '.tmp';
    187         $temp_filename = $dir . wp_unique_filename( $dir, $temp_filename );
    188187
     188        $new_base_name = wp_unique_filename( $dir, $temp_filename );
     189        if ( strlen( $new_base_name ) > 255 ) {
     190                return wp_tempnam( '', $dir);
     191        }
     192
     193        $temp_filename = $dir . $new_base_name;
    189194        $fp = @fopen( $temp_filename, 'x' );
    190195        if ( ! $fp && is_writable( $dir ) && file_exists( $temp_filename ) ) {
    191196                return wp_tempnam( $filename, $dir );