php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26051 filetype() returns wrong type for device drivers
Submitted: 2003-10-31 06:06 UTC Modified: 2003-11-01 06:00 UTC
From: six at t0x dot net Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.4RC3 OS: win2k
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: six at t0x dot net
New email:
PHP Version: OS:

 

 [2003-10-31 06:06 UTC] six at t0x dot net
Description:
------------
As the subject states, filetype() on windows (w2k at least) returns wrong type for device drivers. Actually, it seems to always return the type "file".



Reproduce code:
---------------
<?

// Of course this works with any device name with any extension

echo "type : ".filetype("c:\com1.xxx");

?>

Expected result:
----------------
type : char

Actual result:
--------------
type : file

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-31 08:38 UTC] sniper@php.net
PHP returns whatever the libc stat() function returns for the filetype. No bug.

 [2003-10-31 09:27 UTC] six at t0x dot net
There are specific win32 API calls (GetFileType comes to my mind) to get this kind of information.

I don't think this should be classified as "Bogus" because this is a very confusing behavior, at least, if you don't plan to fix the bug, the documentation should be updated to clearly state that filetype() does not work on Win32.
 [2003-10-31 09:39 UTC] sniper@php.net
filetype() does work just fine on windows. 
If windows returns 'wrong' types, it's not bug in PHP..

 [2003-10-31 10:01 UTC] six at t0x dot net
You seem to assume that the runtime c library is 100% compatible with the unix ones ...

It's not that windows returns wrong types, just that windows provides *another way* to get the file type (the GetFileType API call).

And no, filetype() doesn't work on windows ... At least as it's described in the documentation that says "Returns the type of the file" and not "Wrapper for the stat() libc call".

This is an important problem, because it's currently impossible to protect an app from potential security issues regarding access to critical device files on win32 (like CON, PRN, CLOCK$, ...). A PHP app running on windows, receiving a file name from an untrusted input has *no way* to tell what the file really is.
 [2003-10-31 10:06 UTC] six at t0x dot net
Please consider the security problem stated above before definetly denying this is a bug
 [2003-11-01 06:00 UTC] sniper@php.net
considered. Not PHP bug. Feel free to provide patch to 'fix' this though. But as long as Windows offers the stat() libc func, we use that. If it's not working as it should, it sure is not bug in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC