Skip to content

Commit

Permalink
Merge branch 'PHP-5.5' into PHP-5.6
Browse files Browse the repository at this point in the history
* PHP-5.5:
  improved the fix for bug #66395
  updated NEWS
  Fixed bug #66009 Failed compilation of PHP extension with C++ std library using VS 2012
  • Loading branch information
weltling committed Jan 5, 2014
2 parents 4e7c9ea + 3bde9cf commit e5dd5d0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -1429,14 +1429,27 @@ PHPAPI void php_basename(const char *s, size_t len, char *suffix, size_t sufflen
goto quit_loop;
case 1:
#if defined(PHP_WIN32) || defined(NETWARE)
if (*c == '/' || *c == '\\' || (*c == ':' && (c - s == 1))) {
if (*c == '/' || *c == '\\') {
#else
if (*c == '/') {
#endif
if (state == 1) {
state = 0;
cend = c;
}
#if defined(PHP_WIN32) || defined(NETWARE)
/* Catch relative paths in c:file.txt style. They're not to confuse
with the NTFS streams. This part ensures also, that no drive
letter traversing happens. */
} else if ((*c == ':' && (c - comp == 1))) {
if (state == 0) {
comp = c;
state = 1;
} else {
cend = c;
state = 0;
}
#endif
} else {
if (state == 0) {
comp = c;
Expand Down
36 changes: 36 additions & 0 deletions ext/standard/tests/file/basename_bug66395_variation2-win32.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
basename bug #66395 check drive traversing and NTFS streams
--SKIPIF--
<?php if (substr(PHP_OS, 0, 3) != 'WIN') { die('skip Windows only basename tests'); } ?>
--FILE--
<?php
echo basename("y:") . "\n";
echo basename("y:/") . "\n";
echo basename("notdriveletter:file.txt") . "\n";
echo basename("a:\\b:c:d:hello.txt\\hcd:c.txt") . "\n";
echo basename("a:b:c:d:hello.txt\\d:some.txt") . "\n";
echo basename("a:b:c:d:hello\world\a.bmp\c:d:e:f.txt") . "\n";
echo basename("a:\\b:\\c:d:hello\\world\\a.bmp\\d:e:f:g.txt") . "\n";
echo basename("a:\\b:\\c:d:hello/world\\a.bmp\\d:\\e:\\f:g.txt") . "\n";
echo basename("a:\\b:/c:d:hello\\world:somestream") . "\n";
echo basename("a:\\b:\\c:d:hello\\world:some.stream") . "\n";
echo basename("a:/b:\\c:d:hello\\world:some.stream:\$DATA") . "\n";
echo basename("x:y:z:hello\world:my.stream:\$DATA") . "\n";
echo basename("a:\\b:\\c:d:hello\\world:c:\$DATA") . "\n";
?>
==DONE==
--EXPECTF--
y
y
notdriveletter:file.txt
hcd:c.txt
some.txt
f.txt
g.txt
g.txt
world:somestream
world:some.stream
world:some.stream:$DATA
world:my.stream:$DATA
world:c:$DATA
==DONE==

0 comments on commit e5dd5d0

Please sign in to comment.