Merge parse_directory_line into interpret_directive
authorJacob Bachmeyer <jcb@gnu.org>
Thu, 27 Oct 2022 04:07:08 +0000 (23:07 -0500)
committerJacob Bachmeyer <jcb@gnu.org>
Thu, 27 Oct 2022 04:07:08 +0000 (23:07 -0500)
The old code is still extant because it is also used elsewhere, but will
be cleaned up in future commits.

gatekeeper.pl

index 7d840d8328598e3070ca7980de73b8c4e1d78326..6a1af5546ba9421194d1b8a1e4d6d220b5768698 100755 (executable)
@@ -1682,9 +1682,43 @@ sub interpret_directive {
     my $tainted_val = $item->[1];
 
     if ($tainted_cmd eq 'directory') {
-      parse_directory_line($tainted_val, $directive_file_contents,0);
-      $header{directory} = $info{directory};
-      $header{package} = $info{package};
+      unless ($tainted_val =~ m/^($RE_filename_relative)$/) {
+       push @errors, "invalid directory $tainted_val";
+       next;
+      }
+      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.
+      if ($dir_depth > MAX_DIRECTORY_DEPTH) {
+       push @errors, "$dir_depth levels is too deep, in $val";
+       next;
+      }
+
+      # Only let them specify one directory directive.
+      if (defined $header{directory}) {
+       push @errors,
+         "Only one directory directive is allowed per directive file. "
+           ."Error at directory directive: $val";
+       next;
+      }
+
+      $header{directory} = $val;       # ok.
+      $header{package} = $dirs[0];     # top-level name, no subdir
+      $info{directory} = $header{directory};
+      $info{package} = $header{package};
+
+      # TODO: move this part elsewhere:
+      # Set email addresses
+      my @a = email_addresses($info{package});
+      foreach my $address (@a) {
+       # Do not include duplicates
+       push (@{$info{email}}, $address)
+         unless (grep($_ eq $address,@{$info{email}}) > 0);
+      }
+
     } elsif ($tainted_cmd eq 'filename') {
       # We use the same filename restrictions as scan_incoming
       unless ($tainted_val =~ /^($RE_filename_here)$/) {