felipe Sun, 15 Nov 2009 20:30:57 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=290796
Log: - Fixed bug #49936 (crash with ftp stream in php_stream_context_get_option()) (patch by Pierrick) Bug: http://bugs.php.net/49936 (Assigned) crash with ftp stream in php_stream_context_get_option() Changed paths: U php/php-src/branches/PHP_5_3/NEWS U php/php-src/branches/PHP_5_3/ext/curl/streams.c U php/php-src/branches/PHP_5_3/ext/standard/ftp_fopen_wrapper.c U php/php-src/branches/PHP_5_3/ext/standard/http_fopen_wrapper.c A php/php-src/branches/PHP_5_3/ext/standard/tests/streams/bug49936.phpt U php/php-src/branches/PHP_5_3/main/streams/php_stream_context.h U php/php-src/branches/PHP_5_3/main/streams/streams.c U php/php-src/branches/PHP_5_3/main/streams/transports.c U php/php-src/trunk/ext/curl/streams.c U php/php-src/trunk/ext/standard/ftp_fopen_wrapper.c U php/php-src/trunk/ext/standard/http_fopen_wrapper.c A php/php-src/trunk/ext/standard/tests/streams/bug49936.phpt U php/php-src/trunk/main/streams/php_stream_context.h U php/php-src/trunk/main/streams/streams.c U php/php-src/trunk/main/streams/transports.c
Modified: php/php-src/branches/PHP_5_3/NEWS =================================================================== --- php/php-src/branches/PHP_5_3/NEWS 2009-11-15 18:58:58 UTC (rev 290795) +++ php/php-src/branches/PHP_5_3/NEWS 2009-11-15 20:30:57 UTC (rev 290796) @@ -37,6 +37,8 @@ - Fixed bug #49985 (pdo_pgsql prepare() re-use previous aborted transaction). (ben dot pineau at gmail dot com, Ilia, Matteo) - Fixed bug #49938 (Phar::isBuffering() returns inverted value). (Greg) +- Fixed bug #49936 (crash with ftp stream in php_stream_context_get_option()). + (Pierrick) - Fixed bug #49921 (Curl post upload functions changed). (Ilia) - Fixed bug #49910 (no support for ././@LongLink for long filenames in phar tar support). (Greg) Modified: php/php-src/branches/PHP_5_3/ext/curl/streams.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/curl/streams.c 2009-11-15 18:58:58 UTC (rev 290795) +++ php/php-src/branches/PHP_5_3/ext/curl/streams.c 2009-11-15 20:30:57 UTC (rev 290796) @@ -270,7 +270,7 @@ memset(curlstream, 0, sizeof(php_curl_stream)); stream = php_stream_alloc(&php_curl_stream_ops, curlstream, 0, mode); - php_stream_context_set(stream, context); + php_stream_context_set(stream, context TSRMLS_CC); curlstream->curl = curl_easy_init(); curlstream->multi = curl_multi_init(); Modified: php/php-src/branches/PHP_5_3/ext/standard/ftp_fopen_wrapper.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/standard/ftp_fopen_wrapper.c 2009-11-15 18:58:58 UTC (rev 290795) +++ php/php-src/branches/PHP_5_3/ext/standard/ftp_fopen_wrapper.c 2009-11-15 20:30:57 UTC (rev 290796) @@ -143,7 +143,7 @@ goto connect_errexit; } - php_stream_context_set(stream, context); + php_stream_context_set(stream, context TSRMLS_CC); php_stream_notify_info(context, PHP_STREAM_NOTIFY_CONNECT, NULL, 0); /* Start talking to ftp server */ @@ -550,7 +550,7 @@ goto errexit; } - php_stream_context_set(datastream, context); + php_stream_context_set(datastream, context TSRMLS_CC); php_stream_notify_progress_init(context, 0, file_size); if (use_ssl_on_data && (php_stream_xport_crypto_setup(datastream, @@ -715,7 +715,7 @@ goto opendir_errexit; } - php_stream_context_set(datastream, context); + php_stream_context_set(datastream, context TSRMLS_CC); if (use_ssl_on_data && (php_stream_xport_crypto_setup(stream, STREAM_CRYPTO_METHOD_SSLv23_CLIENT, NULL TSRMLS_CC) < 0 || Modified: php/php-src/branches/PHP_5_3/ext/standard/http_fopen_wrapper.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/standard/http_fopen_wrapper.c 2009-11-15 18:58:58 UTC (rev 290795) +++ php/php-src/branches/PHP_5_3/ext/standard/http_fopen_wrapper.c 2009-11-15 20:30:57 UTC (rev 290796) @@ -245,7 +245,7 @@ eol_detect = stream->flags & (PHP_STREAM_FLAG_DETECT_EOL | PHP_STREAM_FLAG_EOL_MAC); stream->flags &= ~(PHP_STREAM_FLAG_DETECT_EOL | PHP_STREAM_FLAG_EOL_MAC); - php_stream_context_set(stream, context); + php_stream_context_set(stream, context TSRMLS_CC); php_stream_notify_info(context, PHP_STREAM_NOTIFY_CONNECT, NULL, 0); Added: php/php-src/branches/PHP_5_3/ext/standard/tests/streams/bug49936.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/standard/tests/streams/bug49936.phpt (rev 0) +++ php/php-src/branches/PHP_5_3/ext/standard/tests/streams/bug49936.phpt 2009-11-15 20:30:57 UTC (rev 290796) @@ -0,0 +1,21 @@ +--TEST-- +Bug #49936 (crash with ftp stream in php_stream_context_get_option()) +--FILE-- +<?php + +$dir = 'ftp://your:s...@localhost/'; + +var_dump(opendir($dir)); +var_dump(opendir($dir)); + +?> +--EXPECTF-- +Warning: opendir(): connect() failed: Connection refused in %s on line %d + +Warning: opendir(ftp://....@localhost/): failed to open dir: operation failed in %s on line %d +bool(false) + +Warning: opendir(): connect() failed: Connection refused in %s on line %d + +Warning: opendir(ftp://....@localhost/): failed to open dir: operation failed in %s on line %d +bool(false) Property changes on: php/php-src/branches/PHP_5_3/ext/standard/tests/streams/bug49936.phpt ___________________________________________________________________ Added: svn:keywords + Id Rev Revision Added: svn:eol-style + native Modified: php/php-src/branches/PHP_5_3/main/streams/php_stream_context.h =================================================================== --- php/php-src/branches/PHP_5_3/main/streams/php_stream_context.h 2009-11-15 18:58:58 UTC (rev 290795) +++ php/php-src/branches/PHP_5_3/main/streams/php_stream_context.h 2009-11-15 20:30:57 UTC (rev 290796) @@ -95,7 +95,7 @@ BEGIN_EXTERN_C() PHPAPI void php_stream_notification_notify(php_stream_context *context, int notifycode, int severity, char *xmsg, int xcode, size_t bytes_sofar, size_t bytes_max, void * ptr TSRMLS_DC); -PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context); +PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context TSRMLS_DC); END_EXTERN_C() #define php_stream_notify_info(context, code, xmsg, xcode) do { if ((context) && (context)->notifier) { \ Modified: php/php-src/branches/PHP_5_3/main/streams/streams.c =================================================================== --- php/php-src/branches/PHP_5_3/main/streams/streams.c 2009-11-15 18:58:58 UTC (rev 290795) +++ php/php-src/branches/PHP_5_3/main/streams/streams.c 2009-11-15 20:30:57 UTC (rev 290796) @@ -1858,22 +1858,9 @@ php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS TSRMLS_CC, "wrapper does not support stream open"); } else { - /* refcount++ to make sure the context doesn't get destroyed - * if open() fails and stream is closed */ - if (context) { - zend_list_addref(context->rsrc_id); - } - stream = wrapper->wops->stream_opener(wrapper, path_to_open, mode, options ^ REPORT_ERRORS, opened_path, context STREAMS_REL_CC TSRMLS_CC); - - /* if open() succeeded and context was not used, do refcount-- - * XXX if a wrapper didn't actually use context (no way to know that) - * and open() failed, refcount will stay increased */ - if (context && stream && !stream->context) { - zend_list_delete(context->rsrc_id); - } } /* if the caller asked for a persistent stream but the wrapper did not @@ -1971,10 +1958,19 @@ /* }}} */ /* {{{ context API */ -PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context) +PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context TSRMLS_DC) { php_stream_context *oldcontext = stream->context; + stream->context = context; + + if (context) { + zend_list_addref(context->rsrc_id); + } + if (oldcontext) { + zend_list_delete(oldcontext->rsrc_id); + } + return oldcontext; } Modified: php/php-src/branches/PHP_5_3/main/streams/transports.c =================================================================== --- php/php-src/branches/PHP_5_3/main/streams/transports.c 2009-11-15 18:58:58 UTC (rev 290795) +++ php/php-src/branches/PHP_5_3/main/streams/transports.c 2009-11-15 20:30:57 UTC (rev 290796) @@ -134,7 +134,7 @@ context STREAMS_REL_CC TSRMLS_CC); if (stream) { - stream->context = context; + php_stream_context_set(stream, context TSRMLS_CC); if ((flags & STREAM_XPORT_SERVER) == 0) { /* client */ Modified: php/php-src/trunk/ext/curl/streams.c =================================================================== --- php/php-src/trunk/ext/curl/streams.c 2009-11-15 18:58:58 UTC (rev 290795) +++ php/php-src/trunk/ext/curl/streams.c 2009-11-15 20:30:57 UTC (rev 290796) @@ -270,7 +270,7 @@ memset(curlstream, 0, sizeof(php_curl_stream)); stream = php_stream_alloc(&php_curl_stream_ops, curlstream, 0, mode); - php_stream_context_set(stream, context); + php_stream_context_set(stream, context TSRMLS_CC); curlstream->curl = curl_easy_init(); curlstream->multi = curl_multi_init(); Modified: php/php-src/trunk/ext/standard/ftp_fopen_wrapper.c =================================================================== --- php/php-src/trunk/ext/standard/ftp_fopen_wrapper.c 2009-11-15 18:58:58 UTC (rev 290795) +++ php/php-src/trunk/ext/standard/ftp_fopen_wrapper.c 2009-11-15 20:30:57 UTC (rev 290796) @@ -143,7 +143,7 @@ goto connect_errexit; } - php_stream_context_set(stream, context); + php_stream_context_set(stream, context TSRMLS_CC); php_stream_notify_info(context, PHP_STREAM_NOTIFY_CONNECT, NULL, 0); /* Start talking to ftp server */ @@ -551,7 +551,7 @@ goto errexit; } - php_stream_context_set(datastream, context); + php_stream_context_set(datastream, context TSRMLS_CC); php_stream_notify_progress_init(context, 0, file_size); if (use_ssl_on_data && (php_stream_xport_crypto_setup(datastream, @@ -716,7 +716,7 @@ goto opendir_errexit; } - php_stream_context_set(datastream, context); + php_stream_context_set(datastream, context TSRMLS_CC); if (use_ssl_on_data && (php_stream_xport_crypto_setup(stream, STREAM_CRYPTO_METHOD_SSLv23_CLIENT, NULL TSRMLS_CC) < 0 || Modified: php/php-src/trunk/ext/standard/http_fopen_wrapper.c =================================================================== --- php/php-src/trunk/ext/standard/http_fopen_wrapper.c 2009-11-15 18:58:58 UTC (rev 290795) +++ php/php-src/trunk/ext/standard/http_fopen_wrapper.c 2009-11-15 20:30:57 UTC (rev 290796) @@ -288,7 +288,7 @@ eol_detect = stream->flags & (PHP_STREAM_FLAG_DETECT_EOL | PHP_STREAM_FLAG_EOL_MAC); stream->flags &= ~(PHP_STREAM_FLAG_DETECT_EOL | PHP_STREAM_FLAG_EOL_MAC); - php_stream_context_set(stream, context); + php_stream_context_set(stream, context TSRMLS_CC); php_stream_notify_info(context, PHP_STREAM_NOTIFY_CONNECT, NULL, 0); Added: php/php-src/trunk/ext/standard/tests/streams/bug49936.phpt =================================================================== --- php/php-src/trunk/ext/standard/tests/streams/bug49936.phpt (rev 0) +++ php/php-src/trunk/ext/standard/tests/streams/bug49936.phpt 2009-11-15 20:30:57 UTC (rev 290796) @@ -0,0 +1,21 @@ +--TEST-- +Bug #49936 (crash with ftp stream in php_stream_context_get_option()) +--FILE-- +<?php + +$dir = 'ftp://your:s...@localhost/'; + +var_dump(opendir($dir)); +var_dump(opendir($dir)); + +?> +--EXPECTF-- +Warning: opendir(): connect() failed: Connection refused in %s on line %d + +Warning: opendir(ftp://....@localhost/): failed to open dir: operation failed in %s on line %d +bool(false) + +Warning: opendir(): connect() failed: Connection refused in %s on line %d + +Warning: opendir(ftp://....@localhost/): failed to open dir: operation failed in %s on line %d +bool(false) Property changes on: php/php-src/trunk/ext/standard/tests/streams/bug49936.phpt ___________________________________________________________________ Added: svn:keywords + Id Rev Revision Added: svn:eol-style + native Modified: php/php-src/trunk/main/streams/php_stream_context.h =================================================================== --- php/php-src/trunk/main/streams/php_stream_context.h 2009-11-15 18:58:58 UTC (rev 290795) +++ php/php-src/trunk/main/streams/php_stream_context.h 2009-11-15 20:30:57 UTC (rev 290796) @@ -98,7 +98,7 @@ BEGIN_EXTERN_C() PHPAPI void php_stream_notification_notify(php_stream_context *context, int notifycode, int severity, char *xmsg, int xcode, size_t bytes_sofar, size_t bytes_max, void * ptr TSRMLS_DC); -PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context); +PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context TSRMLS_DC); END_EXTERN_C() #define php_stream_notify_info(context, code, xmsg, xcode) do { if ((context) && (context)->notifier) { \ Modified: php/php-src/trunk/main/streams/streams.c =================================================================== --- php/php-src/trunk/main/streams/streams.c 2009-11-15 18:58:58 UTC (rev 290795) +++ php/php-src/trunk/main/streams/streams.c 2009-11-15 20:30:57 UTC (rev 290796) @@ -2422,22 +2422,9 @@ php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS TSRMLS_CC, "wrapper does not support stream open"); } else { - /* refcount++ to make sure the context doesn't get destroyed - * if open() fails and stream is closed */ - if (context) { - zend_list_addref(context->rsrc_id); - } - stream = wrapper->wops->stream_opener(wrapper, path_to_open, implicit_mode, options ^ REPORT_ERRORS, opened_path, context STREAMS_REL_CC TSRMLS_CC); - - /* if open() succeeded and context was not used, do refcount-- - * XXX if a wrapper didn't actually use context (no way to know that) - * and open() failed, refcount will stay increased */ - if (context && stream && !stream->context) { - zend_list_delete(context->rsrc_id); - } } /* if the caller asked for a persistent stream but the wrapper did not @@ -2595,10 +2582,19 @@ /* }}} */ /* {{{ context API */ -PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context) +PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context TSRMLS_DC) { php_stream_context *oldcontext = stream->context; + stream->context = context; + + if (context) { + zend_list_addref(context->rsrc_id); + } + if (oldcontext) { + zend_list_delete(oldcontext->rsrc_id); + } + return oldcontext; } Modified: php/php-src/trunk/main/streams/transports.c =================================================================== --- php/php-src/trunk/main/streams/transports.c 2009-11-15 18:58:58 UTC (rev 290795) +++ php/php-src/trunk/main/streams/transports.c 2009-11-15 20:30:57 UTC (rev 290796) @@ -134,7 +134,7 @@ context STREAMS_REL_CC TSRMLS_CC); if (stream) { - stream->context = context; + php_stream_context_set(stream, context TSRMLS_CC); if ((flags & STREAM_XPORT_SERVER) == 0) { /* client */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php