PHP4 Bug #1812: Crash when a switch is within a for loop parsing thru a string. :)
| From: | C dot Just at its dot uq dot edu dot au | Date: | Wed, 21 Jul 1999 23:46:09 +0000 |
| Subject: | PHP4 Bug #1812: Crash when a switch is within a for loop parsing thru a string. :) | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-8930@lists.php.net to get a copy of this message | ||
From: C.Just@its.uq.edu.au
Operating system: Win32 (Pretty sure it\'s Independant though)
PHP version: 4.0 Beta 1
PHP Bug Type: Reproduceable crash
Bug description: Crash when a switch is within a for loop parsing thru a string. :)
Here is a sequence of code which I found doesn't work.
I have a better way of performing this function with regexp's but this should work without
crashing anyway.
I have had a play with this function removing bits here and there to find out exactly where the
problem is.
It seems that if you remove this section.
-----------
case "<":
$stack++;
break;
case ">":
$stack--;
break;
-----------
There is no crash.
Also if the for loop is removed there is no crash.
Also if I replace the switch statement line with this
------------
$temp = $str[$i];
switch($temp) {
------------
It works too.
Thought that might make it a bit easier to track down.
Here is the function below.
------------------------------
function StripHTML($str) {
$dest = "";
$stack = 0;
for ($i=0;$i<strlen($str);$i++) {
switch($str[$i]) {
case "<":
$stack++;
break;
case ">":
$stack--;
break;
default:
if (!$stack) {
$dest .= $str[$i];
}
break;
}
}
return $dest;
}
---------------------------