Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.1.7

Bug #17381 infinite loop in __destruct of generated parser
Submitted: 2010-05-07 21:47 UTC Modified: 2010-08-08 19:40 UTC
From: thue Assigned: jespino
Status: Closed Package: PHP_ParserGenerator (version 0.1.6)
PHP Version: Irrelevant OS: All
Roadmaps: (Not assigned)    

 [2010-05-07 21:47 UTC] thue (Thue Kristensen)
Description: ------------ The __destruct() of the generated parser can go into an infinite loop. Test script: --------------- # cat test.php %name TEST_ %token_prefix TEST_ %declare_class {class test} %include { $a = new test(); $a->lala(); } %include_class { public function lala() { exit(1); } } start ::= . # cat create_parser.php require_once(dirname(__FILE__)."/../../../../lib/parser_generator/ParserGenerator.php"); $parser = new PHP_ParserGenerator(); $parser->main(); # php create_parser.php test.y Expected result: ---------------- Program terminates... Actual result: -------------- Infinite loop in the __destruct code while ($this->yyidx >= 0) { $this->yy_pop_parser_stack(); } since $this->yyidx===0 and $this->yystack===Array(), and $this->yy_pop_parser_stack(); does if (!count($this->yystack)) { return; }


 [2010-08-06 22:28 UTC] jespino (Jesús Espino)
I think this is a duplication of bug #12730.
 [2010-08-07 19:17 UTC] thue (Thue Kristensen)
Agreed. But mine has a test case :). In any case, it is trivial to fix. #12730 has a fix, and I have a (slightly better, perhaps) fix in my private tree.
 [2010-08-08 15:47 UTC] jespino (Jesús Espino)
Please, add the patch here to apply it to the package.
 [2010-08-08 18:08 UTC] thue (Thue Kristensen)
My fix was simply to use $this->yystack !== Array() for checking whether the stack was empty, instead $yyidx . This way, it will not go into an infinite loop even if $yyidx gets out of sync. Something like while ($this->yystack !== Array()) { $this->yy_pop_parser_stack(); }
 [2010-08-08 19:40 UTC] jespino (Jesús Espino)
-Status: Open +Status: Closed -Assigned To: +Assigned To: jespino
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on by the end of next Sunday (CET). If this was a problem with the website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. Applied the patch of Thue Kristensen