]> git.proxmox.com Git - pve-apiclient.git/commitdiff
avoid harmful '<>' pattern, explicitly read from STDIN
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 22 Jan 2018 09:52:13 +0000 (10:52 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 22 Jan 2018 13:56:33 +0000 (14:56 +0100)
Fixes problems in CLIHandler using the code pattern:

while (my $line = <>) {
    ...
}

For why this causes only _now_ problems lets first look how <>
behaves:

"The null filehandle <> is special: [...] Input from <> comes either
from standard input, or from each file listed on the command line.
Here's how it works: the first time <> is evaluated, the @ARGV array
is checked, and if it is empty, $ARGV[0] is set to "-" , which when
opened gives you standard input.  The @ARGV array is then processed
as a list of filenames." - 'perldoc perlop'

Recent changes in the CLIHandler code changed how we modfiied @ARGV
Earlier we assumed that the first argument must be the command and
thus shifted it out of @ARGV, now we can have multiple levels of
(sub)commands. This change also changed how we handle @ARGV, we do
not unshift anything but go through the arguments until we got to
the final command and copy the rest of @ARGV as we know that this
must be the commandos arguments.

For '<>' this means that ARGV was still fully populated and perl
tried to open element as a file, which naturally failed.
Thus the change in pve-common only exposed this 'dangerous' code
pattern.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/APIClient/LWP.pm

index 20e3b56621dee188ed4cd129b2b96f31deb8ef5a..31df3c5929a4e9e9d9be4f6365d17d0c0f8b684b 100755 (executable)
@@ -146,7 +146,7 @@ sub manual_verify_fingerprint {
        "X509 SHA256 key fingerprint is $fingerprint.\n" .
        "Are you sure you want to continue connecting (yes/no)? ";
 
-    my $answer = <>;
+    my $answer = <STDIN>;
 
     my $valid = ($answer =~ m/^\s*yes\s*$/i) ? 1 : 0;