#40033 [Opn->Fbk]: Server Crashes when Throwing an Exception

From: Date: Mon, 08 Jan 2007 17:42:48 +0000
Subject: #40033 [Opn->Fbk]: Server Crashes when Throwing an Exception
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-107324@lists.php.net to get a copy of this message
 ID:               40033
 Updated by:       rrichards@php.net
 Reported By:      francisco dot a dot castillo at ge dot com
-Status:           Open
+Status:           Feedback
 Bug Type:         Reproducible crash
 Operating System: Linux Fedora Core 6
 PHP Version:      5.2.0
 New Comment:

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

Looking at the stack trace this looks like same as bug #39625,   so
please try a snap.


Previous Comments:
------------------------------------------------------------------------

[2007-01-08 17:21:06] francisco dot a dot castillo at ge dot com

Just write to know what happen with this bug 'cause I haven't received
any information of the status. I have my server down because of this.

Thanks for your attention

------------------------------------------------------------------------

[2007-01-05 22:07:11] francisco dot a dot castillo at ge dot com

Well, I saw that the backtrace threw a problem regarding the XSL, well,
I'll paste the code but I use a transformation when throwing an
exception, so, I could show it passing an XML to an XSL. This is the
code:

Throws the Exception:
try{
  throw new PHPDevException($this ->
error,100,"DAO",$part,false,"SQL","SQL DAO",$qry);		   }catch
(PHPDevException $ac){
      $ac -> toScreen();
      die();
   }	

The Exception class:

<?
	//require_once("classes/DAO.inc.php");
	//require_once("Config.inc.php");
	require_once("XSLoader.inc.php");
	
	/**
	 * @author Francisco A. Castillo Guerrero. This class handles
	 * all the exceptions created by the assessment center
	 * redesign.
	 */
	class PHPDevException extends Exception{		
		
		protected   $code;
		protected   $message;
		protected   $title;
		protected 	$fclass;
		protected 	$method;
		protected 	$line;
		protected 	$sys;
		protected 	$uri;
		protected 	$sql;
		protected 	$redire;
		
		/**
		 * This is the constructor of the exception class. This method is
called when a new
		 * instance is created. This happens when you throw a new
PHPDevException.
		 * The parameters that receives are the following:
		 *
		 * @param String 	$errmsg
		 * @param int 		$errcode
		 * @param String 	$class
		 * @param String 	$method
		 * @param boolena 	$redire
		 * @param String 	$title
		 * @param String 	$system
		 * @param String 	$sql
		 */
		public function __construct($errmsg, $errcode, $class, $method,
$redire, $title = 'AC', $system = '', $sql = ''){			
			$this -> title = $title;
			$this -> fclass = $class;			
			$this -> method = $method;
			$this -> message = $errmsg;
			$this -> code = $errcode;
			$this -> line = parent::getLine();
			$this -> sys = $system;
			$this -> uri   = $_SERVER['PHP_SELF'];
			$this -> sql = $sql;
			$this -> redire = $redire;
			
			parent::__construct($errmsg,$errcode);
		}
    	
		/**
		 * Inserts into the log table, the content of this Exception.
		 * In the imformation inserted includes parameters from the
		 * same class and are the following:
		 * 
		 * @param Date 		ltime. 		Date of the insertion
		 * @param Long 		time_stamp.	Time stamp of the date
		 * @param String	cname		Class name from the generated exception
		 * @param String	method		Method of the class where the exception was
thrown
		 * @param Int		lineNumber	Line where the exception was thrown
		 * @param String	system_name	Name of the system
		 * @param String	uri			Part of the url that generated the exception
		 * @param String	Message		Message of the exception
		 *
		 */
		 
    	public function toLog(){
    	    // Log the content of the Exception.
    	    $dao = new DAO(true);
    	    
    	    $ts = mktime();
    	    $date = date("Y/m/d", $ts);
    	    
    	    
    	    $table = "logger(ltime, time_stamp, cname, method, lineNumber,
msg_code, system_name, uri, message)";
    	    $vals = "'$date', $ts,'".
    	    $this -> fclass."','".
    	    $this -> method."',".
    	    $this -> line.",'".
    	    $this -> code."','".
    	    $this -> sys."','".
    	    $this -> uri."','".
    	    $this -> message."'";
    	    
    	    $dao -> insert($table,$vals);
    	    $this -> redir();    		
    	}
    	
    	/**
    	 * Output the exception to the browser
    	 *
    	 */
    	public function toScreen(){
    		
    		$this -> redir();
    		
    		print $this -> formatException($this -> message);    			
    	}
    	
    	/**
    	 * Outputs the exception and save it into the log
    	 *
    	 */
    	public function toBoth(){
    		$this -> redir();
    		$this -> toScreen();
    		$this -> toLog();
    	}
    	
    	/**
    	 * Redirects the page if an exception is raised and if the
redirect
    	 * flag is active (true) in the Config file
    	 *
    	 */
    	private function redir(){
    		global $redirect;
    		
    		if($this -> redire === true){
    			//header("Location: $redirect");
    			
    			print
"<script>setTimeout('self.location.href=\"$redirect\"',0)</script>";
    		}    		
    	}
    	
    	/**
    	 * This method formats the output to be shown in the browser.
    	 * Only receives the message to format and returns the
    	 * formatted string    	 
    	 *
    	 * @param 	String	msg		Message to format
    	 * @return 	String 	em		The HTML formated string
    	 */
    	private function formatException($msg){
    		$xml = "
			<exception>
			<title>".$this -> title." Exception Raised</title>
			<content>
				<element name='Query'><val>".$this ->
sql."</val></element>
				<element name='Class'><val>".$this ->
fclass."</val></element>
				<element name='Method'><val>".$this ->
method."</val></element>
				<element name='Line Number'><val>".$this ->
line."</val></element>
				<element
name='Description'><val>".$msg."</val></element>				
			</content>
			</exception>";
    		//print $xml;die();
    		$path = getcwd()."\\exceptions";
    		
		return XSLoader::load($xml,"xslt\\".__CLASS__);
	}
}
?>

