From f01197df71bcd69802db7fdb8c50f2d2ae0f8b0f Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Sun, 17 Sep 2023 13:42:30 +0300 Subject: [PATCH 1/2] Add die handler that stores the error from eval message --- web-lib.pl | 7 +++++++ webmin/twofactor-funcs-lib.pl | 6 ++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/web-lib.pl b/web-lib.pl index 3171f7c28..555353968 100755 --- a/web-lib.pl +++ b/web-lib.pl @@ -34,5 +34,12 @@ if (!$done_web_lib_funcs) { $remote_error_handler ||= \&error; $main::remote_error_handler ||= \&error; +# Die handler that stores the error from +# eval message in a global variable +$SIG{__DIE__} = sub { + # Don't meddle with the natural functioning of eval. + $main::error_last_eval = $_[0] if (!$^S); +}; + 1; diff --git a/webmin/twofactor-funcs-lib.pl b/webmin/twofactor-funcs-lib.pl index 923464f64..58399b6a8 100644 --- a/webmin/twofactor-funcs-lib.pl +++ b/webmin/twofactor-funcs-lib.pl @@ -162,8 +162,7 @@ sub validate_twofactor_apikey_totp { my ($miniserv, $in) = @_; eval "use Authen::OATH"; -$main::error_last_eval = $@; -if ($main::error_last_eval) { +if ($@) { return &text('twofactor_etotpmodule', 'Authen::OATH', "../cpan/download.cgi?source=3&cpan=Authen::OATH&mode=2&". "return=/$module_name/&returndesc=".&urlize($text{'index_return'})); @@ -249,8 +248,7 @@ $id =~ /^[A-Z0-9=]+$/i || return $text{'twofactor_etotpid'}; $token =~ /^\d+$/ || return $text{'twofactor_etotptoken'}; eval "use lib (\"$root_directory/vendor_perl\")"; eval "use Authen::OATH"; -$main::error_last_eval = $@; -if ($main::error_last_eval) { +if ($@) { return &text('twofactor_etotpmodule2', 'Authen::OATH'); } my $secret = &decode_base32($id); From 43334357391a7f07481f4ce5a06daf3fc24c6138 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Sun, 17 Sep 2023 13:44:03 +0300 Subject: [PATCH 2/2] Fix indent --- web-lib.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web-lib.pl b/web-lib.pl index 555353968..5a8db9a67 100755 --- a/web-lib.pl +++ b/web-lib.pl @@ -38,7 +38,7 @@ $main::remote_error_handler ||= \&error; # eval message in a global variable $SIG{__DIE__} = sub { # Don't meddle with the natural functioning of eval. - $main::error_last_eval = $_[0] if (!$^S); + $main::error_last_eval = $_[0] if (!$^S); }; 1;