From a7134e60d8778366dd4c703dae6530bcd2e79109 Mon Sep 17 00:00:00 2001 From: Ian Berry Date: Fri, 11 Apr 2003 05:36:58 +0000 Subject: [PATCH] fixed a problem when using one graph item with 'total all data sources' (bug#25); added security fixes from 0.6.8a git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/trunk/cacti@829 860744bd-22fc-0310-8c96-e9fe5004b5ca --- lib/rrd.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/rrd.php b/lib/rrd.php index d265126b0e..59cd594975 100644 --- a/lib/rrd.php +++ b/lib/rrd.php @@ -26,8 +26,8 @@ define("RRD_NL", " \\\n"); -function bufprint($text) { - $_SESSION["sess_debug_buffer"] .= $text; +function escape_command($command) { + return ereg_replace("(\\\$|`)", "", $command); } function rrdtool_execute($command_line, $log_command, $output_flag) { @@ -54,9 +54,9 @@ function rrdtool_execute($command_line, $log_command, $output_flag) { /* use popen to eliminate the zombie issue */ if ($config["cacti_server_os"] == "unix") { - $fp = popen(read_config_option("path_rrdtool") . " $command_line", "r"); + $fp = popen(read_config_option("path_rrdtool") . escape_command(" $command_line"), "r"); }elseif ($config["cacti_server_os"] == "win32") { - $fp = popen(read_config_option("path_rrdtool") . " $command_line", "rb"); + $fp = popen(read_config_option("path_rrdtool") . escape_command(" $command_line"), "rb"); } /* Return Flag: @@ -503,7 +503,13 @@ function rrdtool_function_graph($local_graph_id, $rra_id, $graph_data_array) { } } - $cdef_total = $cdef_total_ds . str_repeat("+,", ($item_count - 2)) . "+"; + /* if there is only one item to total, don't even bother with the summation. otherwise + cdef=a,b,c,+,+ is fine. */ + if ($item_count == 1) { + $cdef_total = str_replace(",", "", $cdef_total_ds); + }else{ + $cdef_total = $cdef_total_ds . str_repeat("+,", ($item_count - 2)) . "+"; + } } $cdef_string = str_replace("CURRENT_DATA_SOURCE", generate_graph_def_name((isset($cf_ds_cache{$graph_item["data_template_rrd_id"]}[$cf_id]) ? $cf_ds_cache{$graph_item["data_template_rrd_id"]}[$cf_id] : "0")), $cdef_string);