Skip to content

Commit 8ba2c7c

Browse files
committed
Try to not load a module more than once
1 parent a2f722f commit 8ba2c7c

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

cgi-bin/page.fcgi

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ sub doit
328328

329329
# Check if this is a CAPTCHA verification attempt
330330
if ($info->param('g-recaptcha-response')) {
331-
require 'VWF::CAPTCHA';
332-
VWF::CAPTCHA->new();
331+
require 'VWF::CAPTCHA' && VWF::CAPTCHA->import() unless VWF::CAPTCHA->can('new');
333332

334333
my $recaptcha_config = $config->recaptcha();
335334
if ($recaptcha_config && $recaptcha_config->{enabled}) {
@@ -390,7 +389,7 @@ sub doit
390389
$logger->warn("Hard rate limit exceeded for $client_ip ($request_count requests)");
391390
$info->status(429);
392391

393-
eval 'require VWF::Display::captcha';
392+
require 'VWF::Display::captcha' && VWF::Display::captcha->import() unless VWF::Display::captcha->can('new');
394393
my $display = VWF::Display::captcha->new({
395394
cachedir => $cachedir,
396395
info => $info,
@@ -539,7 +538,7 @@ sub doit
539538

540539
# TODO: consider creating a whitelist of valid modules
541540
$logger->debug("doit(): Loading module $display_module from @INC");
542-
eval "require $display_module";
541+
eval "require $display_module; 1" && $display_module->import() unless $display_module->can('new');
543542
if($@) {
544543
$logger->debug("Failed to load module $display_module: $@");
545544
$logger->info("Unknown page $page");
@@ -548,7 +547,6 @@ sub doit
548547
$info->status(404);
549548
}
550549
} else {
551-
$display_module->import();
552550
# use Class::Inspector;
553551
# my $methods = Class::Inspector->methods($display_module);
554552
# print "$display_module exports ", join(', ', @{$methods}), "\n";
@@ -775,9 +773,8 @@ sub vwflog
775773
}
776774

777775
if($syslog) {
778-
require Sys::Syslog;
776+
require 'Sys::Syslog' && Sys::Syslog->import() unless Sys::Syslog->can('openlog');
779777

780-
Sys::Syslog->import();
781778
if(ref($syslog) eq 'HASH') {
782779
Sys::Syslog::setlogsock($syslog);
783780
}

0 commit comments

Comments
 (0)