From e11b62adab0d5c04971a061bfeeb62da5084957b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 22 Jul 2016 01:41:43 -0700 Subject: [PATCH] Improve error reporting for XML RPCs - If handling an XML RPC, use set_error_handler() to output PHP warnings as XML. Otherwise they appear as strings in the XML reply, making them not parse. - suppress warnings from PHP function calls where we're already checking errors --- html/inc/dir_hier.inc | 2 +- html/inc/util_basic.inc | 10 ++++++++-- html/inc/xml.inc | 11 +++++++++++ html/user/job_file.php | 2 +- html/user/manage_project.php | 2 -- html/user/submit_rpc_handler.php | 8 ++++---- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/html/inc/dir_hier.inc b/html/inc/dir_hier.inc index 0b24324ed4..1d806b05dd 100644 --- a/html/inc/dir_hier.inc +++ b/html/inc/dir_hier.inc @@ -16,7 +16,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with BOINC. If not, see . -// PHP versions of functions in sched/sched_util.C +// PHP versions of functions in sched/sched_util.cpp function filename_hash($filename, $fanout) { $m = md5($filename); diff --git a/html/inc/util_basic.inc b/html/inc/util_basic.inc index 3bc578b254..55ba0fabee 100644 --- a/html/inc/util_basic.inc +++ b/html/inc/util_basic.inc @@ -44,7 +44,7 @@ function show_page($x, $y) { "; } -function xml_error($num, $msg=null) { +function xml_error($num, $msg=null, $file=null, $line=null) { if (!$msg) { switch($num) { case -112: $msg = "Invalid XML"; break; @@ -64,8 +64,14 @@ function xml_error($num, $msg=null) { echo " $num $msg - "; + if ($file) { + echo " $file\n"; + } + if ($line) { + echo " $line\n"; + } + echo "\n"; exit(); } diff --git a/html/inc/xml.inc b/html/inc/xml.inc index 7883f249b6..21d51097d0 100644 --- a/html/inc/xml.inc +++ b/html/inc/xml.inc @@ -29,8 +29,19 @@ function db_init_xml() { return 0; } +function handler($errno, $errstr, $errfile, $errline) { + echo " + $errstr + $errfile + $errline + +"; +} + + function xml_header() { global $generating_xml; + set_error_handler('handler', E_ALL); header('Content-type: text/xml'); echo "\n"; $generating_xml = true; diff --git a/html/user/job_file.php b/html/user/job_file.php index c0302eba61..36f5c29f01 100644 --- a/html/user/job_file.php +++ b/html/user/job_file.php @@ -192,7 +192,7 @@ if (0) { xml_header(); $r = simplexml_load_string($_POST['request']); if (!$r) { - xml_error(-1, "can't parse request message"); + xml_error(-1, "can't parse request message", __FILE__, __LINE__); } switch($r->getName()) { diff --git a/html/user/manage_project.php b/html/user/manage_project.php index f5985885ed..2ad9735bda 100644 --- a/html/user/manage_project.php +++ b/html/user/manage_project.php @@ -117,8 +117,6 @@ function handle_edit_form() { } $q = (string) $usub->quota; $mj = $usub->max_jobs_in_progress; - $sav = $usub->create_app_versions?"checked":""; - $sa = $usub->create_apps?"checked":""; echo "

Quota: diff --git a/html/user/submit_rpc_handler.php b/html/user/submit_rpc_handler.php index afea766d37..27d253040a 100644 --- a/html/user/submit_rpc_handler.php +++ b/html/user/submit_rpc_handler.php @@ -132,28 +132,28 @@ function stage_file($file) { // read the file (from disk or network) to get MD5. // Copy to download hier, using a physical name based on MD5 // - $md5 = md5_file($file->source); + $md5 = @md5_file($file->source); if (!$md5) { xml_error(-1, "BOINC server: Can't get MD5 of file $file->source"); } $name = "jf_$md5"; $path = dir_hier_path($name, $download_dir, $fanout); if (file_exists($path)) return $name; - if (!copy($file->source, $path)) { + if (!@copy($file->source, $path)) { xml_error(-1, "BOINC server: can't copy file from $file->source to $path"); } return $name; case "local_staged": return $file->source; case "inline": - $md5 = md5($file->source); + $md5 = @md5($file->source); if (!$md5) { xml_error(-1, "BOINC server: Can't get MD5 of inline data"); } $name = "jf_$md5"; $path = dir_hier_path($name, $download_dir, $fanout); if (file_exists($path)) return $name; - if (!file_put_contents($path, $file->source)) { + if (!@file_put_contents($path, $file->source)) { xml_error(-1, "BOINC server: can't write to file $path"); } return $name;