|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #24185 getcwd() fails if parent directory miss readable-flag
Submitted: 2003-06-14 12:44 UTC Modified: 2004-08-06 09:20 UTC
From: fulcrum at mbnet dot fi Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4CVS-2003-06-14 (stable) OS: NetBSD
Private report: No CVE-ID: None
 [2003-06-14 12:44 UTC] fulcrum at mbnet dot fi
If one of the parent directories of the current working directory doesn't have the readable flag +r (while +x is still specified) getcwd() return false, even though the current directory has full (or at least readable & executale) access (the restrictive permissions apply ONLY to the parent directory).

The possible return value of false isn't either mentioned in the documenation.

Reproduce code:
mkdir one ; mkdir one/two ; mkdir one/two/three
echo "<?php echo gettype(getcwd()).'; '; echo getcwd() ? 'true' : 'false'; ?>" > one/sample.php
echo "<?php echo gettype(getcwd()).'; '; echo getcwd() ? 'true' : 'false'; ?>" > one/two/sample.php
echo "<?php echo gettype(getcwd()).'; '; echo getcwd() ? 'true' : 'false'; ?>" > one/two/three/sample.php
chmod 111 one ; chmod 755 one/two ; chmod 755 one/two/three
chmod 644 one/sample.php ; chmod 644 one/two/sample.php ; chmod 644 one/two/three/sample.php

Expected result:
string; true

string; true

string; true

Actual result:
string; true

boolean; false

boolean; false


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-14 13:44 UTC]
From "man getcwd":

  NULL  on failure (for example, if the current directory    
  is not readable), with errno set accordingly,
  and buf on success.

And as PHP just wraps around this function, the behaviour is the same.

 [2003-06-14 15:14 UTC] fulcrum at mbnet dot fi
I have experienced on two servers, one Linux (unkown distro) server running 4.3.1 and an other unkown UNIX (?) computer with the opposite effect (the effect I was expecting myself). Could this be a OS specific issue?

Anyways the documenation should be clarified.
 [2003-06-14 17:30 UTC]
At least Linux, OpenBSD, AIX, Solaris and HP-UX implementations of getcwd() should behave the same way.
(I didn't test it, just read the man pages I found with google :)

 [2004-08-06 09:20 UTC]
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

This is the case on some unices, and is actually in the
POSIX 1 standard:

In section For each of the following conditions, if
the condition is detected, the getcwd() function shall
return a value of NULL and set errno to the corresponding

    [EACCESS] Read or search permission was denied for a
    component of the pathname.

So I've documented this and the fact that the return value can be false.
 [2020-02-07 06:11 UTC]
Automatic comment on behalf of dave
Log: - Fix #24185.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Aug 07 18:01:27 2020 UTC