diff --git a/ext/standard/link.c b/ext/standard/link.c index 0c505864226..8ea64eb5c81 100644 --- a/ext/standard/link.c +++ b/ext/standard/link.c @@ -49,6 +49,7 @@ #include "safe_mode.h" #include "php_link.h" +#include "php_string.h" /* {{{ proto string readlink(string filename) Return the target of a symbolic link */ @@ -116,12 +117,22 @@ PHP_FUNCTION(symlink) int ret; char source_p[MAXPATHLEN]; char dest_p[MAXPATHLEN]; + char dirname[MAXPATHLEN]; + size_t len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &topath, &topath_len, &frompath, &frompath_len) == FAILURE) { return; } + + if (!expand_filepath(frompath, source_p TSRMLS_CC)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such file or directory"); + RETURN_FALSE; + } - if (!expand_filepath(frompath, source_p TSRMLS_CC) || !expand_filepath(topath, dest_p TSRMLS_CC)) { + memcpy(dirname, source_p, sizeof(source_p)); + len = php_dirname(dirname, strlen(dirname)); + + if (!expand_filepath_ex(topath, dest_p, dirname, len TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such file or directory"); RETURN_FALSE; } diff --git a/ext/standard/tests/file/symlink_to_symlink.phpt b/ext/standard/tests/file/symlink_to_symlink.phpt index cf12a1d0b7a..b7554f9bd07 100644 --- a/ext/standard/tests/file/symlink_to_symlink.phpt +++ b/ext/standard/tests/file/symlink_to_symlink.phpt @@ -1,5 +1,11 @@ --TEST-- symlink() using a relative path, and symlink() to a symlink +--SKIPIF-- + --FILE-- --CLEAN-- @@ -74,5 +80,8 @@ Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad) is not bool(false) bool(true) bool(true) +bool(true) +bool(true) +bool(true) *** Finished testing open_basedir configuration [symlink] ***