X-Git-Url: https://ruderich.org/simon/gitweb/?p=blhc%2Fblhc.git;a=blobdiff_plain;f=bin%2Fblhc;h=f11ba111028c3949fd526a8f89eee47f316fba2c;hp=168a1699c21744707ff22708aebd49e7c44ef20d;hb=14b61d421e2479318cb2971acc1c94812f5a8ac1;hpb=47eb461331046250bbe1b2d39f73266a25bb5315 diff --git a/bin/blhc b/bin/blhc index 168a169..f11ba11 100755 --- 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.