From 29fa220a36012b94923e8bc0d9b048688aab9f27 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Thu, 18 Sep 2025 11:23:26 +0200 Subject: [PATCH] Fix util/find-doc-nits' environment variable check exceptions 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 Reviewed-by: Dmitry Belyavskiy (Merged from https://github.com/openssl/openssl/pull/28601) --- util/find-doc-nits | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/util/find-doc-nits b/util/find-doc-nits index 6b541c27411..06bcb198621 100755 --- a/util/find-doc-nits +++ b/util/find-doc-nits @@ -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>) { -- 2.47.3