Skip to content

Commit 4fe751e

Browse files
committed
- Tests and small parsing correction for php://fd wrapper
1 parent f732582 commit 4fe751e

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

ext/standard/php_fopen_wrapper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch
265265

266266
start = &path[3];
267267
fildes_ori = strtol(start, &end, 10);
268-
if (end == start || (*end != '\0' && *end != '/')) {
268+
if (end == start || *end != '\0') {
269269
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC,
270270
"php://fd/ stream must be specified in the form php://fd/<orig fd>");
271271
return NULL;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
php://fd wrapper: basic test
3+
--FILE--
4+
<?php
5+
$f = fopen("php://fd/1", "wb");
6+
fwrite($f, "hi!");
7+
8+
echo "\nDone.\n";
9+
--EXPECT--
10+
hi!
11+
Done.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
php://fd wrapper: mode is ignored
3+
--FILE--
4+
<?php
5+
$f = fopen("php://fd/1", "rkkk");
6+
fwrite($f, "hi!");
7+
8+
echo "\nDone.\n";
9+
--EXPECT--
10+
hi!
11+
Done.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
php://fd wrapper: bad syntax
3+
--FILE--
4+
<?php
5+
fopen("php://fd", "w");
6+
fopen("php://fd/", "w");
7+
fopen("php://fd/-2", "w");
8+
fopen("php://fd/1/", "w");
9+
10+
echo "\nDone.\n";
11+
--EXPECTF--
12+
Warning: fopen(): Invalid php:// URL specified in %s on line %d
13+
14+
Warning: fopen(php://fd): failed to open stream: operation failed in %s on line 2
15+
16+
Warning: fopen(php://fd/): failed to open stream: php://fd/ stream must be specified in the form php://fd/<orig fd> in %s on line %d
17+
18+
Warning: fopen(php://fd/-2): failed to open stream: The file descriptors must be non-negative numbers smaller than %d in %s on line %d
19+
20+
Warning: fopen(php://fd/1/): failed to open stream: php://fd/ stream must be specified in the form php://fd/<orig fd> in %s on line %d
21+
22+
Done.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
php://fd wrapper: invalid file descriptor
3+
--SKIPIF--
4+
<?php include('skipif.inc');
5+
if(substr(PHP_OS, 0, 3) == "WIN")
6+
die("skip Not for Windows");
7+
8+
//we'd need a release and a test variation for windows, because in debug builds we get this message:
9+
//Warning: Invalid parameter detected in CRT function '_dup' (f:\dd\vctools\crt_bld\self_x86\crt\src\dup.c:52)
10+
//I greped the CRT sources and found no function capable of validating a file descriptor
11+
12+
--FILE--
13+
<?php
14+
fopen("php://fd/12", "w");
15+
16+
echo "\nDone.\n";
17+
--EXPECTF--
18+
Warning: fopen(php://fd/12): failed to open stream: Error duping file descriptor 12; possibly it doesn't exist: [9]: %s in %s on line %d
19+
20+
Done.

0 commit comments

Comments
 (0)