Browse Source

MFH: prevent resource leaking when passing invalid stream resource as second argument

PECL_OPENSSL
Antony Dovgal 20 years ago
parent
commit
1a63feffd1
  1. 11
      ext/standard/file.c

11
ext/standard/file.c

@ -571,12 +571,17 @@ PHP_FUNCTION(file_put_contents)
long flags = 0;
zval *zcontext = NULL;
php_stream_context *context = NULL;
php_stream *srcstream;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/|lr!", &filename, &filename_len,
&data, &flags, &zcontext) == FAILURE) {
return;
}
if (Z_TYPE_P(data) == IS_RESOURCE) {
php_stream_from_zval(srcstream, &data);
}
context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT);
stream = php_stream_open_wrapper_ex(filename, (flags & PHP_FILE_APPEND) ? "ab" : "wb",
@ -591,14 +596,8 @@ PHP_FUNCTION(file_put_contents)
switch (Z_TYPE_P(data)) {
case IS_RESOURCE:
{
php_stream *srcstream;
php_stream_from_zval(srcstream, &data);
numbytes = php_stream_copy_to_stream(srcstream, stream, PHP_STREAM_COPY_ALL);
break;
}
case IS_NULL:
case IS_LONG:
case IS_DOUBLE:

Loading…
Cancel
Save