[wp-trac] [WordPress Trac] #31767: insert_with_markers() is not atomic, leading to corrupted .htaccess updates under race conditions

WordPress Trac noreply at wordpress.org
Fri Oct 2 15:33:12 UTC 2015


#31767: insert_with_markers() is not atomic, leading to corrupted .htaccess updates
under race conditions
---------------------------------+-----------------------
 Reporter:  tigertech            |       Owner:  dd32
     Type:  defect (bug)         |      Status:  assigned
 Priority:  normal               |   Milestone:  4.4
Component:  Filesystem API       |     Version:  4.1.1
 Severity:  critical             |  Resolution:
 Keywords:  has-patch 4.4-early  |     Focuses:
---------------------------------+-----------------------

Comment (by willmot):

 This change causes a broken
 [[https://github.com/humanmade/backupwordpress/blob/master/tests/other/testBackupPath.php#L174|unit
 test]] in one of our plugins.

 Previously `insert_with_markers` would create the file if it didn't
 already exist, now it simply returns `false` if the file doesn't exist.

 This was perhaps an unintended side effect / feature caused by our use of
 [[https://github.com/WordPress/WordPress/blob/4.3.1/wp-
 admin/includes/misc.php#L112|fopen( $filename, 'w' );]]. Switching to
 [[https://github.com/WordPress/WordPress/blob/master/wp-
 admin/includes/misc.php#L116|fopen( $filename, 'r+' );]] means the file is
 no longer created if it doesn't exist. Also the function now bails right
 at the top if the file isn't writable whereas previously it would only
 bail if `file_exists() && ! is_writable()`.

 Here's the where we're calling `insert_with_markers`:
 https://github.com/humanmade/backupwordpress/blob/master/classes/class-
 path.php#L258

 Here's what the function used to look like:
 https://github.com/WordPress/WordPress/blob/4.3.1/wp-
 admin/includes/misc.php#L90-L149

 We can easily fixup our plugin so it doesn't rely on this behaviour, but
 wanted to raise as a bahaviour change anyhow.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/31767#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list