]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix util/find-doc-nits' environment variable check exceptions
authorRichard Levitte <levitte@openssl.org>
Thu, 18 Sep 2025 09:23:26 +0000 (11:23 +0200)
committerNeil Horman <nhorman@openssl.org>
Thu, 30 Oct 2025 12:12:06 +0000 (08:12 -0400)
Some files in @except_env_files are located in the build directory,
not the source directory.

Furthermore, because the files and directories in @except_dirs and
@except_env_files may look different than the elements in what find()
returns, realpath() must be used to ensure that file name comparison
matches when it should.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/28601)

util/find-doc-nits

index 6b541c2741171afcf465dd17b435248a2b895b62..06bcb1986219c24d1d54fa5b3121431fb4a86a97 100755 (executable)
@@ -13,6 +13,7 @@ use strict;
 
 use Carp qw(:DEFAULT cluck);
 use Pod::Checker;
+use Cwd qw(realpath);
 use File::Find;
 use File::Basename;
 use File::Spec::Functions;
@@ -1286,9 +1287,11 @@ sub check_env_vars {
         "$config{sourcedir}/test",
     );
     my @except_env_files = (
-        "$config{sourcedir}/providers/implementations/keymgmt/template_kmgmt.c",
         "$config{sourcedir}/providers/implementations/kem/template_kem.c",
-        "$config{sourcedir}/Makefile.in",
+        # The following files are generated, and are therefore found in the
+        # build directory rather than the source directory
+        "$config{builddir}/providers/implementations/keymgmt/template_kmgmt.c",
+        "$config{builddir}/Makefile.in",
     );
     my @env_headers;
     my @env_macro;
@@ -1323,13 +1326,23 @@ sub check_env_vars {
         }
     }
 
+    # Because we compare against them, make sure that all elements in
+    # @except_dirs and @except_env_files are real paths.  Otherwise,
+    # we may get false positives because relative paths to the same
+    # file could look different.
+    # For example, './foo.c' == '../dir/foo.c', but turning them into
+    # real paths will have them actually look the same.
+    @except_dirs = map { realpath($_) } @except_dirs;
+    @except_env_files = map { realpath($_) } @except_env_files;
+
     # look for source files
     find(sub { push @env_files, $File::Find::name if /\.c$|\.in$/; },
          $config{sourcedir});
 
     foreach my $filename (@env_files) {
-        next if (grep { $filename =~ /^$_\// } @except_dirs)
-                || grep { $_ eq $filename } @except_env_files;
+        my $realfilename = realpath($filename);
+        next if (grep { $realfilename =~ /^$_\// } @except_dirs)
+                || grep { $_ eq $realfilename } @except_env_files;
 
         open my $fh, '<', $filename or die "Can't open $filename: $!";
         while (my $line = <$fh>) {