php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16483 file_exists() results in stat() error
Submitted: 2002-04-08 01:52 UTC Modified: 2002-04-08 03:42 UTC
From: don at blacksun dot org Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4.1.2 OS: FreeBSD 4.5-STABLE
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: don at blacksun dot org
New email:
PHP Version: OS:

 

 [2002-04-08 01:52 UTC] don at blacksun dot org
If you try to stat a file that appears to be in a directory, and that directory is actually a regular file instead, file_exists() throws a stat error instead of just returning false.

Needless to say this makes checking user input a lot more difficult. I am forced to check the entire path to see if each part is a directory before finally checking the last part to see whether it exists.

file_exists() is a function and should either return true or false. If the file exists it should return true. If it does not (for _whatever_ reason) it should return false. Side effects like a stat error are unwanted, and can provide useful information to someone trying to attack the site.

-Don

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-08 01:54 UTC] don at blacksun dot org
Here is the error:

Warning: stat failed for index/nothing (errno=20 - Not a directory) in /usr/local/www/htdocs/support/index.php

"index" is a regular file. A file_exists("index/nothing"); returns a stat error.

-Don
 [2002-04-08 02:21 UTC] derick@php.net
Please verify that this bug is fixed in php4.2.0rc2. You can find it at www.php.net/~derick/

Derick
 [2002-04-08 03:18 UTC] don at blacksun dot org
That fixed the problem.

I appologize. I searched on open instead of all and did not see the other submissions with regard to this error.

Thanks for the help.

-Don
 [2002-04-08 03:42 UTC] sniper@php.net
Fixed -> closed.

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC