]> granicus.if.org Git - php/commitdiff
- Added check for encoding optional parameter (avoiding the segfault in filter.c...
authorFelipe Pena <felipe@php.net>
Wed, 28 May 2008 18:02:52 +0000 (18:02 +0000)
committerFelipe Pena <felipe@php.net>
Wed, 28 May 2008 18:02:52 +0000 (18:02 +0000)
  If the parameter is not suplied, it will try to use the UG(stream_enconding)

ext/standard/streamsfuncs.c
ext/standard/tests/streams/stream_encoding.phpt [new file with mode: 0644]

index cb6b00766794cc6799b9a5a3871202216d587e37..14bcebb2e775acb131edff64580f89888eb3a350 100644 (file)
@@ -1578,6 +1578,14 @@ PHP_FUNCTION(stream_encoding)
        if (remove_write_tail) {
                php_stream_filter_remove(stream->writefilters.tail, 1 TSRMLS_CC);
        }
+       
+       if (encoding_len == 0) {
+               if (UG(stream_encoding) == NULL) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "The stream_encoding must be defined");
+                       RETURN_FALSE;
+               }
+               encoding = UG(stream_encoding);
+       }
 
        /* UTODO: Allow overriding error handling for converters */
        php_stream_encoding_apply(stream, 1, encoding, UG(from_error_mode), UG(from_subst_char));
diff --git a/ext/standard/tests/streams/stream_encoding.phpt b/ext/standard/tests/streams/stream_encoding.phpt
new file mode 100644 (file)
index 0000000..e92fda5
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Testing stream_encoding()
+--FILE--
+<?php
+
+stream_encoding(fopen(__FILE__, 'r'));
+print "Done";
+
+?>
+--EXPECT--
+Done