From e77d30fe2031d9fd0d483c7218b268d3f7a059c5 Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Sat, 15 Oct 2022 20:07:24 -0500 Subject: [PATCH] Use File::Spec::Unix to count directories in parse_directory_line --- gatekeeper.pl | 8 +++++--- testsuite/lib/gatekeeper.exp | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/gatekeeper.pl b/gatekeeper.pl index 837dfe0..5e2d2e0 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -1110,10 +1110,12 @@ sub parse_directory_line { 1,$directive_file_contents); my $val = $1; # so far so good + my @dirs = File::Spec::Unix->splitdir($1); + my $dir_depth = scalar @dirs; + # A couple of subdir levels are ok, but don't allow hundreds. - my $slash_count = ($val =~ tr,/,/,); - fatal("$slash_count slashes is too many, in $val",1,$directive_file_contents) - if ($slash_count > (MAX_DIRECTORY_DEPTH-1) and not $do_not_fail); + fatal("$dir_depth levels is too deep, in $val",1,$directive_file_contents) + if ($dir_depth > MAX_DIRECTORY_DEPTH and not $do_not_fail); # Only let them specify one directory directive. fatal("Only one directory directive is allowed per directive file. " diff --git a/testsuite/lib/gatekeeper.exp b/testsuite/lib/gatekeeper.exp index e84d263..236b1e4 100644 --- a/testsuite/lib/gatekeeper.exp +++ b/testsuite/lib/gatekeeper.exp @@ -627,7 +627,7 @@ proc analyze_log { base_dir name assess } { exp_continue } -re {^gatekeeper\[[0-9]+\]: \(Test\)\ - ([0-9]+) slashes is too many, in [^\r\n]+} { + ([0-9]+) levels is too deep, in [^\r\n]+} { # from parse_directory_line, when the directory is too deep set A(validate,bad-directory-depth) 1 set A(validate,bad-directory-depth,$expect_out(1,string)) 1 -- 2.25.1