diff options
author | Felipe Pena <felipe@php.net> | 2008-07-22 14:09:24 +0000 |
---|---|---|
committer | Felipe Pena <felipe@php.net> | 2008-07-22 14:09:24 +0000 |
commit | fdfbfb96a14f46aa7ff457d97e713725c0e69e32 (patch) | |
tree | 966f191df49221395fdda380b986c8e210dab797 /ext/standard | |
parent | cb3bc158076026430722bb408c736496b1c88277 (diff) | |
download | php-git-fdfbfb96a14f46aa7ff457d97e713725c0e69e32.tar.gz |
- MFH: Fixed bug #44246 (closedir() accepts a file resource opened by fopen())
Diffstat (limited to 'ext/standard')
-rw-r--r-- | ext/standard/file.c | 10 | ||||
-rw-r--r-- | ext/standard/fsock.c | 2 | ||||
-rw-r--r-- | ext/standard/proc_open.c | 2 | ||||
-rw-r--r-- | ext/standard/streamsfuncs.c | 9 | ||||
-rw-r--r-- | ext/standard/tests/file/fscanf_variation10.phpt | 2 | ||||
-rw-r--r-- | ext/standard/tests/file/fscanf_variation16.phpt | 2 | ||||
-rw-r--r-- | ext/standard/tests/file/fscanf_variation22.phpt | 2 | ||||
-rw-r--r-- | ext/standard/tests/file/fscanf_variation29.phpt | 2 | ||||
-rw-r--r-- | ext/standard/tests/file/fscanf_variation35.phpt | 2 | ||||
-rw-r--r-- | ext/standard/tests/file/fscanf_variation4.phpt | 2 | ||||
-rw-r--r-- | ext/standard/tests/file/fscanf_variation41.phpt | 2 | ||||
-rw-r--r-- | ext/standard/tests/file/fscanf_variation47.phpt | 2 |
12 files changed, 29 insertions, 10 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c index 40f04b412d..6bc27a8d82 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -856,6 +856,8 @@ PHP_NAMED_FUNCTION(php_if_tmpfile) stream = php_stream_fopen_tmpfile(); if (stream) { + stream->flags |= PHP_STREAM_FLAG_FCLOSE; + php_stream_to_zval(stream, return_value); } else { RETURN_FALSE; @@ -885,6 +887,8 @@ PHP_NAMED_FUNCTION(php_if_fopen) if (stream == NULL) { RETURN_FALSE; } + + stream->flags |= PHP_STREAM_FLAG_FCLOSE; php_stream_to_zval(stream, return_value); } @@ -902,6 +906,12 @@ PHPAPI PHP_FUNCTION(fclose) } PHP_STREAM_TO_ZVAL(stream, &arg1); + + if (!(stream->flags & PHP_STREAM_FLAG_FCLOSE)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a valid stream resource", stream->rsrc_id); + RETURN_FALSE; + } + if (!stream->is_persistent) { zend_list_delete(stream->rsrc_id); } else { diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c index 31774f554c..7fd30f80c0 100644 --- a/ext/standard/fsock.c +++ b/ext/standard/fsock.c @@ -79,6 +79,8 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) stream = php_stream_xport_create(hostname, hostname_len, ENFORCE_SAFE_MODE | REPORT_ERRORS, STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, hashkey, &tv, NULL, &errstr, &err); + stream->flags |= PHP_STREAM_FLAG_FCLOSE; + if (port > 0) { efree(hostname); } diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c index cd4c7b70e0..f6f469a54a 100644 --- a/ext/standard/proc_open.c +++ b/ext/standard/proc_open.c @@ -969,7 +969,7 @@ PHP_FUNCTION(proc_open) zval *retfp; /* nasty hack; don't copy it */ - stream->flags |= PHP_STREAM_FLAG_NO_SEEK; + stream->flags |= PHP_STREAM_FLAG_NO_SEEK | PHP_STREAM_FLAG_FCLOSE; MAKE_STD_ZVAL(retfp); php_stream_to_zval(stream, retfp); diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index dab4044ea9..195e364157 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -126,6 +126,7 @@ PHP_FUNCTION(stream_socket_client) STREAM_XPORT_CLIENT | (flags & PHP_STREAM_CLIENT_CONNECT ? STREAM_XPORT_CONNECT : 0) | (flags & PHP_STREAM_CLIENT_ASYNC_CONNECT ? STREAM_XPORT_CONNECT_ASYNC : 0), hashkey, &tv, context, &errstr, &err); + if (stream == NULL) { /* host might contain binary characters */ @@ -154,6 +155,8 @@ PHP_FUNCTION(stream_socket_client) RETURN_FALSE; } + stream->flags |= PHP_STREAM_FLAG_FCLOSE; + if (errstr) { efree(errstr); } @@ -200,6 +203,8 @@ PHP_FUNCTION(stream_socket_server) stream = php_stream_xport_create(host, host_len, ENFORCE_SAFE_MODE | REPORT_ERRORS, STREAM_XPORT_SERVER | flags, NULL, NULL, context, &errstr, &err); + + stream->flags |= PHP_STREAM_FLAG_FCLOSE; if (stream == NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s (%s)", host, errstr == NULL ? "Unknown error" : errstr); @@ -265,7 +270,9 @@ PHP_FUNCTION(stream_socket_accept) NULL, NULL, &tv, &errstr TSRMLS_CC) && clistream) { - + + clistream->flags |= PHP_STREAM_FLAG_FCLOSE; + if (peername) { ZVAL_STRINGL(zpeername, peername, peername_len, 0); } diff --git a/ext/standard/tests/file/fscanf_variation10.phpt b/ext/standard/tests/file/fscanf_variation10.phpt index 501b937815..a46c112879 100644 --- a/ext/standard/tests/file/fscanf_variation10.phpt +++ b/ext/standard/tests/file/fscanf_variation10.phpt @@ -68,7 +68,7 @@ foreach($float_formats as $float_format) { // closing the resources fclose($fp); -fclose($dfp); +closedir($dfp); echo "\n*** Done ***"; ?> diff --git a/ext/standard/tests/file/fscanf_variation16.phpt b/ext/standard/tests/file/fscanf_variation16.phpt index fb2fd0cd41..8025767bc1 100644 --- a/ext/standard/tests/file/fscanf_variation16.phpt +++ b/ext/standard/tests/file/fscanf_variation16.phpt @@ -67,7 +67,7 @@ foreach($string_formats as $string_format) { // closing the resources fclose($fp); -fclose($dfp); +closedir($dfp); echo "\n*** Done ***"; ?> diff --git a/ext/standard/tests/file/fscanf_variation22.phpt b/ext/standard/tests/file/fscanf_variation22.phpt index 4c551befc5..a3809500a6 100644 --- a/ext/standard/tests/file/fscanf_variation22.phpt +++ b/ext/standard/tests/file/fscanf_variation22.phpt @@ -67,7 +67,7 @@ foreach($char_formats as $char_format) { // closing the resources fclose($fp); -fclose($dfp); +closedir($dfp); echo "\n*** Done ***"; ?> diff --git a/ext/standard/tests/file/fscanf_variation29.phpt b/ext/standard/tests/file/fscanf_variation29.phpt index c5b93e5d86..ce7083bc08 100644 --- a/ext/standard/tests/file/fscanf_variation29.phpt +++ b/ext/standard/tests/file/fscanf_variation29.phpt @@ -68,7 +68,7 @@ foreach($octal_formats as $octal_format) { // closing the resources fclose($fp); -fclose($dfp); +closedir($dfp); echo "\n*** Done ***"; ?> diff --git a/ext/standard/tests/file/fscanf_variation35.phpt b/ext/standard/tests/file/fscanf_variation35.phpt index f6498128cc..1f98bd8f42 100644 --- a/ext/standard/tests/file/fscanf_variation35.phpt +++ b/ext/standard/tests/file/fscanf_variation35.phpt @@ -63,7 +63,7 @@ foreach($hexa_formats as $hexa_format) { // closing the resources fclose($fp); -fclose($dfp); +closedir($dfp); echo "\n*** Done ***"; ?> diff --git a/ext/standard/tests/file/fscanf_variation4.phpt b/ext/standard/tests/file/fscanf_variation4.phpt index dff15309c0..0d9cd9dd43 100644 --- a/ext/standard/tests/file/fscanf_variation4.phpt +++ b/ext/standard/tests/file/fscanf_variation4.phpt @@ -64,7 +64,7 @@ foreach($int_formats as $int_format) { // closing the resources fclose($fp); -fclose($dfp); +closedir($dfp); echo "\n*** Done ***"; ?> diff --git a/ext/standard/tests/file/fscanf_variation41.phpt b/ext/standard/tests/file/fscanf_variation41.phpt index 1591471ddf..080ce98054 100644 --- a/ext/standard/tests/file/fscanf_variation41.phpt +++ b/ext/standard/tests/file/fscanf_variation41.phpt @@ -63,7 +63,7 @@ foreach($unsigned_formats as $unsigned_format) { // closing the resources fclose($fp); -fclose($dfp); +closedir($dfp); echo "\n*** Done ***"; ?> diff --git a/ext/standard/tests/file/fscanf_variation47.phpt b/ext/standard/tests/file/fscanf_variation47.phpt index cda93cb1a6..7010571a42 100644 --- a/ext/standard/tests/file/fscanf_variation47.phpt +++ b/ext/standard/tests/file/fscanf_variation47.phpt @@ -63,7 +63,7 @@ foreach($scientific_formats as $scientific_format) { // closing the resources fclose($fp); -fclose($dfp); +closedir($dfp); echo "\n*** Done ***"; ?> |