Skip to content

Commit 86d6151

Browse files
hardening: move to argument array pattern for shell execution (backport to 1.2.x)
1 parent 12f368e commit 86d6151

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/poller.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,15 @@ function exec_poll_php($command, $using_proc_function, $pipes, $proc_fd) {
130130
* @return (void)
131131
*/
132132
function exec_background($filename, $args = '', $redirect_args = '') {
133-
global $config, $debug;
133+
global $debug;
134+
135+
if (is_array($args)) {
136+
$args = implode(' ', array_map('cacti_escapeshellarg', $args));
137+
}
138+
139+
if (is_array($redirect_args)) {
140+
$redirect_args = implode(' ', $redirect_args);
141+
}
134142

135143
cacti_log("DEBUG: About to Spawn a Remote Process [CMD: $filename, ARGS: $args]", true, 'POLLER', ($debug ? POLLER_VERBOSITY_NONE:POLLER_VERBOSITY_DEBUG));
136144

lib/rrd.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ function rrdtool_execute() {
255255
function __rrd_execute($command_line, $log_to_stdout, $output_flag, $rrdtool_pipe = false, $logopt = 'WEBLOG') {
256256
global $config;
257257

258+
if (is_array($command_line)) {
259+
$command_line = implode(' ', array_map('cacti_escapeshellarg', $command_line));
260+
}
261+
258262
static $last_command;
259263

260264
if (!is_numeric($output_flag)) {

0 commit comments

Comments
 (0)