--- embedaddon/php/ext/standard/link.c 2012/02/21 23:48:02 1.1 +++ embedaddon/php/ext/standard/link.c 2014/06/15 20:03:57 1.1.1.4 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2012 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: link.c,v 1.1 2012/02/21 23:48:02 misho Exp $ */ +/* $Id: link.c,v 1.1.1.4 2014/06/15 20:03:57 misho Exp $ */ #include "php.h" #include "php_filestat.h" @@ -47,7 +47,6 @@ #include #include -#include "safe_mode.h" #include "php_link.h" #include "php_string.h" @@ -64,14 +63,6 @@ PHP_FUNCTION(readlink) return; } - if (strlen(link) != link_len) { - RETURN_FALSE; - } - - if (PG(safe_mode) && !php_checkuid(link, NULL, CHECKUID_CHECK_FILE_AND_DIR)) { - RETURN_FALSE; - } - if (php_check_open_basedir(link TSRMLS_CC)) { RETURN_FALSE; } @@ -94,20 +85,31 @@ PHP_FUNCTION(readlink) PHP_FUNCTION(linkinfo) { char *link; - int link_len; + char *dirname; + int link_len, dir_len; struct stat sb; int ret; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &link, &link_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &link, &link_len) == FAILURE) { return; } + dirname = estrndup(link, link_len); + dir_len = php_dirname(dirname, link_len); + + if (php_check_open_basedir(dirname TSRMLS_CC)) { + efree(dirname); + RETURN_FALSE; + } + ret = VCWD_LSTAT(link, &sb); if (ret == -1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); + efree(dirname); RETURN_LONG(-1L); } + efree(dirname); RETURN_LONG((long) sb.st_dev); } /* }}} */ @@ -124,17 +126,9 @@ PHP_FUNCTION(symlink) char dirname[MAXPATHLEN]; size_t len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &topath, &topath_len, &frompath, &frompath_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pp", &topath, &topath_len, &frompath, &frompath_len) == FAILURE) { return; } - - if (strlen(topath) != topath_len) { - RETURN_FALSE; - } - - if (strlen(frompath) != frompath_len) { - RETURN_FALSE; - } if (!expand_filepath(frompath, source_p TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such file or directory"); @@ -156,14 +150,6 @@ PHP_FUNCTION(symlink) RETURN_FALSE; } - if (PG(safe_mode) && !php_checkuid(dest_p, NULL, CHECKUID_CHECK_FILE_AND_DIR)) { - RETURN_FALSE; - } - - if (PG(safe_mode) && !php_checkuid(source_p, NULL, CHECKUID_CHECK_FILE_AND_DIR)) { - RETURN_FALSE; - } - if (php_check_open_basedir(dest_p TSRMLS_CC)) { RETURN_FALSE; } @@ -196,18 +182,10 @@ PHP_FUNCTION(link) char source_p[MAXPATHLEN]; char dest_p[MAXPATHLEN]; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &topath, &topath_len, &frompath, &frompath_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pp", &topath, &topath_len, &frompath, &frompath_len) == FAILURE) { return; } - if (strlen(topath) != topath_len) { - RETURN_FALSE; - } - - if (strlen(frompath) != frompath_len) { - RETURN_FALSE; - } - 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; @@ -217,14 +195,6 @@ PHP_FUNCTION(link) php_stream_locate_url_wrapper(dest_p, NULL, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC) ) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to link to a URL"); - RETURN_FALSE; - } - - if (PG(safe_mode) && !php_checkuid(dest_p, NULL, CHECKUID_CHECK_FILE_AND_DIR)) { - RETURN_FALSE; - } - - if (PG(safe_mode) && !php_checkuid(source_p, NULL, CHECKUID_CHECK_FILE_AND_DIR)) { RETURN_FALSE; }