Skip to content

Commit 3a8ed7a

Browse files
fix(rrd): correctness fixes in graph rendering and rrdtool output handling (#7183)
* fix(rrd): correctness fixes in graph rendering and rrdtool output handling Found while reviewing the graph path; itemized in the PR description. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix(rrd): use explicit default case for graph date format Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * test(security): refresh sink inventory baseline for line shifts Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> --------- Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> Co-authored-by: TheWitness <thewitness@cacti.net>
1 parent 530cc1a commit 3a8ed7a

2 files changed

Lines changed: 33 additions & 27 deletions

File tree

lib/rrd.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,10 @@ function __rrd_execute($command_line, $log_to_stdout, $output_flag, $rrdtool_pip
383383
break;
384384
case RRDTOOL_OUTPUT_STDERR:
385385
case RRDTOOL_OUTPUT_RETURN_STDERR:
386-
$output = fgets($fp, 1000000);
386+
$output = '';
387+
while (!feof($fp)) {
388+
$output .= fgets($fp, 4096);
389+
}
387390

388391
if (isset($process)) {
389392
fclose($fp);
@@ -531,6 +534,7 @@ function __rrd_proxy_execute($command_line, $log_to_stdout, $output_flag, $rrdp=
531534
return rtrim(substr($output, 0, strpos($output, 'OK u')));
532535
break;
533536
case RRDTOOL_OUTPUT_STDERR:
537+
case RRDTOOL_OUTPUT_RETURN_STDERR:
534538
if (substr($output, 1, 3) == 'PNG') {
535539
return 'OK';
536540
}
@@ -540,7 +544,11 @@ function __rrd_proxy_execute($command_line, $log_to_stdout, $output_flag, $rrdp=
540544
if (substr($output, 0, 5) == '<?xml') {
541545
return 'SVG/XML Output OK';
542546
}
543-
print $output;
547+
if ($output_flag == RRDTOOL_OUTPUT_RETURN_STDERR) {
548+
return $output;
549+
} else {
550+
print $output;
551+
}
544552
break;
545553
case RRDTOOL_OUTPUT_BOOLEAN :
546554
return (substr_count($output, 'OK u')) ? true : false;
@@ -1324,11 +1332,6 @@ function rrd_function_process_graph_options($graph_start, $graph_end, &$graph, &
13241332
/* Replace "|query_*|" in the graph command to replace e.g. vertical_label. */
13251333
$graph_opts = rrd_substitute_host_query_data($graph_opts, $graph, array());
13261334

1327-
/* provide smooth lines */
1328-
if ($graph['slope_mode'] == 'on') {
1329-
$graph_opts .= '--slope-mode' . RRD_NL;
1330-
}
1331-
13321335
/* if the user desires a watermark set it */
13331336
$watermark = str_replace("'", '"', read_config_option('graph_watermark'));
13341337
if ($watermark != '') {
@@ -1599,7 +1602,7 @@ function rrdtool_function_graph($local_graph_id, $rra_id, $graph_data_array, $rr
15991602
/* remember the last CF for this data source for use with GPRINT
16001603
* if e.g. an AREA/AVERAGE and a LINE/MAX is used
16011604
* we will have AVERAGE first and then MAX, depending on GPRINT sequence */
1602-
$last_graph_cf['data_source_name']['local_data_template_rrd_id'] = $graph_cf;
1605+
$last_graph_cf[$graph_item['data_source_name']][$graph_item['local_data_template_rrd_id']] = $graph_cf;
16031606

16041607
/* remember this for second foreach loop */
16051608
$graph_items[$key]['cf_reference'] = $graph_cf;
@@ -1612,8 +1615,8 @@ function rrdtool_function_graph($local_graph_id, $rra_id, $graph_data_array, $rr
16121615
* see 'man rrdgraph_data' for the correct VDEF based notation
16131616
* so our task now is to 'guess' the very graph_item, this GPRINT is related to
16141617
* and to use that graph_item's CF */
1615-
if (isset($last_graph_cf['data_source_name']['local_data_template_rrd_id'])) {
1616-
$graph_cf = $last_graph_cf['data_source_name']['local_data_template_rrd_id'];
1618+
if (isset($last_graph_cf[$graph_item['data_source_name']][$graph_item['local_data_template_rrd_id']])) {
1619+
$graph_cf = $last_graph_cf[$graph_item['data_source_name']][$graph_item['local_data_template_rrd_id']];
16171620
/* remember this for second foreach loop */
16181621
$graph_items[$key]['cf_reference'] = $graph_cf;
16191622
} else {
@@ -2593,6 +2596,9 @@ function rrdtool_function_format_graph_date(&$graph_data_array) {
25932596
case GD_Y_MN_D:
25942597
$graph_date = 'Y' . $datecharacter . 'M' . $datecharacter . 'd H:i:s';
25952598
break;
2599+
default:
2600+
$graph_date = 'Y' . $datecharacter . 'm' . $datecharacter . 'd H:i:s';
2601+
break;
25962602
}
25972603

25982604
/* display the timespan for zoomed graphs */
@@ -3653,7 +3659,7 @@ function rrd_rra_clone($file_array, $cf, $rra_array, $debug) {
36533659
rrdtool_execute("restore -f $xml_file $file", false, RRDTOOL_OUTPUT_STDOUT, $rrdtool_pipe, 'UTIL');
36543660
/* scratch that XML file to avoid filling up the disk */
36553661
unlink($xml_file);
3656-
cacti_log('Deleted RRA(s) from RRDfile: ' . $file, false, 'UTIL');
3662+
cacti_log('Cloned RRA(s) in RRDfile: ' . $file, false, 'UTIL');
36573663
} else {
36583664
$check['err_msg'] = __('ERROR: RRDfile %s not writeable', $file);
36593665
return $check;
@@ -4108,7 +4114,7 @@ function rrdtool_create_error_image($string, $width = '', $height = '') {
41084114
imagecopyresized($nimage, $image, 0, 0, 0, 0, $width, $height, 450, 200);
41094115

41104116
/* create the image */
4111-
imagepng($image);
4117+
imagepng($nimage);
41124118
} else {
41134119
/* create the image */
41144120
imagepng($image);

tests/security/baselines/sink_inventory.baseline.tsv

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ cmd_exec ./lib/poller.php:64 * @param (array) $pipes - the array of r/w pip
6969
cmd_exec ./lib/poller.php:65 * @param (resource) $proc_fd - the file descriptor returned from proc_open()
7070
cmd_exec ./lib/rrd.php:317 $process = proc_open(read_config_option('path_rrdtool') . ' - ' . $debug, $descriptorspec, $pipes);
7171
cmd_exec ./lib/rrd.php:91 return popen($command, 'w');
72-
cmd_exec ./lib/rrd.php:940 $fp = popen($rrdtool_cmd, 'r');
72+
cmd_exec ./lib/rrd.php:948 $fp = popen($rrdtool_cmd, 'r');
7373
cmd_exec ./lib/rrdcheck.php:798 $process = proc_open($command, $fds, $pipes);
7474
cmd_exec ./lib/snmp.php:214 exec($command, $snmp_value);
7575
cmd_exec ./lib/snmp.php:314 exec($command, $snmp_value);
@@ -414,19 +414,19 @@ dynamic_include ./lib/reports.php:395 include_once($config['base_path'] . '/lib
414414
dynamic_include ./lib/reports.php:396 include_once($config['base_path'] . '/lib/html_reports.php');
415415
dynamic_include ./lib/reports.php:678 include_once($config['library_path'] . '/html_tree.php');
416416
dynamic_include ./lib/reports.php:755 include_once($config['base_path'] . '/lib/time.php');
417-
dynamic_include ./lib/rrd.php:1067 include($config['include_path'] . '/global_arrays.php');
418-
dynamic_include ./lib/rrd.php:1344 include_once($config['library_path'] . '/cdef.php');
419-
dynamic_include ./lib/rrd.php:1345 include_once($config['library_path'] . '/vdef.php');
420-
dynamic_include ./lib/rrd.php:1346 include_once($config['library_path'] . '/graph_variables.php');
421-
dynamic_include ./lib/rrd.php:1347 include_once($config['library_path'] . '/boost.php');
422-
dynamic_include ./lib/rrd.php:1348 include_once($config['library_path'] . '/xml.php');
423-
dynamic_include ./lib/rrd.php:1349 include($config['include_path'] . '/global_arrays.php');
424-
dynamic_include ./lib/rrd.php:2630 include($rrdtheme);
425-
dynamic_include ./lib/rrd.php:3235 include_once($config['library_path'] . '/time.php');
426-
dynamic_include ./lib/rrd.php:4006 include($themefile);
427-
dynamic_include ./lib/rrd.php:590 include ($config['include_path'] . '/global_arrays.php');
428-
dynamic_include ./lib/rrd.php:909 include($config['include_path'] . '/global_arrays.php');
429-
dynamic_include ./lib/rrd.php:983 include_once($config['library_path'] . '/boost.php');
417+
dynamic_include ./lib/rrd.php:1075 include($config['include_path'] . '/global_arrays.php');
418+
dynamic_include ./lib/rrd.php:1347 include_once($config['library_path'] . '/cdef.php');
419+
dynamic_include ./lib/rrd.php:1348 include_once($config['library_path'] . '/vdef.php');
420+
dynamic_include ./lib/rrd.php:1349 include_once($config['library_path'] . '/graph_variables.php');
421+
dynamic_include ./lib/rrd.php:1350 include_once($config['library_path'] . '/boost.php');
422+
dynamic_include ./lib/rrd.php:1351 include_once($config['library_path'] . '/xml.php');
423+
dynamic_include ./lib/rrd.php:1352 include($config['include_path'] . '/global_arrays.php');
424+
dynamic_include ./lib/rrd.php:2636 include($rrdtheme);
425+
dynamic_include ./lib/rrd.php:3241 include_once($config['library_path'] . '/time.php');
426+
dynamic_include ./lib/rrd.php:4012 include($themefile);
427+
dynamic_include ./lib/rrd.php:598 include ($config['include_path'] . '/global_arrays.php');
428+
dynamic_include ./lib/rrd.php:917 include($config['include_path'] . '/global_arrays.php');
429+
dynamic_include ./lib/rrd.php:991 include_once($config['library_path'] . '/boost.php');
430430
dynamic_include ./lib/rrdcheck.php:716 include_once($config['base_path'] . '/lib/rrd.php');
431431
dynamic_include ./lib/rrdcheck.php:746 include_once($config['library_path'] . '/poller.php');
432432
dynamic_include ./lib/snmp.php:49 include_once($config['include_path'] . '/vendor/phpsnmp/extension.php');
@@ -578,7 +578,7 @@ fs_write ./lib/poller.php:1306 file_put_contents($mypath, $contents);
578578
fs_write ./lib/poller.php:1335 file_put_contents($mypath, $contents);
579579
fs_write ./lib/reports.php:1704 $f = fopen($fn, 'wb');
580580
fs_write ./lib/reports.php:1745 $f = fopen($fn, 'wb');
581-
fs_write ./lib/rrd.php:2517 if ($fp = fopen($graph_data_array['export_realtime'], 'w')) {
581+
fs_write ./lib/rrd.php:2520 if ($fp = fopen($graph_data_array['export_realtime'], 'w')) {
582582
fs_write ./lib/spikekill.php:780 return file_put_contents($xmlfile, $output);
583583
fs_write ./package_import.php:385 file_put_contents($xmlfile, $data);
584584
fs_write ./package_import.php:96 if (file_put_contents($xmlfile, $_SESSION['sess_import_package']) === false) {

0 commit comments

Comments
 (0)