From 193e305fa5d33424df5b8d55a32e44f7c9b7c337 Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Wed, 29 Jan 2020 16:54:02 +0100 Subject: [PATCH] TT#75114 prevent exit() invocations Change-Id: If6c1049b842b44706c076e9e39ee7d42de4a43b5 --- lib/NGCP/Panel/Utils/ProvisioningTemplates.pm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/NGCP/Panel/Utils/ProvisioningTemplates.pm b/lib/NGCP/Panel/Utils/ProvisioningTemplates.pm index 2f6b838ec8..de3412af89 100644 --- a/lib/NGCP/Panel/Utils/ProvisioningTemplates.pm +++ b/lib/NGCP/Panel/Utils/ProvisioningTemplates.pm @@ -28,6 +28,19 @@ use NGCP::Panel::Utils::Subscriber qw(); use NGCP::Panel::Utils::Preferences qw(); use NGCP::Panel::Utils::Kamailio qw(); +#The function _calculate() evaluates perl code provided via a configuration +#by the user, so we must make sure no such code will call exit() by +#accident or we would terminate the entire program. +our $DISABLE_EXIT = 0; +BEGIN { + *CORE::GLOBAL::exit = sub (;$) { + ## no critic (TestingAndDebugging::ProhibitNoWarnings) + no warnings 'exiting'; + die('exit() called') if $DISABLE_EXIT; + CORE::exit($_[0] // 0); + }; +} + my $IDENTIFIER_FNAME = 'identifier'; my $CODE_SUFFIX_FNAME = '_code'; my $FIELD_TYPE_ATTRIBUTE = 'type'; @@ -997,6 +1010,7 @@ sub _calculate { $context->{cr_c} //= {}; if ($f =~ /^([a-z0-9_]+)$CODE_SUFFIX_FNAME$/) { my $cl; + local $DISABLE_EXIT = 1; if ($strict_closure) { $cl = eval_closure( source => $c,