PHP 4.0 Bug #7219: Mysql-related stack fault with PHP 4.0.3

From: Date: Sun, 15 Oct 2000 13:35:04 +0000
Subject: PHP 4.0 Bug #7219: Mysql-related stack fault with PHP 4.0.3
Groups: php.dev 
Request: Send a blank email to php-dev+get-35046@lists.php.net to get a copy of this message
From: rubein@earthlink.net Operating system: Win98 PHP version: 4.0.3 PHP Bug Type: *General Issues Bug description: Mysql-related stack fault with PHP 4.0.3 The following section of code produces a stack fault in PHP 4.0.3: while(1) { $append = array(); $append[0] = $resid; switch($restype) { case "messages": case "m": $append[1] = "messages"; $child = "messages"; $parent = "threads"; break; case "threads": case "t": $append[1] = "threads"; $child = "threads"; $parent = "boards"; break; case "boards": case "b": $append[1] = "boards"; $child = "boards"; $parent = "boards"; break; case "realms": case "r": $append[1] = "realms"; $restype = "realms"; break; } $ret[] = $append; if($restype == "realms") return $ret; $result = mysql_query("SELECT p.id AS id FROM $child AS c, $parent AS p WHERE c.id=$resid AND p.id=c.parent"); // THis is line 378. if($result = mysql_fetch_array($result, MYSQL_ASSOC)) { $restype = $parent; $resid = $result["id"]; } else { $restype = "realms"; $resid = $realmid; } } Judging from some debug code I tossed in, this (bad) query is being sent to mysql: SELECT p.id AS id FROM AS c, AS p WHERE c.id=1 AND p.id=c.parent Although the query is incorrect (there's apparently a bug in my code somewhere, but that's irrelevant for the purposes of this bug report), it would make far more sense for PHP to either catch itself or at least get caught in an infinite loop. Instead, it stack faults: PHP caused a stack fault in module MSVCRT.DLL at 015f:780035be. Registers: EAX=00542138 CS=015f EIP=780035be EFLGS=00010216 EBX=00000002 SS=0167 ESP=00541ed8 EBP=00000000 ECX=00543174 DS=0167 ESI=00000000 FS=9e6f EDX=100cdcf4 ES=0167 EDI=007634a0 GS=0000 Bytes at CS:EIP: 53 55 56 57 8b bc 24 64 02 00 00 33 c9 33 ed 89 Stack dump: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 This bug is reproduced any time the script is reloaded. The warning (Repeated several, several times) is this: Warning: Supplied argument is not a valid MySQL result resource in include.php on line 378 Operating system: Win98 Webserver: Apache 1.3.12/Win32 PHP: 4.0.3, running as a CGI module Using the built-in mysql extensions under MySQL 3.23.25-beta (as determined by SELECT version();) - Daniel Grace -- Edit Bug report at: http://bugs.php.net/?id=7219&edit=1

« previous php.dev (#35046) next »