perl: harden external command invocations

In `adddocsref.pl`, `checksrc-all.pl`, `singleuse.pl` and tests 307, 1013,
1022, 1275, 1707, 1708, 1710.

Closes #21097
This commit is contained in:
Viktor Szakats 2026-03-22 02:42:17 +01:00
parent a56ab9dbc8
commit 20914e3753
No known key found for this signature in database
11 changed files with 24 additions and 23 deletions

View file

@ -13,7 +13,7 @@ use Cwd 'abs_path';
my @files;
my $is_git = 0;
if(system('git rev-parse --is-inside-work-tree >/dev/null 2>&1') == 0) {
@files = `git ls-files \"*.[ch]\"`;
open(O, '-|', 'git', 'ls-files', '*.[ch]') || die; push @files, <O>; close(O);
$is_git = 1;
}
else {
@ -33,7 +33,8 @@ my $anyfailed = 0;
for my $dir (@dirs) {
if($is_git) {
@files = `git ls-files \"$dir/*.[ch]\"`;
@files = ();
open(O, '-|', 'git', 'ls-files', "$dir/*.[ch]") || die; push @files, <O>; close(O);
chomp(@files);
}
else {

View file

@ -36,9 +36,9 @@
use strict;
use warnings;
my $unittests="";
my @unittests;
if(@ARGV && $ARGV[0] eq "--unit") {
$unittests = "tests/unit ";
push @unittests, 'tests/unit';
shift @ARGV;
}
@ -167,7 +167,7 @@ my %api = (
sub doublecheck {
my ($f, $used) = @_;
open(F, "git grep -Fwle '$f' -- lib ${unittests}projects|");
open(F, '-|', 'git', 'grep', '-Fwle', $f, '--', 'lib', @unittests, 'projects');
my @also;
while(<F>) {
my $e = $_;
@ -182,8 +182,7 @@ sub doublecheck {
return @also;
}
open(N, "nm $file|") ||
die;
open(N, '-|', 'nm', $file) || die;
my %exist;
my %uses;