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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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: Sat Apr 20 00:01:27 2024 UTC