cvs: php4 /pear/XML Parser.php
| From: | Thomas V.V.Cox | Date: | Mon, 17 Sep 2001 13:55:31 +0000 |
| Subject: | cvs: php4 /pear/XML Parser.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-854@lists.php.net to get a copy of this message | ||
cox Mon Sep 17 09:55:31 2001 EDT
Modified files:
/php4/pear/XML Parser.php
Log:
- Fix a security hole when the xml tag name is equal to a defined method
(i.e. <funcStartHandler>). From now, prefix the "xmltag_" string to the
function names when using the 'func' mode. See @notes for more info.
- Use call_user_func() when php >= 4.0.7 instead of the deprecated
call_user_method().
Index: php4/pear/XML/Parser.php
diff -u php4/pear/XML/Parser.php:1.16 php4/pear/XML/Parser.php:1.17
--- php4/pear/XML/Parser.php:1.16 Thu Jul 5 21:32:04 2001
+++ php4/pear/XML/Parser.php Mon Sep 17 09:55:31 2001
@@ -17,21 +17,26 @@
// | |
// +----------------------------------------------------------------------+
//
+// $Id: Parser.php,v 1.17 2001/09/17 13:55:31 cox Exp $
require_once "PEAR.php";
/**
- * XML Parser class. This is an XML parser based on PHP's "xml" extension,
- * based on the bundled expat library.
- *
- * @author Stig Bakken <ssb@fast.no>
- * @todo Tests that need to be made:
- * - error class
- * - mixing character encodings
- * - a test using all expat handlers
- * - options (folding, output charset)
- * - different parsing modes
- * @notes It requires PHP 4.0.4pl1 or greater
+* XML Parser class. This is an XML parser based on PHP's "xml" extension,
+* based on the bundled expat library.
+*
+* @author Stig Bakken <ssb@fast.no>
+* @todo Tests that need to be made:
+* - error class
+* - mixing character encodings
+* - a test using all expat handlers
+* - options (folding, output charset)
+* - different parsing modes
+*
+* @notes - It requires PHP 4.0.4pl1 or greater
+* - From revision 1.17, the function names used by the 'func' mode
+* are in the format "xmltag_$elem", for example: use "xmltag_name"
+* to handle the <name></name> tags of your xml file.
*/
class XML_Parser extends PEAR {
// {{{ properties
@@ -76,6 +81,12 @@
/** @var string target encoding */
var $tgtenc;
+ /*
+ * Use call_user_func when php >= 4.0.7
+ * @var boolean
+ * @see setMode()
+ */
+ var $use_call_user_func = true;
// }}}
// {{{ constructor
@@ -132,6 +143,17 @@
switch ($mode) {
case "func":
+ // use call_user_func() when php >= 4.0.7
+ // or call_user_method() if not
+ // XXXX add the php version comparing code to PEAR.php?
+ list($v, ) = explode('-', PHP_VERSION); // 4.0.7-dev
+ list($php_ver, $php_rel, $php_patch) = explode('.', $v);
+ if ($php_ver >= 4 && ($php_rel > 0 || $php_patch >= 7)) {
+ $this->use_call_user_func = true;
+ } else {
+ $this->use_call_user_func = false;
+ }
+
xml_set_element_handler($this->parser, "funcStartHandler",
"funcEndHandler");
break;
@@ -248,10 +270,15 @@
// }}}
// {{{ funcStartHandler()
- function funcStartHandler($xp, $elem, $attribs) {
-
- if (method_exists($this, $elem)) {
- call_user_method($elem, $this, $xp, $elem, &$attribs);
+ function funcStartHandler($xp, $elem, $attribs)
+ {
+ $func = 'xmltag_' . $elem;
+ if (method_exists($this, $func)) {
+ if ($this->use_call_user_func) {
+ call_user_func(array(&$this, $func), $xp, $elem, $attribs);
+ } else {
+ call_user_method($func, $this, $xp, $elem, $attribs);
+ }
}
}
@@ -261,18 +288,21 @@
function funcEndHandler($xp, $elem)
{
- $func = $elem . '_';
+ $func = 'xmltag_' . $elem . '_';
if (method_exists($this, $func)) {
- call_user_method($func, $this, $xp, $elem);
+ if ($this->use_call_user_func) {
+ call_user_func(array(&$this, $func), $xp, $elem);
+ } else {
+ call_user_method($func, $this, $xp, $elem);
+ }
}
}
-
/**
*
* @abstract
*/
- function StartHandler($xp, $elem, $attribs)
+ function StartHandler($xp, $elem, &$attribs)
{
return NULL;
}