Skip to content

Commit

Permalink
Add script that will report all the errors of current-script-run. Thi…
Browse files Browse the repository at this point in the history
…s script is intended to be used same as common.inc.php, but at the end of each script.

Signed-off-by: Dhananjay Nakrani <dhananjaynakrani@gmail.com>
  • Loading branch information
JayNakrani committed May 9, 2014
1 parent 7d549c9 commit 7bdad8e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libraries/Error_Handler.class.php
Expand Up @@ -94,6 +94,15 @@ protected function getErrors()
return $this->errors;
}

/**
* returns the errorsoccured in the current run only. Does not include the errors save din the SESSION
*
*/
public function getCurrentErrors()
{
return $this->errors;
}

/**
* Error handler - called when errors are triggered/occurred
*
Expand Down
56 changes: 56 additions & 0 deletions libraries/common_error_reporting.inc.php
@@ -0,0 +1,56 @@
<?php

/**
* block attempts to directly run this script
*/
if (getcwd() == dirname(__FILE__)) {
die('Attack stopped');
}

This comment has been minimized.

Copy link
@nijel

nijel May 10, 2014

Please use the standard way we use in other libraries (if(defined('PHPMYADMIN'))...)

This comment has been minimized.

Copy link
@JayNakrani

JayNakrani May 11, 2014

Author Owner

I've added that part.
Please see 1eb9429b7a437b02d95ffbb06826232fe2dc238a


/** if there were any errors currently write them to a log file.
* Later it will be changed to submit them to the error reporting server.
*/
if($GLOBALS['error_handler']->hasErrors()) {
// then log them in a local file.
$path = "./pma_error_log.txt";
$fp = fopen($path, "w");

This comment has been minimized.

Copy link
@nijel

nijel May 10, 2014

I think using file is a bad idea here. In many cases it won't be writable and we have the data in session anyway, so why not to use the data from session later, rather than storing them somewhere else?

This comment has been minimized.

Copy link
@JayNakrani

JayNakrani May 10, 2014

Author Owner

I've used the file just to dump errors. File is temporary only. It will be removed in the next week. This script will then submit errors to server rather than dumping them in a file.


// for each errors in the list
foreach($GLOBALS['error_handler']->getCurrentErrors() as $errObj ) {
/**
* Following check is to avoid error reported by PMA_warnMissingExtension();
*
*/
if ($errObj->getLine() && $errObj->getType()) {
$str = "\n\n".$errObj->getFile() . "(#" . $errObj->getLine() . ")\n\t". $errObj->getTitle();
// for stack trace
// ------------------------------------------------------------------------------------------
$backtrace = $errObj->getBacktrace();
$error_str= "";
foreach($backtrace as $i=>$stack_frame)
{
$error_str .= "\n \t\t\t Frame[".$i."]: \tfile:".$stack_frame["file"]."\tline:".$stack_frame["line"]."\tfunction:".$stack_frame["function"]."(";
foreach($stack_frame["args"] as $j=>$arg)
{
if($j != 0)
{
$error_str .= ", ";
}

$error_str .= "arg[".$j."] = ".$arg;
}
$error_str .= ")";

if($i >= 5) // MAX 5 of stack frames.
{
break;
}
}
// ------------------------------------------------------------------------------------------
$retVal = fwrite ($fp , $str);
$retVal = fwrite ($fp , $error_str);
}
}
fclose($fp);
}
?>

3 comments on commit 7bdad8e

@JayNakrani
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

common_error_reporting.inc.php is supposed to be included at the end of every php scripts the same way common.inc.php is included at the beginning. common.inc.php already does the initialization of the error handler and everything. And that's why all the errors occurred during the php script execution are stored in an object of PMA_Error_Handler pointed by $GLOBALS['error_handler'].
At the end, simple inclusion of common_error_reporting.inc.php script will report all the stored errors. Currently it dumps them to a local log file named pma_error_log.txt which will not be needed in the actual code and hence will be removed shortly.

@phpmyadmin-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit is using tab character for indentation instead of spaces, what is mandated by phpMyAdmin. Please check our Developer guidelines for more information.

Offending files: libraries/common_error_reporting.inc.php

@phpmyadmin-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit contains trailing whitespace, what is prohibited in phpMyAdmin. Please check our Developer guidelines for more information.

Offending files: libraries/common_error_reporting.inc.php

Please sign in to comment.