note
radiantmatrix
<p>I can tell you why I suggested that capacity in the [id://558656|referenced node]: very simply, it's way too easy to mess up (usually by a failure to anticipate a problem) when using the single-argument form.
<p>When using a single-argument form of [doc://system] or [doc://exec] (i.e. <code>system("$command $arg1 $arg2")</code>), it's up to the programmer to escape those arguments properly for the shell. Which they might choose to do non-portably. The multiple-argument forms (i.e. <code>exec($command, $arg1, $arg2, @other_args)</code>) , though, don't have that issue: the shell escaping/quoting is handled under the covers.
<p>Fewer bugs creep into code, and fewer portability problems arise, with the multiple-argument form. There's also very few instances where the muliple-argument form is any kind of hinderance. That's reason enough, IMO, to consider that form a best practice (even if it's a "low-severity" one when broken).
<p>If that's not enough, though, there are some minor security issues. Tainted data being passed as arguments will be quoted for the shell (they won't be in the single-arg form), so there isn't a "Shell Code Injection" possibility. Maybe that doesn't come up most of the time, but considering the number of CGI and GUI applications I've seen that interpolate tainted (or very poorly untainted) user data into [doc://system] calls, it's worth thinking about.
<p>Essentially, this is the same argument as using the 3-arg form of [doc://open], and using prototypes for SQL statements with [cpan://DBI]. There are times when it's perfectly safe to use 2-arg open and to interpolate variables in SQL statements (esp. with proper untainting). But, 3-arg open and prototypes are best practices because it's just as easy to do it the preferred way, and it helps prevent common mistakes and problems. Same thing here.
<p>I'll be the first to stand up and say that this isn't something [cpan://Perl::Critic] should gripe about by default, but it would be <em>really nice</em> to have it complain at lower severity levels.
<!--
<p><small><b>Updates:</b><ul type='square'>
<li>date : desc</li>
</ul></small></p>
-->
<div class="pmsig"><div class="pmsig-375088">
<small>
<small><font color='#000000'><</font><font color='#1a1a1a'>–</font><font color='#343434'>r</font><font color='#4e4e4e'>a</font><font color='#686868'>d</font><font color='#828282'>i</font><font color='#9c9c9c'>a</font><font color='#b6b6b6'>n</font><font color='#d0d0d0'>t</font><font color='#eaeaea'>.</font><font color='#d0d0d0'>m</font><font color='#b6b6b6'>a</font><font color='#9c9c9c'>t</font><font color='#828282'>r</font><font color='#686868'>i</font><font color='#4e4e4e'>x</font><font color='#343434'>–</font><font color='#1a1a1a'>></font></small>
<!--<-</small><b>radiant</b>.<b>matrix</b><small>-></small-->
<br><a href='http://radiantmatrix.org/'>A collection of thoughts and links from the minds of geeks</a>
<br><em>The Code that can be seen is not the true Code</em>
<br><em>I haven't found a problem yet that can't be solved by a well-placed [http://en.wikipedia.org/wiki/Trebuchet|trebuchet]</em>
</small>
</div></div>
558707
558711