]> ruderich.org/simon Gitweb - blhc/blhc.git/commitdiff
Strip (basic) environment variables before compiler detection
authorSimon Ruderich <simon@ruderich.org>
Sat, 9 Oct 2021 09:17:59 +0000 (11:17 +0200)
committerSimon Ruderich <simon@ruderich.org>
Sat, 9 Oct 2021 09:17:59 +0000 (11:17 +0200)
NEWS
bin/blhc
t/logs/env
t/tests.t

diff --git a/NEWS b/NEWS
index 2ff705516db37336b309efe4a4a0863b946b7c91..1d87d134262c358eda3e58d49a4ce3d9f42c7418 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@ Version 0.XX
   (Debian Bug #994154).
 - Properly handle quoted flags; reported by Olek Wojnar (see Debian Bug
   #975650 message 45).
+- Strip (basic) environment variables before compiler detection to reduce
+  false positives; reported by Fabian Wolff (Debian Bug #975650)
 
 
 Version 0.12
index 2f8da5f2c4efdda473a2e3d414f98e65f3d796c8..0c9360b360788163294b89e94b9832091c05b98c 100755 (executable)
--- a/bin/blhc
+++ b/bin/blhc
@@ -1022,9 +1022,29 @@ foreach my $file (@ARGV) {
                 $complete_line = undef;
             }
 
+            my $noenv = $line;
+            # Strip (basic) environment variables for compiler detection. This
+            # prevents false positives when environment variables contain
+            # compiler binaries. Nested quotes, command substitution, etc. is
+            # not supported.
+            $noenv =~ s/^
+                \s*
+                (?:
+                    [a-zA-Z_]+          # environment variable name
+                    =
+                    (?:
+                        [^\s"'\$`\\]+   # non-quoted string
+                        |
+                        '[^"'\$`\\]*'   # single-quoted string
+                        |
+                        "[^"'\$`\\]*"   # double-quoted string
+                    )
+                    \s+
+                )*
+            //x;
             # Ignore lines with no compiler commands.
             next if not $non_verbose
-                    and not $line =~ /$cc_regex_normal/o;
+                    and not $noenv =~ /$cc_regex_normal/o;
             # Ignore lines with no filenames with extensions. May miss some
             # non-verbose builds (e.g. "gcc -o test" [sic!]), but shouldn't be
             # a problem as the log will most likely contain other non-verbose
index 6b2a908d03d34c2bca6c437ed904040866398b33..990766c21c84bb5674119e8094c02389b2301f1c 100644 (file)
@@ -1,3 +1,4 @@
 dpkg-buildpackage: source package test
 
 VERSION=v-amd64-linux CPP="gcc -x assembler-with-cpp -E -P -Wdate-time -D_FORTIFY_SOURCE=2" CPPFLAGS="-Wdate-time -D_FORTIFY_SOURCE=2" ../../config/gen-posix-names.sh _SC_ ml_sysconf.h
+VERSION="`echo hi`" CPP="gcc -x assembler-with-cpp -E -P -Wdate-time -D_FORTIFY_SOURCE=2" CPPFLAGS="-Wdate-time -D_FORTIFY_SOURCE=2" ../../config/gen-posix-names.sh _SC_ ml_sysconf.h
index b4c0352f0caac860b92c9bb618acd3d05bb27cab..595c34e4b95e2d8a33a4ca34b816008f7f1e75f2 100644 (file)
--- a/t/tests.t
+++ b/t/tests.t
@@ -634,7 +634,7 @@ LDFLAGS missing (-fPIE -pie -Wl,-z,relro -Wl,-z,now): gcc -g -O2 -fstack-protect
 ';
 
 is_blhc 'env', '--all', 8,
-        'CPPFLAGS missing (-D_FORTIFY_SOURCE=2): VERSION=v-amd64-linux CPP="gcc -x assembler-with-cpp -E -P -Wdate-time -D_FORTIFY_SOURCE=2" CPPFLAGS="-Wdate-time -D_FORTIFY_SOURCE=2" ../../config/gen-posix-names.sh _SC_ ml_sysconf.h
+        'CPPFLAGS missing (-D_FORTIFY_SOURCE=2): VERSION="`echo hi`" CPP="gcc -x assembler-with-cpp -E -P -Wdate-time -D_FORTIFY_SOURCE=2" CPPFLAGS="-Wdate-time -D_FORTIFY_SOURCE=2" ../../config/gen-posix-names.sh _SC_ ml_sysconf.h
 ';