[Libguestfs] [PATCH] Add a test for an executable stack in libguestfs.so

Jim Meyering jim at meyering.net
Wed Aug 5 12:16:02 UTC 2009


Matthew Booth wrote:
> ---
>  regressions/Makefile.am          |    4 ++-
...
> diff --git a/regressions/test-noexec-stack.pl b/regressions/test-noexec-stack.pl
...
> +FILES: foreach my $file (@files) {
> +    my $output;
> +    open($output, '-|', "readelf -l $file")
> +        or die("\"readelf -l $file\" failed");

Hi Matt,

A general tip:
There's a bit of a risk in opening a pipe like that.
Imagine that $file contains certain shell meta-characters (like "; rm -rf /").

Use an array, and you avoid that, as well as the duplication in the "die":

     my @cmd = ('readelf', '-l', $file);
     open($output, '-|', @cmd)
         or die "$0: failed to run: \`" . join(' ', at cmd) . "': $!\n";

Also, imho, every diagnostic should start with "$program_name: ".
That makes it easier to know which program produced a particular
string, when wading through thousands of lines of output from
hundreds of different tools.




More information about the Libguestfs mailing list