]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
spacecheck: verify filename lengths and characters
authorViktor Szakats <commit@vsz.me>
Wed, 25 Mar 2026 12:19:09 +0000 (13:19 +0100)
committerViktor Szakats <commit@vsz.me>
Wed, 25 Mar 2026 17:56:40 +0000 (18:56 +0100)
Maximum filename length 64, of which 48 maximum for the filename part.
Allowed characters: `A-Za-z0-9/._-`.

Also:
- rename a file to pass the check.
- init max constants outside the loop.
- minor fix to an error message.
  Follow-up to 62d77b12fce55d3481bb0b2e70e0f921c8cbfe5e #21087

Closes #21095

docs/Makefile.am
docs/internals/THRDPOOL-AND-QUEUE.md [moved from docs/internals/THRDPOOL+QUEUE.md with 100% similarity]
scripts/spacecheck.pl

index 750d65481e0fe8e6ff0e4d493f26a482de96238e..c207a21246e560adad3a7654db3bfb86cc211793 100644 (file)
@@ -68,7 +68,7 @@ INTERNALDOCS =                                   \
   internals/SCORECARD.md                         \
   internals/SPLAY.md                             \
   internals/STRPARSE.md                          \
-  internals/THRDPOOL+QUEUE.md                    \
+  internals/THRDPOOL-AND-QUEUE.md                \
   internals/TIME-KEEPING.md                      \
   internals/TLS-SESSIONS.md                      \
   internals/UINT_SETS.md                         \
index 646487aed589f639fb4ca53daea489d22894c904..f1eb4a8992be8325bc63f19520a9dfd42f7555f7 100755 (executable)
@@ -26,6 +26,8 @@
 use strict;
 use warnings;
 
+use File::Basename;
+
 my @tabs = (
     '^m4/zz40-xc-ovr\.m4$',
     'Makefile\.(am|example)$',
@@ -104,18 +106,36 @@ sub eol_detect {
     return '';
 }
 
+my $max_repeat_space = 79;
+my $max_line_len = 192;
+my $max_path_len = 64;
+my $max_filename_len = 48;
+
 my $issues = 0;
 
 open(my $git_ls_files, '-|', 'git', 'ls-files') or die "Failed running git ls-files: $!";
 while(my $filename = <$git_ls_files>) {
     chomp $filename;
 
+    my @err = ();
+
+    if(length($filename) > $max_path_len) {
+        push @err, sprintf('long (%d > %d) path', length($filename), $max_path_len);
+    }
+
+    my $bn = basename($filename);
+    if(length($bn) > $max_filename_len) {
+        push @err, sprintf('long (%d > %d) filename', length($bn), $max_filename_len);
+    }
+
+    if($filename !~ /^[A-Za-z0-9\/._-]+$/) {
+        push @err, sprintf("filename contains character(s) outside [A-Za-z0-9/._-]");
+    }
+
     open(my $fh, '<', $filename) or die "Cannot open '$filename': $!";
     my $content = do { local $/; <$fh> };
     close $fh;
 
-    my @err = ();
-
     if(!fn_match($filename, @tabs) &&
        $content =~ /\t/) {
         push @err, 'content: has tab';
@@ -181,21 +201,19 @@ while(my $filename = <$git_ls_files>) {
 
     if(!fn_match($filename, @longline)) {
         my $line = 0;
-        my $max = 192;
         for my $l (split(/\n/, $content)) {
             $line++;
-            if(length($l) > $max) {
-                push @err, sprintf('line %d: long (%d > %d) line', $line, length($l), $max);
+            if(length($l) > $max_line_len) {
+                push @err, sprintf('line %d: long (%d > %d) line', $line, length($l), $max_line_len);
             }
         }
     }
 
     my $line = 0;
-    my $max = 79;
     for my $l (split(/\n/, $content)) {
         $line++;
-        if($l =~ /( {$max,})/) {
-            push @err, sprintf('line %d: repeat spaces (%d > %d)', $line, length($1), $max);
+        if($l =~ /( {$max_repeat_space,})/) {
+            push @err, sprintf('line %d: repeat spaces (%d >= %d)', $line, length($1), $max_repeat_space);
         }
     }