GH-21992: ext/standard: Fix symlink trying to resolve dangling links#22024
Draft
zaaarf wants to merge 1 commit into
Draft
GH-21992: ext/standard: Fix symlink trying to resolve dangling links#22024zaaarf wants to merge 1 commit into
zaaarf wants to merge 1 commit into
Conversation
Co-authored-by: Michael Moosbauer <schule@michael-moosbauer.de>
Contributor
There is a --clean-- section you can fill in to clean your tmp symlinks. See if this test works: --TEST--
GH-21992: symlink() must not resolve the final dangling link component
--SKIPIF--
<?php
if (PHP_OS_FAMILY === 'Windows') {
die('skip not for Windows');
}
?>
--FILE--
<?php
$dir = __DIR__ . '/gh21992';
$targetDir = $dir . '/target_dir';
$deadLink = $dir . '/dead_link.txt';
$ghost = $targetDir . '/ghost.txt';
$newTarget = $dir . '/something';
mkdir($dir);
mkdir($targetDir);
var_dump(symlink($ghost, $deadLink));
var_dump(readlink($deadLink));
var_dump(symlink($newTarget, $deadLink));
var_dump(is_link($deadLink));
var_dump(readlink($deadLink));
var_dump(is_link($ghost));
?>
--CLEAN--
<?php
$dir = __DIR__ . '/gh21992';
$targetDir = $dir . '/target_dir';
$deadLink = $dir . '/dead_link.txt';
$ghost = $targetDir . '/ghost.txt';
@unlink($ghost);
@unlink($deadLink);
@rmdir($targetDir);
@rmdir($dir);
?>
--EXPECTF--
bool(true)
string(%d) "%s/gh21992/target_dir/ghost.txt"
Warning: symlink(): File exists in %s on line %d
bool(false)
bool(true)
string(%d) "%s/gh21992/target_dir/ghost.txt"
bool(false) |
Author
Oh cool, thanks, good to know. I'll do it in a bit. |
Contributor
|
You may also need to add a new entry in NEWS and UPGRADING since this is a (minor) bug fix :) |
Author
|
needs a bit of work, found inconsistent behaviour |
devnexen
reviewed
May 12, 2026
| ZEND_PARSE_PARAMETERS_END(); | ||
|
|
||
| if (!expand_filepath(frompath, source_p)) { | ||
| if (!expand_filepath_with_mode(frompath, source_p, NULL, 0, CWD_FILEPATH)) { |
Member
There was a problem hiding this comment.
can you explain the difference (look at the source code) ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Solves the problem described in #21992 (OP phrased it with more detail than I could come up with).
I didn't add a test because testing this problem kind of requires touching machine state (i.e. creating a dangling link somewhere), but let me know if I should still do it.