php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27380 Segmentation fault executing do..while() loops inside block containers
Submitted: 2004-02-24 11:26 UTC Modified: 2004-03-08 07:11 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: josh at hostyour dot info Assigned:
Status: No Feedback Package: Reproducible crash
PHP Version: 4.3.4 OS: RH7.3
Private report: No CVE-ID: None
 [2004-02-24 11:26 UTC] josh at hostyour dot info
Description:
------------
If I have a function that has a do..while(); construction in it, inside a block container { }, PHP will segfault on exiting the block container UNLESS I have a statement in between the end of the while (); and the closing brace of the block.

This does NOT happen in "global" execution.  A do..while() loop that lives outside any function's scope works just fine; I have several other do..while() constructs outside of functions that work with no problems.  The segfault seems to only happen when the do..while(); is inside a function AND inside a block container (in this case, belonging to an if statement).

Any ideas?

Reproduce code:
---------------
function announce()
{
	global $totalRows_announce, $row_announce, $announce, $srs;

	$ann = "";

	if ($totalRows_announce > 0) {
		do {
			$author = mysql_result(mysql_query("SELECT nick FROM players WHERE id='".$row_announce['author']."'", $srs), 0, "nick") or die(mysql_error());
			$msg_body = stripslashes(implode("<br>",explode("\n",$row_announce['msg_body'])));
			$ann .= textBlock(textBlock($row_announce['subject'], "", "anntitle") . br() . 
				textBlock("Posted by:".$author." | On: ".$row_announce['posted_date'], "", "annhead") . br() .
				textBlock($msg_body, "", "annbody"), "", (($row_announce['urgent'] == 1) ? "redrow" : ((($ctr++) % 2) ? "lightrow" : "darkrow"))) . br();
		} while ($row_announce = mysql_fetch_assoc($announce));
        // Segfault happens HERE
	} else {
		$ann = textBlock("No Announcements", "", "loginerr");
	} 
	return $ann;
}


Expected result:
----------------
The code, as intended, returns a string of HTML code to the calling function.

Actual result:
--------------
The code immediately segfaults when it encounters the closing brace of the do..while() loop's block container UNLESS there is an intervening statement.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-24 11:32 UTC] derick@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try avoid embedding huge scripts into the report.

Can't reproduce this with only a part of a script.
 [2004-02-24 17:04 UTC] sniper@php.net
And ditch the mysql stuff from the reproducing script..
(a GDB backtrace might reveal something too?)

 [2004-03-08 07:11 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC