diff --git a/pandora_agents/pc/ChangeLog b/pandora_agents/pc/ChangeLog index edc0f2a263..e87f2ed8f8 100644 --- a/pandora_agents/pc/ChangeLog +++ b/pandora_agents/pc/ChangeLog @@ -1,3 +1,8 @@ +2012-05-30 Ramon Novoa + + * pandora_agent: Merged from unix agent. Check for valid regular + expressions before adding module conditions. + 2012-04-25 Miguel de Dios * DEBIAN/postinst, DEBIAN/make_deb_package.sh: disabled the checking diff --git a/pandora_agents/pc/pandora_agent b/pandora_agents/pc/pandora_agent index 82706381bd..080af0b8fa 100644 --- a/pandora_agents/pc/pandora_agent +++ b/pandora_agents/pc/pandora_agent @@ -220,7 +220,8 @@ my $OS_VERSION = guess_os_version ($OS); # Windows specific modules my $Win32 = undef; if ($OS eq 'windows') { - use PandoraWin32; + require PandoraWin32; + PandoraWin32->import(); } ################################################################################ @@ -241,6 +242,22 @@ sub error ($) { `logger -i -t pandora_agent_daemon [ERROR] $msg 2>/dev/null`; } +################################################################################ +# Check a regular expression. Returns 1 if its valid, 0 otherwise. +################################################################################ +sub valid_regexp ($) { + my $regexp = shift; + + eval { + '' =~ /$regexp/; + }; + + # Something went wrong + return 0 if ($@); + + return 1; +} + ################################################################################ # Recursively delete files and directories. ################################################################################ @@ -405,7 +422,11 @@ sub parse_conf_modules($) { push (@{$module->{'precondition'}}, {'operator' => '()', 'value_1' => $1, 'value_2' => $2, 'command' => $3}); # Regular expression } elsif ($action =~ /^\s*=~\s+(\S*)\s+(.*)$/) { - push (@{$module->{'precondition'}}, {'operator' => '=~', 'value_1' => $1, 'command' => $2}); + if (valid_regexp ($1)) { + push (@{$module->{'precondition'}}, {'operator' => '=~', 'value_1' => $1, 'command' => $2}); + } else { + log_message ('setup', "Invalid regular expression in module precondition: $line"); + } } } elsif ($line =~ /^\s*module_exec\s+(.+)$/) { $module->{'func'} = \&module_exec; @@ -462,7 +483,11 @@ sub parse_conf_modules($) { push (@{$module->{'conditions'}}, {'operator' => '()', 'value_1' => $1, 'value_2' => $2, 'command' => $3}); # Regular expression } elsif ($action =~ /^\s*=~\s+(\S*)\s+(.*)$/) { - push (@{$module->{'conditions'}}, {'operator' => '=~', 'value_1' => $1, 'command' => $2}); + if (valid_regexp ($1)) { + push (@{$module->{'conditions'}}, {'operator' => '=~', 'value_1' => $1, 'command' => $2}); + } else { + log_message ('setup', "Invalid regular expression in module condition: $line"); + } } } elsif ($line =~ /^\s*module_intensive_condition\s+(.*)$/) { my $action = $1; @@ -477,7 +502,11 @@ sub parse_conf_modules($) { push (@{$module->{'intensive_conditions'}}, {'operator' => '()', 'value_1' => $1, 'value_2' => $2}); # Regular expression } elsif ($action =~ /^\s*=~\s+(\S*)\s*$/) { - push (@{$module->{'intensive_conditions'}}, {'operator' => '=~', 'value_1' => $1}); + if (valid_regexp ($1)) { + push (@{$module->{'intensive_conditions'}}, {'operator' => '=~', 'value_1' => $1}); + } else { + log_message ('setup', "Invalid regular expression in intensive condition: $line"); + } } } elsif ($line =~ /^\s*module_crontab\s+(((\*|(\d+(-\d+){0,1}))\s*){5}).*$/) { $module->{'cron'} = $1;