]> ruderich.org/simon Gitweb - blhc/blhc.git/blobdiff - bin/blhc
Detect restore of -D_FORTIFY_SOURCE=2
[blhc/blhc.git] / bin / blhc
index 168a1699c21744707ff22708aebd49e7c44ef20d..f11ba111028c3949fd526a8f89eee47f316fba2c 100755 (executable)
--- a/bin/blhc
+++ b/bin/blhc
@@ -431,17 +431,33 @@ sub all_flags_used {
 sub cppflags_fortify_broken {
     my ($line, $missing_flags) = @_;
 
-    # This doesn't take the position into account, but is a simple solution.
-    # And if the build system tries to force -D_FORTIFY_SOURCE=0/1, something
-    # is wrong anyway.
-
-    if (any_flags_used($line, @def_cppflags_fortify_bad)) {
-        # $def_cppflags_fortify[0] must be -D_FORTIFY_SOURCE=2!
-        push @{$missing_flags}, $def_cppflags_fortify[0];
-        return 1;
+    if (not any_flags_used($line, @def_cppflags_fortify_bad)) {
+        return 0;
     }
 
-    return 0;
+    # $def_cppflags_fortify[0] must be -D_FORTIFY_SOURCE=2!
+    my $fortify_source = $def_cppflags_fortify[0];
+
+    # Some build systems enable/disable fortify source multiple times, check
+    # the final result.
+    my $disable_pos = 0;
+    foreach my $flag (@def_cppflags_fortify_bad) {
+        while ($line =~ /$flag/g) {
+            if ($disable_pos < $+[0]) {
+                $disable_pos = $+[0];
+            }
+        }
+    }
+    my $enable_pos = 0;
+    while ($line =~ /$fortify_source/g) {
+        $enable_pos = $+[0];
+    }
+    if ($enable_pos > $disable_pos) {
+        return 0;
+    }
+
+    push @{$missing_flags}, $fortify_source;
+    return 1;
 }
 
 # Modifies $missing_flags_ref array.