Skip to content

Commit

Permalink
Fix #78862: link() silently truncates after a null byte on Windows
Browse files Browse the repository at this point in the history
Since link() is supposed to accepts paths (i.e. strings without NUL
bytes), we must not accept arbitrary strings.
  • Loading branch information
cmb69 authored and smalyshev committed Dec 16, 2019
1 parent a5a1596 commit 0e6c065
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/standard/link_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ PHP_FUNCTION(link)

/*First argument to link function is the target and hence should go to frompath
Second argument to link function is the link itself and hence should go to topath */
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &frompath, &frompath_len, &topath, &topath_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "pp", &frompath, &frompath_len, &topath, &topath_len) == FAILURE) {
return;
}

Expand Down
17 changes: 17 additions & 0 deletions ext/standard/tests/file/windows_links/bug78862.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Bug #78862 (link() silently truncates after a null byte on Windows)
--FILE--
<?php
file_put_contents(__DIR__ . '/bug78862.target', 'foo');
var_dump(link(__DIR__ . "/bug78862.target\0more", __DIR__ . "/bug78862.link\0more"));
var_dump(file_exists(__DIR__ . '/bug78862.link'));
?>
--EXPECTF--
Warning: link() expects parameter 1 to be a valid path, string given in %s on line %d
NULL
bool(false)
--CLEAN--
<?php
unlink(__DIR__ . '/bug78862.target');
unlink(__DIR__ . '/bug78862.link');
?>

0 comments on commit 0e6c065

Please sign in to comment.