From 6e4c2de28807ee088603bfe569d77bb667a0b418 Mon Sep 17 00:00:00 2001 From: Reinhard Scheck Date: Tue, 13 Aug 2013 19:32:49 +0000 Subject: [PATCH] fix COMMENT handling, even in case COMMENT is empty, with or without HR and with variable substitution git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/cacti/branches/0.8.8@7418 860744bd-22fc-0310-8c96-e9fe5004b5ca --- lib/rrd.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/rrd.php b/lib/rrd.php index 6e6e19ce0c..eaad29e823 100644 --- a/lib/rrd.php +++ b/lib/rrd.php @@ -1343,20 +1343,20 @@ function rrdtool_function_graph($local_graph_id, $rra_id, $graph_data_array, $rr $need_rrd_nl = TRUE; if ($graph_item_types{$graph_item["graph_type_id"]} == "COMMENT") { + # perform variable substitution first (in case this will yield an empty results or brings command injection problems) + $comment_arg = rrd_substitute_host_query_data($graph_variables["text_format"][$graph_item_id], $graph, $graph_item); + # next, compute the argument of the COMMENT statement and perform injection counter measures + if (trim($comment_arg) == '') { # an empty COMMENT must be treated with care + $comment_arg = cacti_escapeshellarg(' ' . $hardreturn[$graph_item_id]); + } else { + $comment_arg = cacti_escapeshellarg($comment_arg . $hardreturn[$graph_item_id]); + } + + # create rrdtool specific command line if (read_config_option("rrdtool_version") != "rrd-1.0.x") { - $comment_string = $graph_item_types{$graph_item["graph_type_id"]} . ":" . str_replace(":", "\:", cacti_escapeshellarg($graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id])) . " "; - if (trim($comment_string) == 'COMMENT:"\n"') { - $txt_graph_items .= 'COMMENT:" \n"'; # rrdtool will skip a COMMENT that holds a NL only; so add a blank to make NL work - } else if (trim($comment_string) != "COMMENT:\"\"") { - $txt_graph_items .= rrd_substitute_host_query_data($comment_string, $graph, $graph_item); - } + $txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . str_replace(":", "\:", $comment_arg) . " "; }else { - $comment_string = $graph_item_types{$graph_item["graph_type_id"]} . ":" . cacti_escapeshellarg($graph_variables["text_format"][$graph_item_id] . $hardreturn[$graph_item_id]) . " "; - if (trim($comment_string) == 'COMMENT:"\n"') { - $txt_graph_items .= 'COMMENT:" \n"'; # rrdtool will skip a COMMENT that holds a NL only; so add a blank to make NL work - } else if (trim($comment_string) != "COMMENT:\"\"") { - $txt_graph_items .= rrd_substitute_host_query_data($comment_string, $graph, $graph_item); - } + $txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $comment_arg . " "; } }elseif (($graph_item_types{$graph_item["graph_type_id"]} == "GPRINT") && (!isset($graph_data_array["graph_nolegend"]))) { $graph_variables["text_format"][$graph_item_id] = str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]); /* escape colons */