]> git.proxmox.com Git - pmg-api.git/commitdiff
tree-wide: make slurp mode as local as possible for future-proofing
authorFiona Ebner <f.ebner@proxmox.com>
Mon, 10 Jul 2023 11:36:47 +0000 (13:36 +0200)
committerStoiko Ivanov <s.ivanov@proxmox.com>
Mon, 10 Jul 2023 15:29:05 +0000 (17:29 +0200)
similar to what PMG/TFAConfig.pm already does.

Otherwise, sub-routine calls would still be affected leading to
unexpected results, like the issue fixed by commit "cluster config:
restrict slurp scope to avoid issue parsing network interfaces".

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
src/PMG/API2/ACMEPlugin.pm
src/PMG/Config.pm
src/PMG/LDAPConfig.pm
src/PMG/NodeConfig.pm
src/PMG/PBSConfig.pm
src/PMG/Ticket.pm

index e2004bf20321b4aa31abf7656c6ff1662de2e4f8..25d3a04921cb4ecd3c1467de235fed89abb23db7 100644 (file)
@@ -30,8 +30,7 @@ PVE::JSONSchema::register_standard_option('pmg-acme-pluginid', {
 
 sub read_pmg_acme_challenge_config {
     my ($filename, $fh) = @_;
-    local $/ = undef; # slurp mode
-    my $raw = defined($fh) ? <$fh> : '';
+    my $raw = defined($fh) ? do { local $/ = undef; <$fh> } : '';
     return PVE::ACME::Challenge->parse_config($filename, $raw);
 }
 
index fe89e1189e833dccb334680798c3851b831b1e2a..7339e0d2c713f26318b3afbfa9e21a87c1136703 100644 (file)
@@ -939,10 +939,8 @@ sub get_config {
 sub read_pmg_conf {
     my ($filename, $fh) = @_;
 
-    local $/ = undef; # slurp mode
-
     my $raw;
-    $raw = <$fh> if defined($fh);
+    $raw = do { local $/ = undef; <$fh> } if defined($fh);
 
     return  PMG::Config::Base->parse_config($filename, $raw);
 }
index a6cd6ef0fd7f1cc2c22b5b3440bbaba24c92aed9..e5b3388c63297c083bbd63f74489c4b82628208f 100644 (file)
@@ -221,9 +221,7 @@ __PACKAGE__->init();
 sub read_pmg_ldap_conf {
     my ($filename, $fh) = @_;
 
-    local $/ = undef; # slurp mode
-
-    my $raw = defined($fh) ? <$fh> : '';
+    my $raw = defined($fh) ? do { local $/ = undef; <$fh> } : '';
 
     return __PACKAGE__->parse_config($filename, $raw);
 }
index 42139e4c3bfbf4c689b69b577ca4d7d5d70345b6..6303979705b9cc128019001b206306195d056cc4 100644 (file)
@@ -120,8 +120,7 @@ sub print_domain : prototype($) {
 
 sub read_pmg_node_config {
     my ($filename, $fh) = @_;
-    local $/ = undef; # slurp mode
-    my $raw = defined($fh) ? <$fh> : '';
+    my $raw = defined($fh) ? do { local $/ = undef; <$fh> } : '';
     my $digest = Digest::SHA::sha1_hex($raw);
     my $conf = PVE::JSONSchema::parse_config($config_schema, $filename, $raw);
     $conf->{digest} = $digest;
index 34171234c76f804d4a4e69c6bf158238f2eff8b1..ee506f1feda743a35aca0683d4bc4a622ed982d6 100644 (file)
@@ -194,9 +194,7 @@ __PACKAGE__->init();
 sub read_pmg_pbs_conf {
     my ($filename, $fh) = @_;
 
-    local $/ = undef; # slurp mode
-
-    my $raw = defined($fh) ? <$fh> : '';
+    my $raw = defined($fh) ? do { local $/ = undef; <$fh> } : '';
 
     return __PACKAGE__->parse_config($filename, $raw);
 }
index 0c2ec0b8580f8d5d1306bede85fc16797bc53250..fc2ac777b6bffbe330a57308c088355499bc71c7 100644 (file)
@@ -106,9 +106,7 @@ sub generate_auth_key {
 my $read_rsa_priv_key = sub {
    my ($filename, $fh) = @_;
 
-   local $/ = undef; # slurp mode
-
-   my $input = <$fh>;
+   my $input = do { local $/ = undef; <$fh> };
 
    return Crypt::OpenSSL::RSA->new_private_key($input);
 
@@ -121,9 +119,7 @@ PVE::INotify::register_file('auth_priv_key', $authprivkeyfn,
 my $read_rsa_pub_key = sub {
    my ($filename, $fh) = @_;
 
-   local $/ = undef; # slurp mode
-
-   my $input = <$fh>;
+   my $input = do { local $/ = undef; <$fh> };
 
    return Crypt::OpenSSL::RSA->new_public_key($input);
 };
@@ -135,9 +131,7 @@ PVE::INotify::register_file('auth_pub_key', $authpubkeyfn,
 my $read_csrf_secret = sub {
    my ($filename, $fh) = @_;
 
-   local $/ = undef; # slurp mode
-
-   my $input = <$fh>;
+   my $input = do { local $/ = undef; <$fh> };
 
    return Digest::SHA::hmac_sha256_base64($input);
 };