public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-api 2/2] tree-wide: make slurp mode as local as possible for future-proofing
Date: Mon, 10 Jul 2023 13:36:47 +0200	[thread overview]
Message-ID: <20230710113647.53879-2-f.ebner@proxmox.com> (raw)
In-Reply-To: <20230710113647.53879-1-f.ebner@proxmox.com>

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 |  3 +--
 src/PMG/Config.pm          |  4 +---
 src/PMG/LDAPConfig.pm      |  4 +---
 src/PMG/NodeConfig.pm      |  3 +--
 src/PMG/PBSConfig.pm       |  4 +---
 src/PMG/Ticket.pm          | 12 +++---------
 6 files changed, 8 insertions(+), 22 deletions(-)

diff --git a/src/PMG/API2/ACMEPlugin.pm b/src/PMG/API2/ACMEPlugin.pm
index e2004bf..25d3a04 100644
--- a/src/PMG/API2/ACMEPlugin.pm
+++ b/src/PMG/API2/ACMEPlugin.pm
@@ -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);
 }
 
diff --git a/src/PMG/Config.pm b/src/PMG/Config.pm
index fe89e11..7339e0d 100644
--- a/src/PMG/Config.pm
+++ b/src/PMG/Config.pm
@@ -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);
 }
diff --git a/src/PMG/LDAPConfig.pm b/src/PMG/LDAPConfig.pm
index a6cd6ef..e5b3388 100644
--- a/src/PMG/LDAPConfig.pm
+++ b/src/PMG/LDAPConfig.pm
@@ -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);
 }
diff --git a/src/PMG/NodeConfig.pm b/src/PMG/NodeConfig.pm
index 42139e4..6303979 100644
--- a/src/PMG/NodeConfig.pm
+++ b/src/PMG/NodeConfig.pm
@@ -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;
diff --git a/src/PMG/PBSConfig.pm b/src/PMG/PBSConfig.pm
index 3417123..ee506f1 100644
--- a/src/PMG/PBSConfig.pm
+++ b/src/PMG/PBSConfig.pm
@@ -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);
 }
diff --git a/src/PMG/Ticket.pm b/src/PMG/Ticket.pm
index 0c2ec0b..fc2ac77 100644
--- a/src/PMG/Ticket.pm
+++ b/src/PMG/Ticket.pm
@@ -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);
 };
-- 
2.39.2





  reply	other threads:[~2023-07-10 11:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-10 11:36 [pmg-devel] [PATCH pmg-api 1/2] cluster config: restrict slurp scope to avoid issue parsing network interfaces Fiona Ebner
2023-07-10 11:36 ` Fiona Ebner [this message]
2023-07-11  8:33 ` [pmg-devel] applied-series: " Stoiko Ivanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230710113647.53879-2-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal