From: Mikko Koppanen Date: Thu, 24 Dec 2009 13:12:03 +0000 (+0000) Subject: Changed stream_resolve_include_path to use zend_resolve_path X-Git-Tag: php-5.4.0alpha1~191^2~2169 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=523e6096136201b7cbd123e861ffbdc2063dbd66;p=php Changed stream_resolve_include_path to use zend_resolve_path backported stream_resolve_include_path to PHP 5.3 backported stream_resolve_include_path test to PHP 5.3 --- diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index c12fb4afb7..d90e0881ce 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -1668,63 +1668,32 @@ PHP_FUNCTION(stream_encoding) } /* }}} */ -/* {{{ proto string stream_resolve_include_path(string filename[, resource context]) U +/* {{{ proto string stream_resolve_include_path(string filename) U Determine what file will be opened by calls to fopen() with a relative path */ PHP_FUNCTION(stream_resolve_include_path) { - zval **ppfilename, *zcontext = NULL; - char *filename, *ptr = PG(include_path), *end = ptr + (ptr ? strlen(ptr) : 0), buffer[MAXPATHLEN]; + zval **ppz_filename, *pz_context = NULL; + char *filename, *resolved_path; int filename_len; php_stream_context *context = NULL; - struct stat sb; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|r", &ppfilename, &zcontext) == FAILURE || - php_stream_path_param_encode(ppfilename, &filename, &filename_len, REPORT_ERRORS, context = php_stream_context_from_zval(zcontext, 0)) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|r", &ppz_filename, &pz_context) == FAILURE || + php_stream_path_param_encode(ppz_filename, &filename, &filename_len, REPORT_ERRORS, context = php_stream_context_from_zval(pz_context, 0)) == FAILURE) { return; } - while (ptr < end) { - char *s = strchr(ptr, DEFAULT_DIR_SEPARATOR); - UChar *upath; - int upath_len; + resolved_path = zend_resolve_path(filename, filename_len TSRMLS_CC); - if (!s) { - s = end; - } - - if (s == ptr) { - ptr++; - continue; - } - - if ((s - ptr) + 1 + filename_len >= MAXPATHLEN) { - /* Too long to try */ - ptr = s + 1; - continue; - } - - memcpy(buffer, ptr, s - ptr); - buffer[s - ptr] = '/'; - memcpy(buffer + (s - ptr) + 1, filename, filename_len + 1); - - if (php_check_open_basedir_ex(buffer, 0 TSRMLS_CC)) { - ptr = s + 1; - continue; - } - - if (VCWD_STAT(buffer, &sb)) { - ptr = s + 1; - continue; - } - - if (SUCCESS == php_stream_path_decode(NULL, &upath, &upath_len, buffer, (s - ptr) + 1 + filename_len, REPORT_ERRORS, context)) { - RETURN_UNICODEL(upath, upath_len, 0); + if (resolved_path) { + UChar *ustr; + int ulen; + if (SUCCESS == zend_string_to_unicode(UG(utf8_conv), &ustr, &ulen, resolved_path, strlen(resolved_path) TSRMLS_CC)) { + efree(resolved_path); + RETURN_UNICODEL(ustr, ulen, 0); } else { - /* Fallback */ - RETURN_STRINGL(buffer, (s - ptr) + 1 + filename_len, 1); + RETURN_STRINGL(resolved_path, strlen(resolved_path), 1); } } - RETURN_FALSE; } /* }}} */