WordPress.org

Make WordPress Core

Opened 8 years ago

Closed 7 years ago

#20365 closed defect (bug) (fixed)

[Patch] Fix getnumchmodfromh

Reported by: Keruspe Owned by: dd32
Milestone: 3.5 Priority: normal
Severity: minor Version: 2.6
Component: Filesystem API Keywords: has-patch commit
Focuses: Cc:
PR Number:

Description

Currently, getnumchmodfromh is wrong

"-rwxrw-r--" is currently translated to

"0421420400" (which is correct),

but then, it's being translated to

0+4+2 1+4+2 0+4+0 and the last 0 is ignored -> 674

when it should be

0 4+2+1 4+2+0 4+0+0 -> 0764

The patch attached solves this issue

Attachments (3)

0001-fix-getnumchmodfromh.patch (1.3 KB) - added by Keruspe 8 years ago.
Patch to fix getnumchmodfromh (strpad on the left to replace "d" or "l" bits)
fs-test.php (989 bytes) - added by dd32 7 years ago.
fs-test.html (136.0 KB) - added by dd32 7 years ago.
output from fs-test.php after 0001-fix-getnumchmodfromh.patch was applied (output modified for plain-text)

Download all attachments as: .zip

Change History (6)

@Keruspe
8 years ago

Patch to fix getnumchmodfromh (strpad on the left to replace "d" or "l" bits)

#1 @kurtpayne
7 years ago

  • Cc kurtpayne added
  • Milestone changed from Awaiting Review to 3.5
  • Severity changed from major to minor
  • Version changed from 3.3.1 to 2.6

Patch looks good.

getnumchmodfromh is responsible for the $struc[permsn] member of the return value from dirlist. This does not appear to be used in core, so it's not currently causing unexpected behavior or data loss. It can be a problem for any plugins / themes that use this, though.

#2 @dd32
7 years ago

  • Keywords commit added

I would personally like to remove this entirely from core.. we don't use it, and I can't find any plugins which do (although, obviously the OP here does). somewhat confusing is that getnumchmodfromh() returns a string representation of an octal number, which is not intuitive at all.

It's also worth noting that getnumchmodfromh() does not work for values > 0777, which it was never designed for, but yet, gethchmod does support.

The problem being triggered here, was that getnumchmodfromh() couldn't handle the executable bit (x) being set, all combinations of r&w worked fine, but introduce x and it would return incorrectly.

Attached is a test script (run it from a web browser in wp-admin/) which can be used to verify the behaviour.

Attached patch worksforme.

@dd32
7 years ago

@dd32
7 years ago

output from fs-test.php after 0001-fix-getnumchmodfromh.patch was applied (output modified for plain-text)

#3 @dd32
7 years ago

  • Owner set to dd32
  • Resolution set to fixed
  • Status changed from new to closed

In [22083]:

Make WP_Filesystem_Base::getnumchmodfromh() return the expected values when the executable bit is set in the input. Props Keruspe. Fixes #20365

Note: See TracTickets for help on using tickets.