[PHP-CVS] cvs: php-src /ext/standard user_filters.c /ext/standard/tests/filters filter_errors.inc filter_errors_convert_base64_decode.phpt filter_errors_user.phpt
lbarnaudThu Jan 8 18:39:04 2009 UTC Modified files: /php-src/ext/standard user_filters.c /php-src/ext/standard/tests/filters filter_errors.inc filter_errors_convert_base64_decode.phpt filter_errors_user.phpt Log: Fix memleak when a user filter appends a bucket and returns != PSFS_PASS_ON Improved tests http://cvs.php.net/viewvc.cgi/php-src/ext/standard/user_filters.c?r1=1.59r2=1.60diff_format=u Index: php-src/ext/standard/user_filters.c diff -u php-src/ext/standard/user_filters.c:1.59 php-src/ext/standard/user_filters.c:1.60 --- php-src/ext/standard/user_filters.c:1.59Wed Dec 31 11:12:37 2008 +++ php-src/ext/standard/user_filters.c Thu Jan 8 18:39:04 2009 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: user_filters.c,v 1.59 2008/12/31 11:12:37 sebastian Exp $ */ +/* $Id: user_filters.c,v 1.60 2009/01/08 18:39:04 lbarnaud Exp $ */ #include php.h #include php_globals.h @@ -245,6 +245,14 @@ php_stream_bucket_delref(bucket TSRMLS_CC); } } + if (ret != PSFS_PASS_ON) { + php_stream_bucket *bucket = buckets_out-head; + while (bucket != NULL) { + php_stream_bucket_unlink(bucket TSRMLS_CC); + php_stream_bucket_delref(bucket TSRMLS_CC); + bucket = buckets_out-head; + } + } /* filter resources are cleaned up by the stream destructor, * keeping a reference to the stream resource here would prevent it http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/filters/filter_errors.inc?r1=1.1r2=1.2diff_format=u Index: php-src/ext/standard/tests/filters/filter_errors.inc diff -u php-src/ext/standard/tests/filters/filter_errors.inc:1.1 php-src/ext/standard/tests/filters/filter_errors.inc:1.2 --- php-src/ext/standard/tests/filters/filter_errors.inc:1.1Thu Jan 8 17:01:11 2009 +++ php-src/ext/standard/tests/filters/filter_errors.incThu Jan 8 18:39:04 2009 @@ -27,7 +27,7 @@ fwrite($stream, b$data); fseek($stream, 0, SEEK_SET); - stream_get_line($stream, 8192, \r\n); + stream_filter_append($stream, $filter); stream_get_contents($stream); } http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/filters/filter_errors_convert_base64_decode.phpt?r1=1.1r2=1.2diff_format=u Index: php-src/ext/standard/tests/filters/filter_errors_convert_base64_decode.phpt diff -u php-src/ext/standard/tests/filters/filter_errors_convert_base64_decode.phpt:1.1 php-src/ext/standard/tests/filters/filter_errors_convert_base64_decode.phpt:1.2 --- php-src/ext/standard/tests/filters/filter_errors_convert_base64_decode.phpt:1.1 Thu Jan 8 17:01:11 2009 +++ php-src/ext/standard/tests/filters/filter_errors_convert_base64_decode.phpt Thu Jan 8 18:39:04 2009 @@ -14,3 +14,5 @@ Warning: stream_filter_append(): Filter failed to process pre-buffered data in %s test filtering of non buffered data + +Warning: stream_get_contents(): stream filter (convert.base64-decode): invalid byte sequence in %s http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/filters/filter_errors_user.phpt?r1=1.1r2=1.2diff_format=u Index: php-src/ext/standard/tests/filters/filter_errors_user.phpt diff -u php-src/ext/standard/tests/filters/filter_errors_user.phpt:1.1 php-src/ext/standard/tests/filters/filter_errors_user.phpt:1.2 --- php-src/ext/standard/tests/filters/filter_errors_user.phpt:1.1 Thu Jan 8 17:01:11 2009 +++ php-src/ext/standard/tests/filters/filter_errors_user.phpt Thu Jan 8 18:39:04 2009 @@ -26,14 +26,18 @@ } class test_filter3 extends php_user_filter { function filter($in, $out, $consumed, $closing) { - $bucket = stream_bucket_new($this-stream, 42); - stream_bucket_append($out, $bucket); + if (!$closing) { + $bucket = stream_bucket_new($this-stream, 42); + stream_bucket_append($out, $bucket); + } return PSFS_ERR_FATAL; } } class test_filter4 extends php_user_filter { function filter($in, $out, $consumed, $closing) { - $bucket = stream_bucket_new($this-stream, 42); + if (!$closing) { + $bucket = stream_bucket_new($this-stream, 42); + } return PSFS_ERR_FATAL; } } @@ -44,6 +48,43 @@ filter_errors_test(test_filter$i, 42); } +echo test append / read / remove\n; +for($i = 0; $i 5; ++$i) { + echo test_filter$i\n; + $stream = fopen('php://memory', 'wb+'); + fwrite($stream, b42); + fseek($stream, 0, SEEK_SET); + $f = stream_filter_append($stream, test_filter$i); + stream_get_contents($stream); + stream_filter_remove($f);
[PHP-CVS] cvs: php-src /ext/standard user_filters.c /ext/standard/tests/filters bug46164-1.phpt bug46164-2.phpt
lbarnaudSun Oct 5 01:40:02 2008 UTC Added files: /php-src/ext/standard/tests/filters bug46164-1.phpt bug46164-2.phpt Modified files: /php-src/ext/standard user_filters.c Log: Fixed #46164 (stream_filter_remove() closes the stream) http://cvs.php.net/viewvc.cgi/php-src/ext/standard/user_filters.c?r1=1.54r2=1.55diff_format=u Index: php-src/ext/standard/user_filters.c diff -u php-src/ext/standard/user_filters.c:1.54 php-src/ext/standard/user_filters.c:1.55 --- php-src/ext/standard/user_filters.c:1.54Thu May 8 17:22:07 2008 +++ php-src/ext/standard/user_filters.c Sun Oct 5 01:40:02 2008 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: user_filters.c,v 1.54 2008/05/08 17:22:07 felipe Exp $ */ +/* $Id: user_filters.c,v 1.55 2008/10/05 01:40:02 lbarnaud Exp $ */ #include php.h #include php_globals.h @@ -183,12 +183,14 @@ zval *retval = NULL; zval **args[4]; zval *zclosing, *zconsumed, *zin, *zout, *zstream; + zval zpropname; int call_result; if (FAILURE == zend_hash_find(Z_OBJPROP_P(obj), stream, sizeof(stream), (void**)zstream)) { /* Give the userfilter class a hook back to the stream */ ALLOC_INIT_ZVAL(zstream); php_stream_to_zval(stream, zstream); + zval_copy_ctor(zstream); add_property_zval(obj, stream, zstream); /* add_property_zval increments the refcount which is unwanted here */ zval_ptr_dtor(zstream); @@ -247,6 +249,13 @@ } } + /* filter resources are cleaned up by the stream destructor, +* keeping a reference to the stream resource here would prevent it +* from being destroyed properly */ + INIT_ZVAL(zpropname); + ZVAL_STRINGL(zpropname, stream, sizeof(stream)-1, 0); + Z_OBJ_HANDLER_P(obj, unset_property)(obj, zpropname TSRMLS_CC); + zval_ptr_dtor(zclosing); zval_ptr_dtor(zconsumed); zval_ptr_dtor(zout); http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/filters/bug46164-1.phpt?view=markuprev=1.1 Index: php-src/ext/standard/tests/filters/bug46164-1.phpt +++ php-src/ext/standard/tests/filters/bug46164-1.phpt --TEST-- Bug #46164 - 1 (stream_filter_remove() closes the stream) --FILE-- ?php class user_filter extends php_user_filter { function filter($in, $out, $consumed, $closing) { while($bucket = stream_bucket_make_writeable($in)) { $consumed += $bucket-datalen; stream_bucket_append($out, $bucket); } return PSFS_PASS_ON; } } stream_filter_register('user_filter','user_filter'); $fd = fopen('php://memory','w'); $filter = stream_filter_append($fd, 'user_filter'); stream_filter_remove($filter); var_dump(fclose($fd)); ? --EXPECT-- bool(true) http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/filters/bug46164-2.phpt?view=markuprev=1.1 Index: php-src/ext/standard/tests/filters/bug46164-2.phpt +++ php-src/ext/standard/tests/filters/bug46164-2.phpt --TEST-- Bug #46164 - 2 (stream_filter_remove() closes the stream) --FILE-- ?php class user_filter extends php_user_filter { function filter($in, $out, $consumed, $closing) { while($bucket = stream_bucket_make_writeable($in)) { $consumed += $bucket-datalen; stream_bucket_append($out, $bucket); } unset($this-stream); return PSFS_PASS_ON; } } stream_filter_register('user_filter','user_filter'); $fd = fopen('php://memory','w'); $filter = stream_filter_append($fd, 'user_filter'); fwrite($fd, bfoo); fflush($fd); var_dump(fclose($fd)); ? --EXPECT-- bool(true) -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/standard user_filters.c
felipe Thu May 8 17:22:07 2008 UTC Modified files: /php-src/ext/standard user_filters.c Log: - Fix data size http://cvs.php.net/viewvc.cgi/php-src/ext/standard/user_filters.c?r1=1.53r2=1.54diff_format=u Index: php-src/ext/standard/user_filters.c diff -u php-src/ext/standard/user_filters.c:1.53 php-src/ext/standard/user_filters.c:1.54 --- php-src/ext/standard/user_filters.c:1.53Thu Feb 28 14:16:14 2008 +++ php-src/ext/standard/user_filters.c Thu May 8 17:22:07 2008 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: user_filters.c,v 1.53 2008/02/28 14:16:14 felipe Exp $ */ +/* $Id: user_filters.c,v 1.54 2008/05/08 17:22:07 felipe Exp $ */ #include php.h #include php_globals.h @@ -636,7 +636,7 @@ fdat-classname_len = classname_len; if (zend_hash_add(BG(user_filter_map), filtername, filtername_len + 1, (void*)fdat, - sizeof(*fdat) + classname_len, NULL) == SUCCESS + sizeof(*fdat), NULL) == SUCCESS php_stream_filter_register_factory_volatile(filtername, user_filter_factory TSRMLS_CC) == SUCCESS) { RETVAL_TRUE; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/standard user_filters.c
pollita Sat Aug 4 07:51:15 2007 UTC Modified files: /php-src/ext/standard user_filters.c Log: Bugfix#36492 Userfilters can leak buckets http://cvs.php.net/viewvc.cgi/php-src/ext/standard/user_filters.c?r1=1.48r2=1.49diff_format=u Index: php-src/ext/standard/user_filters.c diff -u php-src/ext/standard/user_filters.c:1.48 php-src/ext/standard/user_filters.c:1.49 --- php-src/ext/standard/user_filters.c:1.48Sat Jul 14 08:38:20 2007 +++ php-src/ext/standard/user_filters.c Sat Aug 4 07:51:15 2007 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: user_filters.c,v 1.48 2007/07/14 08:38:20 tony2001 Exp $ */ +/* $Id: user_filters.c,v 1.49 2007/08/04 07:51:15 pollita Exp $ */ #include php.h #include php_globals.h @@ -232,8 +232,21 @@ php_error_docref(NULL TSRMLS_CC, E_WARNING, failed to call filter function); } - if (retval) + if (retval) { zval_ptr_dtor(retval); + } + + if (buckets_in-head) { + php_stream_bucket *bucket = buckets_in-head; + + php_error_docref(NULL TSRMLS_CC, E_WARNING, Unprocessed filter buckets remaining on input brigade); + while ((bucket = buckets_in-head)) { + /* Remove unconsumed buckets from the brigade */ + php_stream_bucket_unlink(bucket TSRMLS_CC); + php_stream_bucket_delref(bucket TSRMLS_CC); + } + } + zval_ptr_dtor(zclosing); zval_ptr_dtor(zconsumed); zval_ptr_dtor(zout); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/standard user_filters.c
tony2001Tue May 29 20:31:22 2007 UTC Modified files: /php-src/ext/standard user_filters.c Log: fix typo build http://cvs.php.net/viewvc.cgi/php-src/ext/standard/user_filters.c?r1=1.46r2=1.47diff_format=u Index: php-src/ext/standard/user_filters.c diff -u php-src/ext/standard/user_filters.c:1.46 php-src/ext/standard/user_filters.c:1.47 --- php-src/ext/standard/user_filters.c:1.46Tue May 29 20:11:23 2007 +++ php-src/ext/standard/user_filters.c Tue May 29 20:31:22 2007 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: user_filters.c,v 1.46 2007/05/29 20:11:23 iliaa Exp $ */ +/* $Id: user_filters.c,v 1.47 2007/05/29 20:31:22 tony2001 Exp $ */ #include php.h #include php_globals.h @@ -284,7 +284,7 @@ char *wildcard = emalloc(len + 3); /* Search for wildcard matches instead */ - memcpy(wildname, filtername, len + 1); /* copy \0 */ + memcpy(wildcard, filtername, len + 1); /* copy \0 */ period = wildcard + (period - filtername); while (period) { *period = '\0'; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/standard user_filters.c
tony2001Thu Feb 1 14:20:53 2007 UTC Modified files: /php-src/ext/standard user_filters.c Log: bailout if bucket is NULL http://cvs.php.net/viewvc.cgi/php-src/ext/standard/user_filters.c?r1=1.44r2=1.45diff_format=u Index: php-src/ext/standard/user_filters.c diff -u php-src/ext/standard/user_filters.c:1.44 php-src/ext/standard/user_filters.c:1.45 --- php-src/ext/standard/user_filters.c:1.44Fri Jan 19 14:49:52 2007 +++ php-src/ext/standard/user_filters.c Thu Feb 1 14:20:53 2007 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: user_filters.c,v 1.44 2007/01/19 14:49:52 tony2001 Exp $ */ +/* $Id: user_filters.c,v 1.45 2007/02/01 14:20:53 tony2001 Exp $ */ #include php.h #include php_globals.h @@ -541,6 +541,10 @@ add_property_long(return_value, datalen, buffer_len); } + if (bucket == NULL) { + RETURN_FALSE; + } + ALLOC_INIT_ZVAL(zbucket); ZEND_REGISTER_RESOURCE(zbucket, bucket, le_bucket); add_property_zval(return_value, bucket, zbucket); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/standard user_filters.c /main/streams streams.c transports.c userspace.c
tony2001Mon Jan 15 17:06:52 2007 UTC Modified files: /php-src/ext/standard user_filters.c /php-src/main/streams streams.c transports.c userspace.c Log: add trailing '\0' to stream hashes http://cvs.php.net/viewvc.cgi/php-src/ext/standard/user_filters.c?r1=1.42r2=1.43diff_format=u Index: php-src/ext/standard/user_filters.c diff -u php-src/ext/standard/user_filters.c:1.42 php-src/ext/standard/user_filters.c:1.43 --- php-src/ext/standard/user_filters.c:1.42Sun Jan 7 06:29:40 2007 +++ php-src/ext/standard/user_filters.c Mon Jan 15 17:06:52 2007 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: user_filters.c,v 1.42 2007/01/07 06:29:40 pollita Exp $ */ +/* $Id: user_filters.c,v 1.43 2007/01/15 17:06:52 tony2001 Exp $ */ #include php.h #include php_globals.h @@ -270,7 +270,7 @@ /* determine the classname/class entry */ if (FAILURE == zend_hash_find(BG(user_filter_map), (char*)filtername, - strlen(filtername), (void**)fdat)) { + strlen(filtername) + 1, (void**)fdat)) { char *period; /* Userspace Filters using ambiguous wildcards could cause problems. @@ -287,7 +287,7 @@ while (period) { *period = '\0'; strcat(wildcard, .*); - if (SUCCESS == zend_hash_find(BG(user_filter_map), wildcard, strlen(wildcard), (void**)fdat)) { + if (SUCCESS == zend_hash_find(BG(user_filter_map), wildcard, strlen(wildcard) + 1, (void**)fdat)) { period = NULL; } else { *period = '\0'; @@ -617,7 +617,7 @@ fdat-classname = ezstrndup(classname_type, classname, classname_len); fdat-classname_len = classname_len; - if (zend_hash_add(BG(user_filter_map), filtername, filtername_len, (void*)fdat, + if (zend_hash_add(BG(user_filter_map), filtername, filtername_len + 1, (void*)fdat, sizeof(*fdat) + classname_len, NULL) == SUCCESS php_stream_filter_register_factory_volatile(filtername, user_filter_factory TSRMLS_CC) == SUCCESS) { RETVAL_TRUE; http://cvs.php.net/viewvc.cgi/php-src/main/streams/streams.c?r1=1.143r2=1.144diff_format=u Index: php-src/main/streams/streams.c diff -u php-src/main/streams/streams.c:1.143 php-src/main/streams/streams.c:1.144 --- php-src/main/streams/streams.c:1.143Wed Jan 10 22:43:17 2007 +++ php-src/main/streams/streams.c Mon Jan 15 17:06:52 2007 @@ -19,7 +19,7 @@ +--+ */ -/* $Id: streams.c,v 1.143 2007/01/10 22:43:17 pollita Exp $ */ +/* $Id: streams.c,v 1.144 2007/01/15 17:06:52 tony2001 Exp $ */ #define _GNU_SOURCE #include php.h @@ -1997,12 +1997,12 @@ return FAILURE; } - return zend_hash_add(url_stream_wrappers_hash, protocol, protocol_len, wrapper, sizeof(wrapper), NULL); + return zend_hash_add(url_stream_wrappers_hash, protocol, protocol_len + 1, wrapper, sizeof(wrapper), NULL); } PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC) { - return zend_hash_del(url_stream_wrappers_hash, protocol, strlen(protocol)); + return zend_hash_del(url_stream_wrappers_hash, protocol, strlen(protocol) + 1); } static void clone_wrapper_hash(TSRMLS_D) @@ -2027,7 +2027,7 @@ clone_wrapper_hash(TSRMLS_C); } - return zend_hash_add(FG(stream_wrappers), protocol, protocol_len, wrapper, sizeof(wrapper), NULL); + return zend_hash_add(FG(stream_wrappers), protocol, protocol_len + 1, wrapper, sizeof(wrapper), NULL); } PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC) @@ -2036,7 +2036,7 @@ clone_wrapper_hash(TSRMLS_C); } - return zend_hash_del(FG(stream_wrappers), protocol, strlen(protocol)); + return zend_hash_del(FG(stream_wrappers), protocol, strlen(protocol) + 1); } /* }}} */ @@ -2070,10 +2070,10 @@ } if (protocol) { - if (FAILURE == zend_hash_find(wrapper_hash, (char*)protocol, n, (void**)wrapperpp)) { - char *tmp = estrndup(protocol, n); + char *tmp = estrndup(protocol, n); + if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n + 1, (void**)wrapperpp)) { php_strtolower(tmp, n); - if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n, (void**)wrapperpp)) { + if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n + 1, (void**)wrapperpp)) { char
[PHP-CVS] cvs: php-src /ext/standard user_filters.c /ext/standard/tests/filters 001.phpt bug35916.phpt
pollita Sun Jan 7 06:29:41 2007 UTC Modified files: /php-src/ext/standard user_filters.c /php-src/ext/standard/tests/filters 001.phpt bug35916.phpt Log: Remaining unicode updates for user filters http://cvs.php.net/viewvc.cgi/php-src/ext/standard/user_filters.c?r1=1.41r2=1.42diff_format=u Index: php-src/ext/standard/user_filters.c diff -u php-src/ext/standard/user_filters.c:1.41 php-src/ext/standard/user_filters.c:1.42 --- php-src/ext/standard/user_filters.c:1.41Mon Jan 1 09:29:32 2007 +++ php-src/ext/standard/user_filters.c Sun Jan 7 06:29:40 2007 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: user_filters.c,v 1.41 2007/01/01 09:29:32 sebastian Exp $ */ +/* $Id: user_filters.c,v 1.42 2007/01/07 06:29:40 pollita Exp $ */ #include php.h #include php_globals.h @@ -31,8 +31,10 @@ struct php_user_filter_data { zend_class_entry *ce; - /* variable length; this *must* be last in the structure */ - char classname[1]; + + zend_uchar classname_type; + zstr classname; + int classname_len; }; /* to provide context for calling into the next filter from user-space */ @@ -50,10 +52,13 @@ } /* define the base filter class */ - -PHP_FUNCTION(user_filter_nop) +/* {{{ proto void user_filter_nop(void) U +Non-function */ +static PHP_FUNCTION(user_filter_nop) { } +/* }}} */ + static ZEND_BEGIN_ARG_INFO(arginfo_php_user_filter_filter, 0) ZEND_ARG_INFO(0, in) @@ -269,10 +274,10 @@ char *period; /* Userspace Filters using ambiguous wildcards could cause problems. - i.e.: myfilter.foo.bar will always call into myfilter.foo.* - never seeing myfilter.* - TODO: Allow failed userfilter creations to continue - scanning through the list */ + i.e.: myfilter.foo.bar will always call into myfilter.foo.* + never seeing myfilter.* + TODO: Allow failed userfilter creations to continue + scanning through the list */ if ((period = strrchr(filtername, '.'))) { char *wildcard; @@ -300,7 +305,7 @@ /* bind the classname to the actual class */ if (fdat-ce == NULL) { - if (FAILURE == zend_lookup_class(fdat-classname, strlen(fdat-classname), + if (FAILURE == zend_u_lookup_class(fdat-classname_type, fdat-classname, fdat-classname_len, (zend_class_entry ***)fdat-ce TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, user-filter \%s\ requires class \%s\, but that class is not defined, @@ -323,7 +328,7 @@ PZVAL_IS_REF(obj) = 1; /* filtername */ - add_property_string(obj, filtername, (char*)filtername, 1); + add_property_rt_string(obj, filtername, (char*)filtername, 1); /* and the parameters, if any */ if (filterparams) { @@ -378,9 +383,10 @@ static void filter_item_dtor(struct php_user_filter_data *fdat) { + efree(fdat-classname.v); } -/* {{{ proto object stream_bucket_make_writeable(resource brigade) +/* {{{ proto object stream_bucket_make_writeable(resource brigade) U Return a bucket object from the brigade for operating on */ PHP_FUNCTION(stream_bucket_make_writeable) { @@ -405,7 +411,7 @@ zval_ptr_dtor(zbucket); if (bucket-buf_type == IS_UNICODE) { add_property_unicodel(return_value, data, bucket-buf.u, bucket-buflen, 1); - add_property_long(return_value, datalen, bucket-buflen); + add_property_long(return_value, datalen, u_countChar32(bucket-buf.u, bucket-buflen)); } else { add_property_stringl(return_value, data, bucket-buf.s, bucket-buflen, 1); add_property_long(return_value, datalen, bucket-buflen); @@ -485,7 +491,7 @@ } /* }}} */ -/* {{{ proto void stream_bucket_prepend(resource brigade, resource bucket) +/* {{{ proto void stream_bucket_prepend(resource brigade, resource bucket) U Prepend bucket to brigade */ PHP_FUNCTION(stream_bucket_prepend) { @@ -493,7 +499,7 @@ } /* }}} */ -/* {{{ proto void stream_bucket_append(resource brigade, resource bucket) +/* {{{ proto void stream_bucket_append(resource brigade, resource bucket) U Append bucket to brigade */ PHP_FUNCTION(stream_bucket_append) { @@ -501,40 +507,40 @@ } /* }}} */ -/* {{{ proto resource stream_bucket_new(resource stream, string buffer) +/* {{{ proto object stream_bucket_new(resource stream, string buffer) U Create a new bucket for use on the current stream */ PHP_FUNCTION(stream_bucket_new) { zval *zstream, *zbucket; php_stream *stream; - zval *buffer; + zstr
[PHP-CVS] cvs: php-src /ext/standard user_filters.c
tony2001Wed Oct 11 14:46:31 2006 UTC Modified files: /php-src/ext/standard user_filters.c Log: check filter and class names for empty strings http://cvs.php.net/viewvc.cgi/php-src/ext/standard/user_filters.c?r1=1.38r2=1.39diff_format=u Index: php-src/ext/standard/user_filters.c diff -u php-src/ext/standard/user_filters.c:1.38 php-src/ext/standard/user_filters.c:1.39 --- php-src/ext/standard/user_filters.c:1.38Sun Jun 25 22:51:55 2006 +++ php-src/ext/standard/user_filters.c Wed Oct 11 14:46:31 2006 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: user_filters.c,v 1.38 2006/06/25 22:51:55 bjori Exp $ */ +/* $Id: user_filters.c,v 1.39 2006/10/11 14:46:31 tony2001 Exp $ */ #include php.h #include php_globals.h @@ -565,6 +565,16 @@ RETVAL_FALSE; + if (!filtername_len) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Filter name cannot be empty); + return; + } + + if (!classname_len) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Class name cannot be empty); + return; + } + if (!BG(user_filter_map)) { BG(user_filter_map) = (HashTable*) emalloc(sizeof(HashTable)); zend_hash_init(BG(user_filter_map), 5, NULL, (dtor_func_t) filter_item_dtor, 0); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/standard user_filters.c /ext/standard/tests/filters php_user_filter_01.phpt php_user_filter_02.phpt php_user_filter_03.phpt
bjori Sun Jun 25 22:51:55 2006 UTC Added files: /php-src/ext/standard/tests/filters php_user_filter_01.phpt php_user_filter_02.phpt php_user_filter_03.phpt Modified files: /php-src/ext/standard user_filters.c Log: Added argument info (forces user-space filters to register correct arguments) Added tests http://cvs.php.net/viewvc.cgi/php-src/ext/standard/user_filters.c?r1=1.37r2=1.38diff_format=u Index: php-src/ext/standard/user_filters.c diff -u php-src/ext/standard/user_filters.c:1.37 php-src/ext/standard/user_filters.c:1.38 --- php-src/ext/standard/user_filters.c:1.37Mon Mar 13 04:40:11 2006 +++ php-src/ext/standard/user_filters.c Sun Jun 25 22:51:55 2006 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: user_filters.c,v 1.37 2006/03/13 04:40:11 pollita Exp $ */ +/* $Id: user_filters.c,v 1.38 2006/06/25 22:51:55 bjori Exp $ */ #include php.h #include php_globals.h @@ -54,11 +54,26 @@ PHP_FUNCTION(user_filter_nop) { } +static +ZEND_BEGIN_ARG_INFO(arginfo_php_user_filter_filter, 0) + ZEND_ARG_INFO(0, in) + ZEND_ARG_INFO(0, out) + ZEND_ARG_INFO(1, consumed) + ZEND_ARG_INFO(0, closing) +ZEND_END_ARG_INFO() + +static +ZEND_BEGIN_ARG_INFO(arginfo_php_user_filter_onCreate, 0) +ZEND_END_ARG_INFO() + +static +ZEND_BEGIN_ARG_INFO(arginfo_php_user_filter_onClose, 0) +ZEND_END_ARG_INFO() static zend_function_entry user_filter_class_funcs[] = { - PHP_NAMED_FE(filter,PHP_FN(user_filter_nop),NULL) - PHP_NAMED_FE(onCreate, PHP_FN(user_filter_nop),NULL) - PHP_NAMED_FE(onClose, PHP_FN(user_filter_nop),NULL) + PHP_NAMED_FE(filter,PHP_FN(user_filter_nop), arginfo_php_user_filter_filter) + PHP_NAMED_FE(onCreate, PHP_FN(user_filter_nop), arginfo_php_user_filter_onCreate) + PHP_NAMED_FE(onClose, PHP_FN(user_filter_nop), arginfo_php_user_filter_onClose) { NULL, NULL, NULL } }; @@ -66,11 +81,14 @@ PHP_MINIT_FUNCTION(user_filters) { + zend_class_entry *php_user_filter; /* init the filter class ancestor */ INIT_CLASS_ENTRY(user_filter_class_entry, php_user_filter, user_filter_class_funcs); - if (NULL == zend_register_internal_class(user_filter_class_entry TSRMLS_CC)) { + if ((php_user_filter = zend_register_internal_class(user_filter_class_entry TSRMLS_CC)) == NULL) { return FAILURE; } + zend_declare_property_string(php_user_filter, filtername, sizeof(filtername)-1, , ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_string(php_user_filter, params, sizeof(params)-1, , ZEND_ACC_PUBLIC TSRMLS_CC); /* init the filter resource; it has no dtor, as streams will always clean it up * at the correct time */ http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/filters/php_user_filter_01.phpt?view=markuprev=1.1 Index: php-src/ext/standard/tests/filters/php_user_filter_01.phpt +++ php-src/ext/standard/tests/filters/php_user_filter_01.phpt --TEST-- class php_user_filter#1 --FILE-- ?php class foo extends php_user_filter { function filter($in, $out, $consumed, $closing) {} function onCreate() {} function onClose() {} } class bar extends php_user_filter { function filter($in, $out, $consumed) {} function onCreate() {} function onClose() {} } ? --EXPECTF-- Fatal error: Declaration of bar::filter() must be compatible with that of php_user_filter::filter() in %s on line %d http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/filters/php_user_filter_02.phpt?view=markuprev=1.1 Index: php-src/ext/standard/tests/filters/php_user_filter_02.phpt +++ php-src/ext/standard/tests/filters/php_user_filter_02.phpt --TEST-- class php_user_filter#2 --FILE-- ?php class foo extends php_user_filter { function filter($in, $out, $consumed, $closing) {} function onCreate() {} function onClose() {} } ? --EXPECTF-- Fatal error: Declaration of foo::filter() must be compatible with that of php_user_filter::filter() in %s on line %d http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/filters/php_user_filter_03.phpt?view=markuprev=1.1 Index: php-src/ext/standard/tests/filters/php_user_filter_03.phpt +++ php-src/ext/standard/tests/filters/php_user_filter_03.phpt --TEST-- class php_user_filter#3 --FILE-- ?php class foo extends php_user_filter { function filter($in, $out, $consumed, $closing) {} function onCreate($var) {} function onClose() {} } ? --EXPECTF-- Fatal error: Declaration of foo::onCreate() must be compatible with that of php_user_filter::onCreate() in %s on line %d -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/standard user_filters.c
iliaa Sun Jun 12 13:07:21 2005 EDT Modified files: /php-src/ext/standard user_filters.c Log: Removed unused var. http://cvs.php.net/diff.php/php-src/ext/standard/user_filters.c?r1=1.29r2=1.30ty=u Index: php-src/ext/standard/user_filters.c diff -u php-src/ext/standard/user_filters.c:1.29 php-src/ext/standard/user_filters.c:1.30 --- php-src/ext/standard/user_filters.c:1.29Thu Jun 9 04:19:30 2005 +++ php-src/ext/standard/user_filters.c Sun Jun 12 13:07:20 2005 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: user_filters.c,v 1.29 2005/06/09 08:19:30 dmitry Exp $ */ +/* $Id: user_filters.c,v 1.30 2005/06/12 17:07:20 iliaa Exp $ */ #include php.h #include php_globals.h @@ -116,7 +116,6 @@ zval *obj = (zval*)thisfilter-abstract; zval func_name; zval *retval = NULL; - zval **tmp; if (obj == NULL) { /* If there's no object associated then there's nothing to dispose of */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/standard user_filters.c
dmitry Thu Jun 9 04:19:30 2005 EDT Modified files: /php-src/ext/standard user_filters.c Log: Fixed reference counting and probable crash on fclose() or shutdown http://cvs.php.net/diff.php/php-src/ext/standard/user_filters.c?r1=1.28r2=1.29ty=u Index: php-src/ext/standard/user_filters.c diff -u php-src/ext/standard/user_filters.c:1.28 php-src/ext/standard/user_filters.c:1.29 --- php-src/ext/standard/user_filters.c:1.28Mon Jun 21 17:08:05 2004 +++ php-src/ext/standard/user_filters.c Thu Jun 9 04:19:30 2005 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: user_filters.c,v 1.28 2004/06/21 21:08:05 pollita Exp $ */ +/* $Id: user_filters.c,v 1.29 2005/06/09 08:19:30 dmitry Exp $ */ #include php.h #include php_globals.h @@ -135,11 +135,6 @@ if (retval) zval_ptr_dtor(retval); - if (SUCCESS == zend_hash_find(Z_OBJPROP_P(obj), filter, sizeof(filter), (void**)tmp)) { - zend_list_delete(Z_LVAL_PP(tmp)); - FREE_ZVAL(*tmp); - } - /* kill the object */ zval_ptr_dtor(obj); } @@ -345,6 +340,8 @@ ZEND_REGISTER_RESOURCE(zfilter, filter, le_userfilters); filter-abstract = obj; add_property_zval(obj, filter, zfilter); + /* add_property_zval increments the refcount which is unwanted here */ + zval_ptr_dtor(zfilter); return filter; } @@ -470,6 +467,8 @@ ZEND_REGISTER_RESOURCE(zbucket, bucket, le_bucket); object_init(return_value); add_property_zval(return_value, bucket, zbucket); + /* add_property_zval increments the refcount which is unwanted here */ + zval_ptr_dtor(zbucket); add_property_stringl(return_value, data, bucket-buf, bucket-buflen, 1); add_property_long(return_value, datalen, bucket-buflen); } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/standard user_filters.c
helly Sat Apr 10 09:56:28 2004 EDT Modified files: /php-src/ext/standard user_filters.c Log: studlyCaps http://cvs.php.net/diff.php/php-src/ext/standard/user_filters.c?r1=1.24r2=1.25ty=u Index: php-src/ext/standard/user_filters.c diff -u php-src/ext/standard/user_filters.c:1.24 php-src/ext/standard/user_filters.c:1.25 --- php-src/ext/standard/user_filters.c:1.24Sat Jan 17 12:33:11 2004 +++ php-src/ext/standard/user_filters.c Sat Apr 10 09:56:27 2004 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: user_filters.c,v 1.24 2004/01/17 17:33:11 andrey Exp $ */ +/* $Id: user_filters.c,v 1.25 2004/04/10 13:56:27 helly Exp $ */ #include php.h #include php_globals.h @@ -57,8 +57,8 @@ static zend_function_entry user_filter_class_funcs[] = { PHP_NAMED_FE(filter,PHP_FN(user_filter_nop),NULL) - PHP_NAMED_FE(oncreate, PHP_FN(user_filter_nop),NULL) - PHP_NAMED_FE(onclose, PHP_FN(user_filter_nop),NULL) + PHP_NAMED_FE(onCreate, PHP_FN(user_filter_nop),NULL) + PHP_NAMED_FE(onClose, PHP_FN(user_filter_nop),NULL) { NULL, NULL, NULL } }; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/standard user_filters.c
pollita Tue Oct 28 18:56:58 2003 EDT Modified files: /php-src/ext/standard user_filters.c Log: Allow userfilter instantiation to programmatically fail by returning false. Equivalent of Cspace filter failure by returning NULL. Index: php-src/ext/standard/user_filters.c diff -u php-src/ext/standard/user_filters.c:1.20 php-src/ext/standard/user_filters.c:1.21 --- php-src/ext/standard/user_filters.c:1.20Thu Aug 7 15:53:31 2003 +++ php-src/ext/standard/user_filters.c Tue Oct 28 18:56:57 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: user_filters.c,v 1.20 2003/08/07 19:53:31 moriyoshi Exp $ */ +/* $Id: user_filters.c,v 1.21 2003/10/28 23:56:57 pollita Exp $ */ #include php.h #include php_globals.h @@ -118,6 +118,11 @@ zval *retval = NULL; zval **tmp; + if (obj == NULL) { + /* If there's no object associated then there's nothing to dispose of */ + return; + } + ZVAL_STRINGL(func_name, onclose, sizeof(onclose)-1, 0); call_user_function_ex(NULL, @@ -266,20 +271,12 @@ return NULL; } - ALLOC_INIT_ZVAL(zfilter); - ZEND_REGISTER_RESOURCE(zfilter, filter, le_userfilters); - /* create the object */ ALLOC_ZVAL(obj); object_init_ex(obj, fdat-ce); ZVAL_REFCOUNT(obj) = 1; PZVAL_IS_REF(obj) = 1; - /* set the filter property */ - filter-abstract = obj; - - add_property_zval(obj, filter, zfilter); - /* filtername */ add_property_string(obj, filtername, (char*)filtername, 1); @@ -300,8 +297,30 @@ 0, NULL, 0, NULL TSRMLS_CC); - if (retval) + if (retval) { + if (Z_TYPE_P(retval) == IS_BOOL Z_LVAL_P(retval) == 0) { + /* User reported filter creation error return false; */ + zval_ptr_dtor(retval); + + /* Kill the filter (safely) */ + filter-abstract = NULL; + php_stream_filter_free(filter TSRMLS_CC); + + /* Kill the object */ + zval_ptr_dtor(obj); + + /* Report failure to filter_alloc */ + return NULL; + } zval_ptr_dtor(retval); + } + + /* set the filter property, this will be used during cleanup */ + ALLOC_INIT_ZVAL(zfilter); + ZEND_REGISTER_RESOURCE(zfilter, filter, le_userfilters); + filter-abstract = obj; + add_property_zval(obj, filter, zfilter); + return filter; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/standard user_filters.c
pollita Tue Oct 28 19:19:58 2003 EDT Modified files: /php-src/ext/standard user_filters.c Log: Allow userspace filters to use wildcards Index: php-src/ext/standard/user_filters.c diff -u php-src/ext/standard/user_filters.c:1.21 php-src/ext/standard/user_filters.c:1.22 --- php-src/ext/standard/user_filters.c:1.21Tue Oct 28 18:56:57 2003 +++ php-src/ext/standard/user_filters.c Tue Oct 28 19:19:57 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: user_filters.c,v 1.21 2003/10/28 23:56:57 pollita Exp $ */ +/* $Id: user_filters.c,v 1.22 2003/10/29 00:19:57 pollita Exp $ */ #include php.h #include php_globals.h @@ -246,9 +246,36 @@ /* determine the classname/class entry */ if (FAILURE == zend_hash_find(BG(user_filter_map), (char*)filtername, strlen(filtername), (void**)fdat)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, - Err, filter \%s\ is not in the user-filter map, but somehow the user-filter-factory was invoked for it!?, filtername); - return NULL; + char *period; + + /* Userspace Filters using ambiguous wildcards could cause problems. + i.e.: myfilter.foo.bar will always call into myfilter.foo.* + never seeing myfilter.* + TODO: Allow failed userfilter creations to continue + scanning through the list */ + if ((period = strrchr(filtername, '.'))) { + char *wildcard; + + /* Search for wildcard matches instead */ + wildcard = estrdup(filtername); + period = wildcard + (period - filtername); + while (period) { + *period = '\0'; + strcat(wildcard, .*); + if (SUCCESS == zend_hash_find(BG(user_filter_map), wildcard, strlen(wildcard), (void**)fdat)) { + period = NULL; + } else { + *period = '\0'; + period = strrchr(wildcard, '.'); + } + } + efree(wildcard); + } + if (fdat == NULL) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, + Err, filter \%s\ is not in the user-filter map, but somehow the user-filter-factory was invoked for it!?, filtername); + return NULL; + } } /* bind the classname to the actual class */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php