![]() |
|
Syntactic Confectionery Delight | |
PerlMonks |
Proper and acceptable use of backticks in a modern Perl scriptby Polyglot (Chaplain) |
on Sep 18, 2023 at 10:23 UTC ( #11154513=perlquestion: print w/replies, xml ) | Need Help?? |
Polyglot has asked for the wisdom of the Perl Monks concerning the following question:
I'm not even invoking taint in the script--but it seems that taint is active (is this because of the Perl version? more on that below), and crashes the program for one simple line:
my @fonts = `/usr/bin/fc-list : family`; My perl version is:
The error that appears in my logs is: "Insecure $ENV{PATH} while running with -T switch . . .," despite the fact that my shebang line has only #!/usr/bin/perl and, while narrowing the problem down, I have disabled all module uses except one: use CGI qw(-utf8);. As is clear to be seen, there are no variables, nor any executable code, inside the backticks--so there should be no legitimate security issue worthy of shutting down the execution of the script. They invoke a standard command which is useful for displaying the fonts available and installed on the server. Should those fonts change, such as if more were to be installed, the next run of the script would automatically show this--which is what I want. But even if I put ls inside those backticks, the whole script will fail, and I get "Internal Server Error" as the message in my browser. Other options than using backticks seem cludgy at best, and problematic at worst. I could run a cronjob that writes the output of this command to a file, then the perl script reads from that file. To be up-to-date, this cronjob would have to run often, consuming server resources--not to mention the added unnecessary file to be stored in the system. I could use a system call (assuming taint would allow this--I haven't tried it yet) that would do what the cronjob does, then, after opening and reading the file, I could unlink it. This requires multiple steps, much more code, involves file permissions which create potential failure points, and just seems quite rather unperlish. I fell in love with perl years ago when it gave me the ability to do what I wanted in easy and intuitive ways. This taintedness is rubbing against the grain. Why is taint even forced on the script without my having invoked it? In actual fact, I would like the script to run with taint, but I need to be able to run this command, too. Is this as impossible as wanting to have my cake and eat it too? Blessings, ~Polyglot~
Back to
Seekers of Perl Wisdom
|
|