Check the relevant path for open_basedir in symlink()

This commit is contained in:
Arnaud Le Blanc 2008-08-11 15:29:06 +00:00
parent e279aa07fe
commit 0ea8978235
3 changed files with 27 additions and 1 deletions

View File

@ -49,6 +49,7 @@
#include "php_link.h"
#include "ext/standard/file.h"
#include "php_string.h"
/* {{{ proto string readlink(string filename) U
Return the target of a symbolic link */
@ -126,6 +127,8 @@ 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, "ZZ", &pp_topath, &pp_frompath) == FAILURE ||
@ -134,7 +137,15 @@ PHP_FUNCTION(symlink)
return;
}
if (!expand_filepath(frompath, source_p TSRMLS_CC) || !expand_filepath(topath, dest_p TSRMLS_CC)) {
if (!expand_filepath(frompath, source_p TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such file or directory");
RETURN_FALSE;
}
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;
}

View File

@ -1,5 +1,11 @@
--TEST--
symlink() using a relative path, and symlink() to a symlink
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip no symlinks on Windows');
}
?>
--FILE--
<?php
$prefix = __FILE__;

View File

@ -31,6 +31,12 @@ $target = ($directory."/test/ok/ok.txt");
var_dump(symlink($target, $symlink));
var_dump(unlink($symlink));
var_dump(mkdir("ok2"));
$symlink = ($directory."/test/ok/ok2/ok.txt");
var_dump(symlink("../ok.txt", $symlink)); // $target == (dirname($symlink)."/".$target) == ($directory."/test/ok/ok.txt");
var_dump(unlink($symlink));
test_open_basedir_after("symlink");
?>
--CLEAN--
@ -74,4 +80,7 @@ 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] ***