The Transformer Class:

<?
	class XSLoader
	{
		/**
		 * Transforms an XML with the XSL received and returns the 
		 * transformed string.
		 *
		 * @param 	String $xml
		 * @param 	String $xsl_file
		 * @return 	String Transformed Document
		 */
		public function load($xml,$xsl_file)
		{
			$doc = new DOMDocument();
			$xsl = new XSLTProcessor();
			
			$doc -> load($xsl_file.'.xsl');
			$xsl -> importStyleSheet($doc);
			
			$doc -> loadXML($xml);
			
			return $xsl -> transformToXML($doc);
		}
	}	
?>

Thanks! Regards!

------------------------------------------------------------------------

[2007-01-05 22:01:22] iliaa@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 the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.



------------------------------------------------------------------------

[2007-01-05 21:00:43] francisco dot a dot castillo at ge dot com

This is the backtrace:

#0  0x0120e61a in zif_xsl_xsltprocessor_import_stylesheet (ht=1,
return_value=0xa1003c0, return_value_ptr=0x0,
    this_ptr=0xa0fffb0, return_value_used=0) at
/http/php-5.2.0/ext/xsl/xsltprocessor.c:387
#1  0x012789d8 in zend_do_fcall_common_helper_SPEC
(execute_data=0xbf871ba0) at
/http/php-5.2.0/Zend/zend_vm_execute.h:200
#2  0x0126a81d in execute (op_array=0xa0b65c8) at
/http/php-5.2.0/Zend/zend_vm_execute.h:92
#3  0x0127844c in zend_do_fcall_common_helper_SPEC
(execute_data=0xbf871ec0) at
/http/php-5.2.0/Zend/zend_vm_execute.h:234
#4  0x0126a81d in execute (op_array=0xa0bdfb4) at
/http/php-5.2.0/Zend/zend_vm_execute.h:92
#5  0x0127844c in zend_do_fcall_common_helper_SPEC
(execute_data=0xbf872070) at
/http/php-5.2.0/Zend/zend_vm_execute.h:234
#6  0x0126a81d in execute (op_array=0xa0bb158) at
/http/php-5.2.0/Zend/zend_vm_execute.h:92
#7  0x0127844c in zend_do_fcall_common_helper_SPEC
(execute_data=0xbf8722a0) at
/http/php-5.2.0/Zend/zend_vm_execute.h:234
#8  0x0126a81d in execute (op_array=0x9fa8404) at
/http/php-5.2.0/Zend/zend_vm_execute.h:92
#9  0x0127844c in zend_do_fcall_common_helper_SPEC
(execute_data=0xbf872520) at
/http/php-5.2.0/Zend/zend_vm_execute.h:234
#10 0x0126a81d in execute (op_array=0x9f9c1a8) at
/http/php-5.2.0/Zend/zend_vm_execute.h:92
#11 0x0127844c in zend_do_fcall_common_helper_SPEC
(execute_data=0xbf8726f0) at
/http/php-5.2.0/Zend/zend_vm_execute.h:234
#12 0x0126a81d in execute (op_array=0x9fb8fe0) at
/http/php-5.2.0/Zend/zend_vm_execute.h:92
#13 0x0127844c in zend_do_fcall_common_helper_SPEC
(execute_data=0xbf872880) at
/http/php-5.2.0/Zend/zend_vm_execute.h:234
#14 0x0126a81d in execute (op_array=0x9fa5b08) at
/http/php-5.2.0/Zend/zend_vm_execute.h:92
#15 0x0127844c in zend_do_fcall_common_helper_SPEC
(execute_data=0xbf872a20) at
/http/php-5.2.0/Zend/zend_vm_execute.h:234
#16 0x0126a81d in execute (op_array=0x9f9d934) at
/http/php-5.2.0/Zend/zend_vm_execute.h:92
#17 0x0127844c in zend_do_fcall_common_helper_SPEC
(execute_data=0xbf872ec0) at
/http/php-5.2.0/Zend/zend_vm_execute.h:234
#18 0x0126a81d in execute (op_array=0x9f9db54) at
/http/php-5.2.0/Zend/zend_vm_execute.h:92
#19 0x0127844c in zend_do_fcall_common_helper_SPEC
(execute_data=0xbf8730c0) at
/http/php-5.2.0/Zend/zend_vm_execute.h:234
#20 0x0126a81d in execute (op_array=0x9f9eefc) at
/http/php-5.2.0/Zend/zend_vm_execute.h:92
#21 0x0127844c in zend_do_fcall_common_helper_SPEC
(execute_data=0xbf8732c0) at
/http/php-5.2.0/Zend/zend_vm_execute.h:234
#22 0x0126a81d in execute (op_array=0x9f9b44c) at
/http/php-5.2.0/Zend/zend_vm_execute.h:92
#23 0x0124f1c2 in zend_execute_scripts (type=8, retval=<value optimized
out>, file_count=3)
    at /http/php-5.2.0/Zend/zend.c:1097
