Enforce MAX_FILE_NAME_LEN on implied directory names
authorJacob Bachmeyer <jcb@gnu.org>
Tue, 28 Mar 2023 02:06:30 +0000 (21:06 -0500)
committerJacob Bachmeyer <jcb@gnu.org>
Tue, 28 Mar 2023 02:06:30 +0000 (21:06 -0500)
A test is added to verify this check.

gatekeeper.pl
testsuite/gatekeeper.all/01_loose.exp
testsuite/lib/gatekeeper.exp

index 839de84b11e30e7957f143b04cdb457b36035bfa..8c80b00b56f50229849ceb6c5788b82f36b47d19 100755 (executable)
@@ -1807,6 +1807,13 @@ sub interpret_directive {
        next;
       }
 
+      # Do not allow directories to be implied with overlength names.
+      if (grep length > MAX_FILE_NAME_LEN, @dirs) {
+       push @errors, "directory name too long, in $val";
+       push @trace, ['  ^--', 'a component of this name is too long'];
+       next;
+      }
+
       # Only let them specify one directory directive.
       if (defined $header{directory}) {
        push @errors,
index d6d54c5c0d44ec6f5cd187c60b558a98e768c30e..61ef41b3950a3d89f74a9cff4f6133220407e085 100644 (file)
@@ -1,6 +1,6 @@
 # Tests for processing standalone directives
 
-# Copyright (C) 2021, 2022 Jacob Bachmeyer
+# Copyright (C) 2021, 2022, 2023 Jacob Bachmeyer
 #
 # This file is part of a testsuite for the GNU FTP upload system.
 #
@@ -243,6 +243,21 @@ check_loose_directive "bogus: signed with wrong key and too deep" {
     ftp-upload-script@gnu.org ftp-upload-report@gnu.org
 }
 
+check_loose_directive "bogus: signed with wrong key and too long" [list \
+    directive [subst {
+       version 1.2
+       directory foo/[string repeat long 100]/bar
+       no-op ""
+       comment "do nothing"
+    }] dsig { good 01 1001 }] file-tree {
+    { inbox stage pub archive } empty {}
+    { scratch } files { .foo.directive.asc }
+} log {
+    validate,bad-directory-length "excessively long directory name rejected"
+} email-to {
+    ftp-upload-script@gnu.org ftp-upload-report@gnu.org
+}
+
 check_loose_directive "bogus: signed for bogus package" {
     directive {
        version 1.2
index 66461ff059fc1421e8eca692410e7674ce58b493..24332202e7e4d9849305777693c374ef51cf7f9a 100644 (file)
@@ -1,6 +1,6 @@
 # DejaGnu tool init file for GNU FTP upload handler tests
 
-# Copyright (C) 2021, 2022 Jacob Bachmeyer
+# Copyright (C) 2021, 2022, 2023 Jacob Bachmeyer
 #
 # This file is part of a testsuite for the GNU FTP upload system.
 #
@@ -599,6 +599,12 @@ proc analyze_log { base_dir name assess } {
                     set A(validate,bad-directory-depth,$expect_out(1,string)) 1
                     exp_continue
                 }
+       -re {^gatekeeper\[[0-9]+\]: \(Test\) \[PS\]\
+                directory name too long, in [^\r\n]+} {
+                    # from interpret_directive, when a name is too long
+                    set A(validate,bad-directory-length) 1
+                    exp_continue
+                }
        -re {^gatekeeper\[[0-9]+\]: \(Test\) \[PS\]\
                 Only one directory directive is allowed per [^\r\n]+} {
                     # from parse_directory_line, if directory repeated