mirror of
https://github.com/php/php-src.git
synced 2024-12-15 12:54:57 +08:00
Fixed symlink("", "somthing") and link("", "somthing") in ZTS mode
This commit is contained in:
parent
8c18516f5a
commit
1f8c608320
@ -481,7 +481,7 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
|
||||
use_cache = ((use_realpath != CWD_EXPAND) && CWDG(realpath_cache_size_limit));
|
||||
|
||||
if (path_length == 0)
|
||||
return (0);
|
||||
return (1);
|
||||
if (path_length >= MAXPATHLEN)
|
||||
return (1);
|
||||
|
||||
@ -769,9 +769,24 @@ CWD_API char *virtual_realpath(const char *path, char *real_path TSRMLS_DC)
|
||||
{
|
||||
cwd_state new_state;
|
||||
char *retval;
|
||||
char cwd[MAXPATHLEN];
|
||||
|
||||
/* realpath("") returns CWD */
|
||||
if (!*path) {
|
||||
new_state.cwd = (char*)malloc(1);
|
||||
new_state.cwd[0] = '\0';
|
||||
new_state.cwd_length = 0;
|
||||
if (VCWD_GETCWD(cwd, MAXPATHLEN)) {
|
||||
path = cwd;
|
||||
}
|
||||
} else if (!IS_ABSOLUTE_PATH(path, strlen(path))) {
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
} else {
|
||||
new_state.cwd = (char*)malloc(1);
|
||||
new_state.cwd[0] = '\0';
|
||||
new_state.cwd_length = 0;
|
||||
}
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
|
||||
if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH)==0) {
|
||||
int len = new_state.cwd_length>MAXPATHLEN-1?MAXPATHLEN-1:new_state.cwd_length;
|
||||
|
||||
@ -1202,7 +1217,15 @@ CWD_API char *tsrm_realpath(const char *path, char *real_path TSRMLS_DC)
|
||||
cwd_state new_state;
|
||||
char cwd[MAXPATHLEN];
|
||||
|
||||
if (!IS_ABSOLUTE_PATH(path, strlen(path)) &&
|
||||
/* realpath("") returns CWD */
|
||||
if (!*path) {
|
||||
new_state.cwd = (char*)malloc(1);
|
||||
new_state.cwd[0] = '\0';
|
||||
new_state.cwd_length = 0;
|
||||
if (VCWD_GETCWD(cwd, MAXPATHLEN)) {
|
||||
path = cwd;
|
||||
}
|
||||
} else if (!IS_ABSOLUTE_PATH(path, strlen(path)) &&
|
||||
VCWD_GETCWD(cwd, MAXPATHLEN)) {
|
||||
new_state.cwd = strdup(cwd);
|
||||
new_state.cwd_length = strlen(cwd);
|
||||
|
@ -135,6 +135,7 @@ PHP_FUNCTION(symlink)
|
||||
}
|
||||
|
||||
if (!expand_filepath(frompath, source_p TSRMLS_CC) || !expand_filepath(topath, dest_p TSRMLS_CC)) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such file or directory");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
@ -185,6 +186,7 @@ PHP_FUNCTION(link)
|
||||
}
|
||||
|
||||
if (!expand_filepath(frompath, source_p TSRMLS_CC) || !expand_filepath(topath, dest_p TSRMLS_CC)) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such file or directory");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,7 @@ echo "Done\n";
|
||||
--CLEAN--
|
||||
<?php
|
||||
unlink(dirname(__FILE__)."/symlink_link_linkinfo_is_link_error1.tmp");
|
||||
@unlink(dirname(__FILE__)."/symlink_link_linkinfo_is_link_link_error1.tmp");
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing symlink() for error conditions ***
|
||||
|
@ -579,7 +579,9 @@ PHPAPI char *expand_filepath(const char *filepath, char *real_path TSRMLS_DC)
|
||||
char cwd[MAXPATHLEN];
|
||||
char *result;
|
||||
|
||||
if (IS_ABSOLUTE_PATH(filepath, strlen(filepath))) {
|
||||
if (!filepath[0]) {
|
||||
return NULL;
|
||||
} else if (IS_ABSOLUTE_PATH(filepath, strlen(filepath))) {
|
||||
cwd[0] = '\0';
|
||||
} else{
|
||||
result = VCWD_GETCWD(cwd, MAXPATHLEN);
|
||||
|
Loading…
Reference in New Issue
Block a user