cataphract Sat, 11 Dec 2010 01:52:13 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=306215
Log: - Implemented request #26158/bug #53465 (open arbitrary file descriptor with fopen) Bugs: http://bugs.php.net/26158 (Bogus) Open arbitrary file descriptor with fopen http://bugs.php.net/53465 (Assigned) Cannot open file descriptor streams Changed paths: U php/php-src/branches/PHP_5_3/NEWS U php/php-src/branches/PHP_5_3/ext/standard/php_fopen_wrapper.c U php/php-src/trunk/ext/standard/info.c U php/php-src/trunk/ext/standard/php_fopen_wrapper.c Modified: php/php-src/branches/PHP_5_3/NEWS =================================================================== --- php/php-src/branches/PHP_5_3/NEWS 2010-12-11 01:45:51 UTC (rev 306214) +++ php/php-src/branches/PHP_5_3/NEWS 2010-12-11 01:52:13 UTC (rev 306215) @@ -21,6 +21,9 @@ . Fixed bug #53515 (property_exists incorrect on ArrayObject null and 0 values). (Felipe) +- Streams + . Implemented FR #26158 (open arbitrary file descriptor with fopen) + 09 Dec 2010, PHP 5.3.4 - Upgraded bundled Sqlite3 to version 3.7.3. (Ilia) - Upgraded bundled PCRE to version 8.10. (Ilia) Modified: php/php-src/branches/PHP_5_3/ext/standard/php_fopen_wrapper.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/standard/php_fopen_wrapper.c 2010-12-11 01:45:51 UTC (rev 306214) +++ php/php-src/branches/PHP_5_3/ext/standard/php_fopen_wrapper.c 2010-12-11 01:52:13 UTC (rev 306215) @@ -257,6 +257,39 @@ } else { fd = dup(STDERR_FILENO); } + } else if (!strncasecmp(path, "fd/", 3)) { + char *start, + *end; + long fildes_ori; + int dtablesize; + + start = &path[3]; + fildes_ori = strtol(start, &end, 10); + if (end == start || (*end != '\0' && *end != '/')) { + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, + "php://fd/ stream must be specified in the form php://fd/<orig fd>"); + return NULL; + } + +#if HAVE_UNISTD_H + dtablesize = getdtablesize(); +#else + dtablesize = INT_MAX; +#endif + + if (fildes_ori < 0 || fildes_ori >= dtablesize) { + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, + "The file descriptors must be non-negative numbers smaller than %d", dtablesize); + return NULL; + } + + fd = dup(fildes_ori); + if (fd == -1) { + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, + "Error duping file descriptor %d; possibly it doesn't exist: " + "[%d]: %s", fildes_ori, errno, strerror(errno)); + return NULL; + } } else if (!strncasecmp(path, "filter/", 7)) { /* Save time/memory when chain isn't specified */ if (strchr(mode, 'r') || strchr(mode, '+')) { Modified: php/php-src/trunk/ext/standard/info.c =================================================================== --- php/php-src/trunk/ext/standard/info.c 2010-12-11 01:45:51 UTC (rev 306214) +++ php/php-src/trunk/ext/standard/info.c 2010-12-11 01:52:13 UTC (rev 306215) @@ -68,7 +68,7 @@ char *new_str; TSRMLS_FETCH(); - new_str = php_escape_html_entities((char *) str, len, &new_len, 0, ENT_QUOTES, "utf-8" TSRMLS_CC); + new_str = php_escape_html_entities((unsigned char *) str, len, &new_len, 0, ENT_QUOTES, "utf-8" TSRMLS_CC); written = php_output_write(new_str, new_len TSRMLS_CC); efree(new_str); return written; Modified: php/php-src/trunk/ext/standard/php_fopen_wrapper.c =================================================================== --- php/php-src/trunk/ext/standard/php_fopen_wrapper.c 2010-12-11 01:45:51 UTC (rev 306214) +++ php/php-src/trunk/ext/standard/php_fopen_wrapper.c 2010-12-11 01:52:13 UTC (rev 306215) @@ -257,6 +257,39 @@ } else { fd = dup(STDERR_FILENO); } + } else if (!strncasecmp(path, "fd/", 3)) { + char *start, + *end; + long fildes_ori; + int dtablesize; + + start = &path[3]; + fildes_ori = strtol(start, &end, 10); + if (end == start || (*end != '\0' && *end != '/')) { + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, + "php://fd/ stream must be specified in the form php://fd/<orig fd>"); + return NULL; + } + +#if HAVE_UNISTD_H + dtablesize = getdtablesize(); +#else + dtablesize = INT_MAX; +#endif + + if (fildes_ori < 0 || fildes_ori >= dtablesize) { + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, + "The file descriptors must be non-negative numbers smaller than %d", dtablesize); + return NULL; + } + + fd = dup(fildes_ori); + if (fd == -1) { + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, + "Error duping file descriptor %d; possibly it doesn't exist: " + "[%d]: %s", fildes_ori, errno, strerror(errno)); + return NULL; + } } else if (!strncasecmp(path, "filter/", 7)) { /* Save time/memory when chain isn't specified */ if (strchr(mode, 'r') || strchr(mode, '+')) {
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php