1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
--TEST--
Test fopen() function : variation: interesting paths, no use include path
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) != "WIN")
die("skip Run only on Windows");
if (!is_writable('c:\\')) {
die('skip. C:\\ not writable.');
}
?>
--FILE--
<?php
echo "*** Testing fopen() : variation ***\n";
// fopen with interesting windows paths.
$testdir = __DIR__.'/fopen10.tmpDir';
$rootdir = 'fopen10.tmpdirTwo';
mkdir($testdir);
mkdir('c:\\'.$rootdir);
$unixifiedDir = '/'.substr(str_replace('\\','/',$testdir),3);
$paths = array('c:\\',
'c:',
'c',
'\\',
'/',
'c:'.$rootdir,
'c:adir',
'c:\\/',
'c:\\'.$rootdir.'\\/',
'c:\\'.$rootdir.'\\',
'c:\\'.$rootdir.'/',
$unixifiedDir,
'/sortout');
$file = "fopen_variation10.tmp";
$firstfile = 'c:\\'.$rootdir.'\\'.$file;
$secondfile = $testdir.'\\'.$file;
$thirdfile = 'c:\\'.$file;
$h = fopen($firstfile, 'w');
fwrite($h, "file in $rootdir");
fclose($h);
$h = fopen($secondfile, 'w');
fwrite($h, "file in fopen10.tmpDir");
fclose($h);
$h = fopen($thirdfile, 'w');
fwrite($h, "file in root");
fclose($h);
foreach($paths as $path) {
echo "\n--$path--\n";
$toFind = $path.'\\'.$file;
$h = fopen($toFind, 'r');
if ($h === false) {
echo "file not opened for read\n";
}
else {
fpassthru($h);
echo "\n";
}
fclose($h);
};
unlink($firstfile);
unlink($secondfile);
unlink($thirdfile);
rmdir($testdir);
rmdir('c:\\'.$rootdir);
?>
--EXPECTF--
*** Testing fopen() : variation ***
--c:\--
file in root
--c:--
file in root
--c--
Warning: fopen(c\fopen_variation10.tmp): Failed to open stream: No such file or directory in %s on line %d
file not opened for read
Warning: fclose(): Argument #1 must be of type resource, bool given in %s on line %d
--\--
Warning: fopen(\\fopen_variation10.tmp): Failed to open stream: No such file or directory in %s on line %d
file not opened for read
Warning: fclose(): Argument #1 must be of type resource, bool given in %s on line %d
--/--
Warning: fopen(/\fopen_variation10.tmp): Failed to open stream: No such file or directory in %s on line %d
file not opened for read
Warning: fclose(): Argument #1 must be of type resource, bool given in %s on line %d
--c:fopen10.tmpdirTwo--
file in fopen10.tmpdirTwo
--c:adir--
Warning: fopen(c:adir\fopen_variation10.tmp): Failed to open stream: No such file or directory in %s on line %d
file not opened for read
Warning: fclose(): Argument #1 must be of type resource, bool given in %s on line %d
--c:\/--
file in root
--c:\fopen10.tmpdirTwo\/--
file in fopen10.tmpdirTwo
--c:\fopen10.tmpdirTwo\--
file in fopen10.tmpdirTwo
--c:\fopen10.tmpdirTwo/--
file in fopen10.tmpdirTwo
--%s/fopen10.tmpDir--
file in fopen10.tmpDir
--/sortout--
Warning: fopen(/sortout\fopen_variation10.tmp): Failed to open stream: No such file or directory in %s on line %d
file not opened for read
Warning: fclose(): Argument #1 must be of type resource, bool given in %s on line %d
|