logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Perl::Critic::Policy::Community::OpenArgs - Always use the three-argument form of open

Affiliation

       This policy is part of Perl::Critic::Community.

Author

       Dan Book, "dbook@cpan.org"

Configuration

       This policy is not configurable except for the standard options.

Description

       The open() function may be called in a two-argument form where the filename is parsed to determine the
       mode of opening, which may include piping input or output. (In the one-argument form, this filename is
       retrieved from a global variable, but the same magic is used.) This can lead to vulnerabilities if the
       filename is retrieved from user input or could begin or end with a special character. The three-argument
       form specifies the open mode as the second argument, so it is always distinct from the filename.

         open FILE;                   # not ok
         open my $fh, "<$filename";   # not ok
         open my $fh, '<', $filename; # ok

       This policy is similar to the core policy Perl::Critic::Policy::InputOutput::ProhibitTwoArgOpen, but
       additionally prohibits one-argument opens.

Name

       Perl::Critic::Policy::Community::OpenArgs - Always use the three-argument form of open

See Also

       Perl::Critic

perl v5.40.1                                       2025-03-22              Perl::Critic::...unity::OpenArgs(3pm)

See Also