php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50371 realpath() returns path to nonexistent file/folder
Submitted: 2009-12-03 12:08 UTC Modified: 2009-12-04 08:21 UTC
From: max at kosyakov dot net Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.2.11 OS: FreeBSD
Private report: No CVE-ID: None
 [2009-12-03 12:08 UTC] max at kosyakov dot net
Description:
------------
realpath() returns path for the folder that does not exists. 

First appeared on php-5.2.8 on FreeBSD 6.1. I have upgraded to php-5.2.1, however the bug persisted

%php -r '$test = "asdfasdf"; var_dump(realpath($test)); var_dump(file_exists(realpath($test)));'
string(27) "/usr/home/kosyakov/asdfasdf"
bool(false)

%php -v
PHP 5.2.11 (cli) (built: Dec  3 2009 17:26:14)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
    with the ionCube PHP Loader v3.1.32, Copyright (c) 2002-2007, by ionCube Ltd.

%uname -imprsv
FreeBSD 6.1-RELEASE FreeBSD 6.1-RELEASE #0: Sun May  7 04:32:43 UTC 2006     root@opus.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386 i386 GENERIC

%more /usr/soft/php-5.2.11/config.nice
#! /bin/sh
#
# Created by configure

'./configure' \
'--with-apxs2=/usr/local/apache2/bin/apxs' \
'--with-mysql=/usr/local/mysql' \
'--with-config-file-path=/usr/local/apache2/conf' \
'--with-gd' \
'--with-png-dir=/usr/local' \
'--with-jpeg-dir=/usr/local' \
'--with-freetype-dir=/usr/local' \
'--with-zlib-dir=/usr' \
'--with-iconv=/usr/local' \
'--enable-ftp' \
'--with-curl=/usr/local' \
'--with-openssl' \
'--enable-soap' \
'--with-pdo-mysql=/usr/local/mysql' \
'--with-mime-magic' \
'--enable-mbstring' \
'--without-sqlite' \
'--with-pdo-sqlite=/usr/local' \
'--enable-bcmath' \
"$@"

Bugs #43060 and #32627 look like the same bug but it is still reproducible.

Reproduce code:
---------------
---
From manual page: function.realpath#Description
---

$test = "asdfasdf"; 
var_dump(realpath($test)); 
var_dump(file_exists(realpath($test)));'


Expected result:
----------------
bool(false)
bool(false)


Actual result:
--------------
string(27) "/usr/home/kosyakov/asdfasdf"
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-03 23:01 UTC] carsten_sttgt at gmx dot de
> %php -r '$test = "asdfasdf"; var_dump(realpath($test));

I guess
| %php -r "var_dump(realpath('/non/existent'));"
is returing false?
 [2009-12-04 04:44 UTC] jani@php.net
Must be some FreeBSD thing since I get false with both calls.
 [2009-12-04 04:45 UTC] jani@php.net
What does this return: 

# php -r 'var_dump(realpath("/non/existent"));'
 [2009-12-04 07:27 UTC] max at kosyakov dot net
Yes, it does return false:

FreeBSD 6.1-RELEASE (GENERIC) #0: Sun May  7 04:32:43 UTC 2006
%php -r "var_dump(realpath('/non/existent'));"
bool(false)
%
 [2009-12-04 07:31 UTC] jani@php.net
And what does this output:

# ls -l /usr/home/kosyakov/asdfasdf

 [2009-12-04 07:32 UTC] jani@php.net
Also, did you notice this note on the manual page http://php.net/realpath

"5.3.0  	 Prior to this release realpath() would not fail on *BSD systems if only the last last path  component did not exist. "

 [2009-12-04 07:40 UTC] max at kosyakov dot net
%ls -l /usr/home/kosyakov/asdfasdf
ls: /usr/home/kosyakov/asdfasdf: No such file or directory

Ok. I'll try to update to 5.3. But is there a way to get it fixed in the 5.2 branch? I need to maintain compatibility of software we develop with php-5.2 and thus need to run this version on our servers.

Thanks for your assistance.
 [2009-12-04 08:21 UTC] jani@php.net
No way to fix in 5.2, the future is 5.3 anyway.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 03:01:31 2024 UTC