php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #29005 fopen() can't open NT named pipes on local computer
Submitted: 2004-07-04 00:06 UTC Modified: 2012-01-06 16:25 UTC
Votes:5
Avg. Score:4.8 ± 0.4
Reproduced:5 of 5 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (40.0%)
From: cleong at nflc dot org Assigned: thekid (profile)
Status: Closed Package: *General Issues
PHP Version: 4.3.6 OS: Windows 2000
Private report: No CVE-ID: None
 [2004-07-04 00:06 UTC] cleong at nflc dot org
Description:
------------
fopen() can't handle path names like "\\.\pipe\pipename" because the internal function virtual_file_ex() see the ".\" part, thinks that it means current directory, and promptly removes it.

The manual doesn't mention named pipes but I think this is worth fixing as it will give PHP Win32 a robust interprocess communication mechanism that's fairly easy to implement. The fix is easy enough. Insert the following at line 413 in tsrm_virtual_cwd.c, right after the else if (!IS_DIRECTORY_CURRENT(ptr, ptr_length)) loop:

#ifdef TSRM_WIN32
				/* '.' should be retained if the first two chars are '\' as it stands for local machine
				   done mainly for paths to NT named pipes  (\\.\pipe\pipename) */
			} else if(state->cwd_length == 2 && state->cwd[0] == '\\' && state->cwd[1] == '\\') {
				state->cwd = (char *) realloc(state->cwd, state->cwd_length+ptr_length+1);
				memcpy(&state->cwd[state->cwd_length], ptr, ptr_length+1);
				state->cwd_length += ptr_length;
#endif
			}


Reproduce code:
---------------
Set break point at line 1975 in streams.c

fd = open(realpath, open_flags, 0666);

then run <? readfile('\\\\.\\pipe\\pipename'); ?>. Inspect realpath.

Expected result:
----------------
realpath => \\.\pipe\pipename

Actual result:
--------------
realpath => \\pipe\pipename

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-05 09:49 UTC] derick@php.net
Let's make this a feature request as it's currently not meant to work.
 [2004-07-06 16:32 UTC] pollita@php.net
Indeed, Wez and I both have our eyes on named pipe support.  With luck it'll show up in 5.1, in any case it should be a simple backport to make it available to 5.0 via a PECL extension.
 [2004-07-06 16:47 UTC] cleong at nflc dot org
But it's just a matter of not corrupting the filepath. This is a bug in a way, as, for the same reason, the function cannot handle "\\.\C:\filename.ext", which is a valid Win32 path.
 [2010-01-13 14:08 UTC] bob at peret dot net
I got around this by replacing the "." with my local address

"\\\\.\\pipe\\pipename"

"\\\\127.0.0.1\\pipe\\pipename"
 [2012-01-06 16:25 UTC] thekid@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: thekid
 [2012-01-06 16:25 UTC] thekid@php.net
This has been fixed in PHP 5.3 in the meantime:


$ F:\Programme\php-5.3.0-Win32\php.exe -r 'var_dump(fopen("\\\\.\\pipe\\mysql", 
"r+"));'
resource(5) of type (stream)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 12:01:27 2024 UTC