php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46498 is_writable() returns invalid result
Submitted: 2008-11-05 21:01 UTC Modified: 2009-02-20 01:00 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: registrace at koren dot cz Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 5.2.6 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
40 - 9 = ?
Subscribe to this entry?

 
 [2008-11-05 21:01 UTC] registrace at koren dot cz
Description:
------------
PHP Function is_writable() sometimes reports false results.

Requirements: Linux - getuid() != geteuid()

After inspection of PHP source, I realized, that is_writable() internally uses syscall access(2). In turn,  access(2) man page (on Linux) says:

       The check is done with the calling process’s real UID and  GID,  rather
       than  with  the  effective  IDs  as is done when actually attempting an
       operation.  This is to allow set-user-ID programs to  easily  determine
       the invoking user’s authority.


Reproduce code:
---------------
<?
$file = "testfile.txt";

echo "GetUID: " . posix_getuid() . "/" . posix_geteuid() . "<br />";
echo "file is writable " .  (is_writable($file)?"TRUE":"FALSE") . "<br />";

fopen("testfile.txt", 'wt');
echo ("file created");
?>


Expected result:
----------------
Expected result:

either: 
file is writable TRUE
file created

or
file is writable FALSE
ERROR



Actual result:
--------------
GetUID: 933/10099
file is writable FALSE
file created

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-13 00:13 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-02-20 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2012-11-07 22:46 UTC] nick at all-it dot ru
This bug is 4 years old but nothing done to fix it and use proper functions to check effective access right instead of real... I'm using 5.3 version. Does anybody like to fix it? It is awfully difficult to recompile PHP each time I update it. I can provide patch but not sure whether somebody like to have this bug fixed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 10:01:31 2024 UTC