#24 0x01211a13 in php_execute_script (primary_file=0xbf8755e8) at
/http/php-5.2.0/main/main.c:1758
#25 0x012c5420 in php_handler (r=0x9f90328) at
/http/php-5.2.0/sapi/apache2handler/sapi_apache2.c:592
#26 0x0807ac59 in ap_run_handler (r=0x9f90328) at config.c:157
#27 0x0807ddc1 in ap_invoke_handler (r=0x9f90328) at config.c:371
#28 0x080c0bb8 in ap_process_request (r=0x9f90328) at
http_request.c:258
#29 0x080bdebb in ap_process_http_connection (c=0x9f7e120) at
http_core.c:184
#30 0x08081a59 in ap_run_process_connection (c=0x9f7e120) at
connection.c:43
#31 0x080d6b50 in child_main (child_num_arg=<value optimized out>) at
prefork.c:640
#32 0x080d6db3 in make_child (s=0x9db8b58, slot=0) at prefork.c:680
#33 0x080d7b96 in ap_mpm_run (_pconf=0x9db20a8, plog=0x9dfa1c8,
s=0x9db8b58) at prefork.c:956
#34 0x08068a95 in main (argc=165347616, argv=0x9e804a8) at main.c:717

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/40033

-- 
Edit this bug report at http://bugs.php.net/?id=40033&edit=1


Thread (8 messages)

« previous php.bugs (#107324) next »