cvs: pear /PECL/mailparse mailparse.c php_mailparse_mime.c /PECL/mailparse/tests 006.phpt

From: Date: Fri, 08 Nov 2002 14:52:16 +0000
Subject: cvs: pear /PECL/mailparse mailparse.c php_mailparse_mime.c /PECL/mailparse/tests 006.phpt
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-7320@lists.php.net to get a copy of this message
wez Fri Nov 8 09:52:16 2002 EDT Modified files: /pear/PECL/mailparse mailparse.c php_mailparse_mime.c /pear/PECL/mailparse/tests 006.phpt Log: Fix buffer parsing - an off by one error could cause the message not to be parsed correctly and eventually cause a segfault. Tidy up some code. Index: pear/PECL/mailparse/mailparse.c diff -u pear/PECL/mailparse/mailparse.c:1.31 pear/PECL/mailparse/mailparse.c:1.32 --- pear/PECL/mailparse/mailparse.c:1.31 Wed Sep 11 13:44:03 2002 +++ pear/PECL/mailparse/mailparse.c Fri Nov 8 09:52:16 2002 @@ -15,7 +15,7 @@ | Author: Wez Furlong <wez@thebrainroom.com> | +----------------------------------------------------------------------+ */ -/* $Id: mailparse.c,v 1.31 2002/09/11 17:44:03 wez Exp $ */ +/* $Id: mailparse.c,v 1.32 2002/11/08 14:52:16 wez Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -651,7 +651,7 @@ { php_info_print_table_start(); php_info_print_table_header(2, "mailparse support", "enabled"); - php_info_print_table_row(2, "Revision", "$Revision: 1.31 $"); + php_info_print_table_row(2, "Revision", "$Revision: 1.32 $"); php_info_print_table_end(); DISPLAY_INI_ENTRIES(); @@ -755,8 +755,7 @@ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &file)) return; - instream = (php_stream*)zend_fetch_resource(&file TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream()); - ZEND_VERIFY_RESOURCE(instream); + php_stream_from_zval(instream, &file); outstream = php_stream_fopen_temporary_file(NULL, "mailparse", &outpath); if (outstream == NULL) { @@ -868,7 +867,7 @@ Figures out the best way of encoding the content read from the file pointer fp, which must be seek-able */ PHP_FUNCTION(mailparse_determine_best_xfer_encoding) { - zval ** file; + zval **file; int longline = 0; int linelen = 0; int c; @@ -880,8 +879,7 @@ WRONG_PARAM_COUNT; } - stream = zend_fetch_resource(file TSRMLS_CC, -1, "File-Handle", NULL, 1, php_file_le_stream()); - ZEND_VERIFY_RESOURCE(stream); + php_stream_from_zval(stream, file); php_stream_rewind(stream); while(!php_stream_eof(stream)) { @@ -933,8 +931,6 @@ PHP_FUNCTION(mailparse_stream_encode) { zval **srcfile, **destfile, **encod; - void *what; - int type; php_stream *srcstream, *deststream; char *buf; size_t len; @@ -953,14 +949,8 @@ RETURN_FALSE; } - what = zend_fetch_resource(srcfile TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream()); - ZEND_VERIFY_RESOURCE(what); - - srcstream = (php_stream*)what; - - what = zend_fetch_resource(destfile TSRMLS_CC, -1, "File-Handle", &type, 1, php_file_le_stream()); - ZEND_VERIFY_RESOURCE(what); - deststream = (php_stream*)what; + php_stream_from_zval(srcstream, srcfile); + php_stream_from_zval(deststream, destfile); convert_to_string_ex(encod); enc = mbfl_name2no_encoding(Z_STRVAL_PP(encod)); @@ -1040,7 +1030,10 @@ mailparse_fetch_mimepart_resource(part, &arg); - php_mimepart_parse(part, data, data_len TSRMLS_CC); + if (FAILURE == php_mimepart_parse(part, data, data_len TSRMLS_CC)) { + RETURN_FALSE; + } + RETURN_TRUE; } /* }}} */ @@ -1069,10 +1062,15 @@ part = php_mimepart_alloc(); php_mimepart_to_zval(return_value, part); + RETVAL_TRUE; + while(!php_stream_eof(stream)) { int got = php_stream_read(stream, filebuf, MAILPARSE_BUFSIZ); if (got > 0) { - php_mimepart_parse(part, filebuf, got TSRMLS_CC); + if (FAILURE == php_mimepart_parse(part, filebuf, got TSRMLS_CC)) { + RETVAL_FALSE; + break; + } } } php_stream_close(stream); @@ -1270,8 +1268,7 @@ /* filename can be a filename or a stream */ if (Z_TYPE_P(filename) == IS_RESOURCE) { - srcstream = (php_stream*)zend_fetch_resource(&filename TSRMLS_CC, -1, "File-Handle", NULL, 1, php_file_le_stream()); - ZEND_VERIFY_RESOURCE(srcstream); + php_stream_from_zval(srcstream, &filename); } else if (isfile) { convert_to_string_ex(&filename); srcstream = php_stream_open_wrapper(Z_STRVAL_P(filename), "rb", ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL); @@ -1291,8 +1288,7 @@ cbfunc = extract_callback_stream; cbdata = deststream = php_stream_memory_create(TEMP_STREAM_DEFAULT); } else if (Z_TYPE_P(callbackfunc) == IS_RESOURCE) { - deststream = (php_stream*)zend_fetch_resource(&callbackfunc TSRMLS_CC, -1, "File-Handle", NULL, 1, php_file_le_stream()); - ZEND_VERIFY_RESOURCE(deststream); + php_stream_from_zval(deststream, &callbackfunc); cbfunc = extract_callback_stream; cbdata = deststream; deststream = NULL; /* don't free this one */ Index: pear/PECL/mailparse/php_mailparse_mime.c diff -u pear/PECL/mailparse/php_mailparse_mime.c:1.7 pear/PECL/mailparse/php_mailparse_mime.c:1.8 --- pear/PECL/mailparse/php_mailparse_mime.c:1.7 Wed Sep 11 06:38:28 2002 +++ pear/PECL/mailparse/php_mailparse_mime.c Fri Nov 8 09:52:16 2002 @@ -15,7 +15,7 @@ | Author: Wez Furlong <wez@thebrainroom.com> | +----------------------------------------------------------------------+ */ -/* $Id: php_mailparse_mime.c,v 1.7 2002/09/11 10:38:28 wez Exp $ */ +/* $Id: php_mailparse_mime.c,v 1.8 2002/11/08 14:52:16 wez Exp $ */ #include "php.h" #include "php_mailparse.h" @@ -499,7 +499,7 @@ for (len = 0; len < bufsize; len++) if (buf[len] == '\n') break; - if (len < bufsize && buf[len] == '\n') { + if (len <= bufsize && buf[len] == '\n') { ++len; smart_str_appendl(&part->parsedata.workbuf, buf, len); if (FAILURE == php_mimepart_process_line(part TSRMLS_CC)) Index: pear/PECL/mailparse/tests/006.phpt diff -u pear/PECL/mailparse/tests/006.phpt:1.3 pear/PECL/mailparse/tests/006.phpt:1.4 --- pear/PECL/mailparse/tests/006.phpt:1.3 Wed Sep 25 18:55:26 2002 +++ pear/PECL/mailparse/tests/006.phpt Fri Nov 8 09:52:16 2002 @@ -38,26 +38,26 @@ echo "-->\n"; echo $result; -echo "Extract to open file\n"; +echo "\nExtract to open file\n"; $fpdest = tmpfile(); mailparse_msg_extract_part_file($mime, $fp, $fpdest); -echo "rewinding\n"; +echo "\nrewinding\n"; rewind($fpdest); fpassthru($fpdest); -echo "Extract via user function\n"; +echo "\nExtract via user function\n"; $cbdata = ""; -function callback($data) { +function callbackfunc($data) { $GLOBALS["cbdata"] .= $data; } -mailparse_msg_extract_part_file($mime, $fp, "callback"); +mailparse_msg_extract_part_file($mime, $fp, "callbackfunc"); echo "callback data is:\n"; -echo $cbdata; +var_dump($cbdata); -echo "Extract whole part to output\n"; +echo "\nExtract whole part to output\n"; mailparse_msg_extract_whole_part_file($mime, $fp); -echo "Extract part from string to output\n"; +echo "\nExtract part from string to output\n"; mailparse_msg_extract_part($mime, $text); fclose($fpdest); fclose($fp); @@ -71,14 +71,19 @@ --> hello, this is some text hello. blah blah blah. + Extract to open file + rewinding hello, this is some text hello. blah blah blah. + Extract via user function callback data is: -hello, this is some text hello. +string(48) "hello, this is some text hello. blah blah blah. +" + Extract whole part to output To: fred@bloggs.com Mime-Version: 1.0 @@ -87,7 +92,7 @@ hello, this is some text hello. blah blah blah. + Extract part from string to output hello, this is some text hello. blah blah blah. -

« previous php.pear.cvs (#7320) next »