3 # Build log hardening check, checks build logs for missing hardening flags.
5 # Copyright (C) 2012 Simon Ruderich
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 use Term::ANSIColor ();
26 use Text::ParseWords ();
28 our $VERSION = '0.01';
33 # Regex to catch compiler commands.
35 (?<!\.)(?:cc|gcc|g\+\+|c\+\+)
38 # Full regex which matches the complete compiler name. Used in a few places to
39 # prevent false negatives.
40 my $cc_regex_full = qr/
41 (?:[a-z0-9_]+-(?:linux-|kfreebsd-)?gnu(?:eabi|eabihf)?-)?
44 # Regex to catch (GCC) compiler warnings.
45 my $warning_regex = qr/^(.+?):([0-9]+):[0-9]+: warning: (.+?) \[(.+?)\]$/;
47 # List of source file extensions which require preprocessing.
48 my @source_preprocess_compile_cpp = (
50 qw( cc cp cxx cpp CPP c++ C ),
54 my @source_preprocess_compile = (
60 @source_preprocess_compile_cpp,
62 qw( F FOR fpp FPP FTN F90 F95 F03 F08 ),
64 my @source_preprocess_no_compile = (
68 my @source_preprocess = (
69 @source_preprocess_compile,
70 @source_preprocess_no_compile,
72 # List of source file extensions which don't require preprocessing.
73 my @source_no_preprocess_compile_cpp = (
79 my @source_no_preprocess_compile = (
83 @source_no_preprocess_compile_cpp,
87 qw( f for ftn f90 f95 f03 f08 ),
89 my @source_no_preprocess_no_compile = (
93 my @source_no_preprocess = (
94 @source_no_preprocess_compile,
95 @source_no_preprocess_no_compile,
97 # List of header file extensions which require preprocessing.
98 my @header_preprocess = (
99 # C, C++, Objective-C, Objective-C++
102 qw( hh H hp hxx hpp HPP h++ tcc ),
105 # Hashes for fast extensions lookup to check if a file falls in one of these
107 my %extensions_no_preprocess = map { $_ => 1 } (
108 @source_no_preprocess,
110 my %extensions_preprocess = map { $_ => 1 } (
114 my %extensions_compile_link = map { $_ => 1 } (
116 @source_no_preprocess,
118 my %extensions_compile = map { $_ => 1 } (
119 @source_preprocess_compile,
120 @source_no_preprocess_compile,
122 my %extensions_no_compile = map { $_ => 1 } (
123 @source_preprocess_no_compile,
124 @source_no_preprocess_no_compile,
126 my %extensions_compile_cpp = map { $_ => 1 } (
127 @source_preprocess_compile_cpp,
128 @source_no_preprocess_compile_cpp,
130 my %extension = map { $_ => 1 } (
131 @source_no_preprocess,
132 @source_no_preprocess_compile,
133 @source_no_preprocess_compile_cpp,
134 @source_no_preprocess_no_compile,
137 @source_preprocess_compile,
138 @source_preprocess_compile_cpp,
139 @source_preprocess_no_compile,
142 # Regexp to match file extensions.
143 my $file_extension_regex = qr/
145 \S+ # Filename without extension.
147 ([^\\.,;:\s]+) # File extension.
148 (?=\s|\\) # At end of word. Can't use \b because some files have non
149 # word characters at the end and because \b matches double
150 # extensions (like .cpp.o). Works always as all lines are
151 # terminated with "\n".
154 # Expected (hardening) flags. All flags are used as regexps.
159 my @def_cflags_format = (
162 '-Werror=format-security',
164 my @def_cflags_fortify = (
165 # fortify needs at least -O1, but -O2 is recommended anyway
167 my @def_cflags_stack = (
169 '--param=ssp-buffer-size=4',
171 my @def_cflags_pie = (
177 # @def_cxxflags_* is the same as @def_cflags_*.
178 my @def_cppflags = ();
179 my @def_cppflags_fortify = (
180 '-D_FORTIFY_SOURCE=2',
182 my @def_ldflags = ();
183 my @def_ldflags_relro = (
186 my @def_ldflags_bindnow = (
189 my @def_ldflags_pie = (
193 my @def_ldflags_pic = (
198 # Renaming rules for the output so the regex parts are not visible. Also
199 # stores string values of flag regexps above, see compile_flag_regexp().
201 '-O(?:2|3)' => '-O2',
202 '-Wl,(?:-z,)?relro' => '-Wl,-z,relro',
203 '-Wl,(?:-z,)?now' => '-Wl,-z,now',
207 no_compiler_commands => 1 << 0,
208 # used by POD::Usage => 1 << 1,
209 non_verbose_build => 1 << 2,
210 flags_missing => 1 << 3,
211 hardening_wrapper => 1 << 4,
212 invalid_cmake => 1 << 5,
215 # Statistics of missing flags and non-verbose build commands. Used for
219 preprocess_missing => 0,
221 compile_missing => 0,
223 compile_cpp_missing => 0,
227 commands_nonverbose => 0,
230 # Use colored (ANSI) output?
237 my ($message, $missing_flags_ref, $flag_renames_ref, $line) = @_;
239 # Get string value of qr//-escaped regexps and if requested rename them.
240 my @missing_flags = map {
241 $flag_renames_ref->{$_}
242 } @{$missing_flags_ref};
244 my $flags = join ' ', @missing_flags;
245 printf "%s (%s)%s %s",
246 error_color($message, 'red'), $flags, error_color(':', 'yellow'),
249 sub error_non_verbose_build {
253 error_color('NONVERBOSE BUILD', 'red'),
254 error_color(':', 'yellow'),
257 sub error_invalid_cmake {
261 error_color('INVALID CMAKE', 'red'),
262 error_color(':', 'yellow'),
265 sub error_hardening_wrapper {
267 error_color('HARDENING WRAPPER', 'red'),
268 error_color(':', 'yellow'),
269 'no checks possible, aborting';
272 my ($message, $color) = @_;
275 return Term::ANSIColor::colored($message, $color);
282 my ($line, @flags) = @_;
284 foreach my $flag (@flags) {
285 return 1 if $line =~ /$flag/;
291 my ($line, $missing_flags_ref, @flags) = @_;
293 my @missing_flags = ();
294 foreach my $flag (@flags) {
295 if (not $line =~ /$flag/) {
296 push @missing_flags, $flag;
300 return 1 if scalar @missing_flags == 0;
302 @{$missing_flags_ref} = @missing_flags;
306 # Modifies $missing_flags_ref array.
307 sub pic_pie_conflict {
308 my ($line, $pie, $missing_flags_ref, @flags_pie) = @_;
310 return 0 if not $pie;
311 return 0 if not any_flags_used($line, @def_ldflags_pic);
313 my %flags = map { $_ => 1 } @flags_pie;
315 # Remove all PIE flags from @missing_flags as they are not required with
318 not exists $flags{$_}
319 } @{$missing_flags_ref};
320 @{$missing_flags_ref} = @result;
322 # We got a conflict when no flags are left, thus only PIE flags were
323 # missing. If other flags were missing abort because the conflict is not
325 return scalar @result == 0;
328 sub is_non_verbose_build {
329 my ($line, $next_line, $skip_ref) = @_;
331 if (not ($line =~ /^checking if you want to see long compiling messages\.\.\. no/
332 or $line =~ /^\s*\[?(?:CC|CCLD|C\+\+|CXX|CXXLD|LD|LINK)\]?\s+(.+?)$/
333 or $line =~ /^\s*(?:C|c)ompiling\s+(.+?)(?:\.\.\.)?$/
334 or $line =~ /^\s*(?:B|b)uilding (?:program|shared library)\s+(.+?)$/
335 or $line =~ /^\s*\[[\d ]+%\] Building (?:C|CXX) object (.+?)$/)) {
340 return 0 if $line =~ /^\s*C\+\+.+?:\s+(?:yes|no)\s*$/;
344 # On the first pass we only check if this line is verbose or not.
345 return 1 if not defined $next_line;
347 # Second pass, we have access to the next line.
350 # CMake and other build systems print the non-verbose messages also when
351 # building verbose. If a compiler and the file name occurs in the next
352 # line, treat it as verbose build.
354 # Get filename, we can't use the complete path as only parts of it are
355 # used in the real compiler command.
356 $file =~ m{/([^/\s]+)$};
359 if ($next_line =~ /\Q$file\E/ and $next_line =~ /$cc_regex/o) {
360 # We still have to skip the current line as it doesn't contain any
370 sub compile_flag_regexp {
371 my ($flag_renames_ref, @flags) = @_;
374 foreach my $flag (@flags) {
375 # Store flag name in replacement string for correct flags in messages
376 # with qr//ed flag regexps.
377 $flag_renames_ref->{qr/\s$flag(?:\s|\\)/}
378 = (exists $flag_renames_ref->{$flag})
379 ? $flag_renames_ref->{$flag}
382 # Compile flag regexp for faster execution.
383 push @result, qr/\s$flag(?:\s|\\)/;
388 sub extension_found {
389 my ($extensions_ref, @extensions) = @_;
392 foreach my $extension (@extensions) {
393 if (exists $extensions_ref->{$extension}) {
404 # Parse command line arguments.
406 my $option_version = 0;
408 my $option_bindnow = 0;
410 my $option_arch = undef;
411 my $option_buildd = 0;
413 if (not Getopt::Long::GetOptions(
414 'help|h|?' => \$option_help,
415 'version' => \$option_version,
417 'pie' => \$option_pie,
418 'bindnow' => \$option_bindnow,
419 'all' => \$option_all,
421 'color' => \$option_color,
422 'arch=s' => \$option_arch,
423 'buildd' => \$option_buildd,
426 Pod::Usage::pod2usage(2);
430 Pod::Usage::pod2usage(1);
432 if ($option_version) {
433 print "blhc $VERSION Copyright (C) 2012 Simon Ruderich
435 This program is free software: you can redistribute it and/or modify
436 it under the terms of the GNU General Public License as published by
437 the Free Software Foundation, either version 3 of the License, or
438 (at your option) any later version.
440 This program is distributed in the hope that it will be useful,
441 but WITHOUT ANY WARRANTY; without even the implied warranty of
442 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
443 GNU General Public License for more details.
445 You should have received a copy of the GNU General Public License
446 along with this program. If not, see <http://www.gnu.org/licenses/>.
456 # Precompile all flag regexps. any_flags_used(), all_flags_used() get a lot
458 @def_cflags = compile_flag_regexp(\%flag_renames, @def_cflags);
459 @def_cflags_format = compile_flag_regexp(\%flag_renames, @def_cflags_format);
460 @def_cflags_fortify = compile_flag_regexp(\%flag_renames, @def_cflags_fortify);
461 @def_cflags_stack = compile_flag_regexp(\%flag_renames, @def_cflags_stack);
462 @def_cflags_pie = compile_flag_regexp(\%flag_renames, @def_cflags_pie);
463 @def_cxxflags = compile_flag_regexp(\%flag_renames, @def_cxxflags);
464 @def_cppflags = compile_flag_regexp(\%flag_renames, @def_cppflags);
465 @def_cppflags_fortify = compile_flag_regexp(\%flag_renames, @def_cppflags_fortify);
466 @def_ldflags = compile_flag_regexp(\%flag_renames, @def_ldflags);
467 @def_ldflags_relro = compile_flag_regexp(\%flag_renames, @def_ldflags_relro);
468 @def_ldflags_bindnow = compile_flag_regexp(\%flag_renames, @def_ldflags_bindnow);
469 @def_ldflags_pie = compile_flag_regexp(\%flag_renames, @def_ldflags_pie);
470 @def_ldflags_pic = compile_flag_regexp(\%flag_renames, @def_ldflags_pic);
475 FILE: foreach my $file (@ARGV) {
476 print "checking '$file'...\n" if scalar @ARGV > 1;
478 open my $fh, '<', $file or die "$!: $file";
480 # Architecture of this file.
481 my $arch = $option_arch;
483 # Hardening options. Not all architectures support all hardening options.
484 my $harden_format = 1;
485 my $harden_fortify = 1;
486 my $harden_stack = 1;
487 my $harden_relro = 1;
488 my $harden_bindnow = $option_bindnow; # defaults to 0
489 my $harden_pie = $option_pie; # defaults to 0
491 while (my $line = <$fh>) {
492 # dpkg-buildflags only provides hardening flags since 1.16.1, don't
493 # check for hardening flags in buildd mode if an older dpkg-dev is
494 # used. Default flags (-g -O2) are still checked.
496 # Packages which were built before 1.16.1 but used their own hardening
497 # flags are not checked.
498 if ($option_buildd and $line =~ /^Toolchain package versions: /) {
499 require Dpkg::Version;
500 if ($line !~ /\bdpkg-dev_(\S+)/
501 or Dpkg::Version::version_compare($1, '1.16.1') < 0) {
511 # The following two versions of CMake in Debian obeyed CPPFLAGS, but
512 # this was later dropped because upstream rejected the patch. Thus
513 # build logs with these versions will have fortify hardening flags
514 # enabled, even though they may be not correctly set and are missing
515 # when build with later CMake versions. Thanks to Aron Xu for letting
517 if ($line =~ /^Package versions: /
518 and $line =~ /\bcmake_(\S+)/
519 and ($1 eq '2.8.7-1' or $1 eq '2.8.7-2')) {
520 if (not $option_buildd) {
521 error_invalid_cmake($1);
523 print "W-invalid-cmake-used $1\n";
525 $exit |= $exit_code{invalid_cmake};
528 # If hardening wrapper is used (wraps calls to gcc and adds hardening
529 # flags automatically) we can't perform any checks, abort.
530 if ($line =~ /^Build-Depends: .*\bhardening-wrapper\b/) {
531 if (not $option_buildd) {
532 error_hardening_wrapper();
534 print "I-hardening-wrapper-used\n";
536 $exit |= $exit_code{hardening_wrapper};
540 # We skip over unimportant lines at the beginning of the log to
541 # prevent false positives.
542 last if $line =~ /^dpkg-buildpackage:/;
545 # Input lines, contain only the lines with compiler commands.
548 my $continuation = 0;
549 my $complete_line = undef;
550 while (my $line = <$fh>) {
551 # And stop at the end of the build log. Package details (reported by
552 # the buildd logs) are not important for us. This also prevents false
554 last if $line =~ /^Build finished at \d{8}-\d{4}$/;
556 # Detect architecture automatically unless overridden.
558 and $line =~ /^dpkg-buildpackage: host architecture (.+)$/) {
562 # Ignore compiler warnings for now.
563 next if $line =~ /$warning_regex/o;
565 if ($line =~ /\033/) { # esc
566 # Remove all ANSI color sequences which are sometimes used in
567 # non-verbose builds.
568 $line = Term::ANSIColor::colorstrip($line);
569 # Also strip '\0xf' (delete previous character), used by Elinks'
572 # And "ESC(B" which seems to be used on armhf and hurd (not sure
574 $line =~ s/\033\(B//g;
577 # Check if this line indicates a non verbose build.
578 my $non_verbose = is_non_verbose_build($line);
580 # One line may contain multiple commands (";"). Treat each one as
581 # single line. parse_line() is slow, only use it when necessary.
582 my @line = (not $line =~ /;/)
585 # Ensure newline at the line end - necessary for
586 # correct parsing later.
589 } Text::ParseWords::parse_line(';', 1, $line);
590 foreach $line (@line) {
594 # Join lines, but leave the "\" in place so it's clear where
595 # the original line break was.
596 chomp $complete_line;
597 $complete_line .= ' ' . $line;
599 # Line continuation, line ends with "\".
600 if ($line =~ /\\\s*$/) {
602 # Start line continuation.
603 if (not defined $complete_line) {
604 $complete_line = $line;
609 if (not $continuation) {
610 # Use the complete line if a line continuation occurred.
611 if (defined $complete_line) {
612 $line = $complete_line;
613 $complete_line = undef;
616 # Ignore lines with no compiler commands.
617 next if not $non_verbose
618 and not $line =~ /\b$cc_regex(?:\s|\\)/o;
619 # Ignore lines with no filenames with extensions. May miss
620 # some non-verbose builds (e.g. "gcc -o test" [sic!]), but
621 # shouldn't be a problem as the log will most likely contain
622 # other non-verbose commands which are detected.
623 next if not $non_verbose
624 and not $line =~ /$file_extension_regex/o;
626 # Ignore false positives.
628 # `./configure` output.
629 next if not $non_verbose
630 and $line =~ /^(?:checking|(?:C|c)onfigure:) /;
631 next if $line =~ /^\s*(?:Host\s+)?(?:C(?:\+\+)?\s+)?
632 (?:C|c)ompiler[\s.]*:?\s+
634 next if $line =~ /^\s*(?:- )?(?:HOST_)?(?:CC|CXX)\s*=\s*$cc_regex_full\s*$/o;
636 # Check if additional hardening options were used. Used to
637 # ensure they are used for the complete build.
638 $harden_pie = 1 if any_flags_used($line, @def_cflags_pie, @def_ldflags_pie);
639 $harden_bindnow = 1 if any_flags_used($line, @def_ldflags_bindnow);
648 if (scalar @input == 0) {
649 if (not $option_buildd) {
650 print "No compiler commands!\n";
652 print "W-no-compiler-commands\n";
654 $exit |= $exit_code{no_compiler_commands};
658 if ($option_buildd) {
659 $statistics{commands} += scalar @input;
662 # Option or auto detected.
664 # The following was partially copied from dpkg-dev 1.16.1.2
665 # (/usr/share/perl5/Dpkg/Vendor/Debian.pm, add_hardening_flags()),
666 # copyright Raphaël Hertzog <hertzog@debian.org>, Kees Cook
667 # <kees@debian.org>, Canonical, Ltd. licensed under GPL version 2 or
668 # later. Keep it in sync.
671 my ($abi, $os, $cpu) = Dpkg::Arch::debarch_to_debtriplet($arch);
673 # Disable unsupported hardening options.
674 if ($cpu =~ /^(ia64|alpha|mips|mipsel|hppa)$/ or $arch eq 'arm') {
677 if ($cpu =~ /^(ia64|hppa|avr32)$/) {
684 my @cflags = @def_cflags;
685 my @cxxflags = @def_cxxflags;
686 my @cppflags = @def_cppflags;
687 my @ldflags = @def_ldflags;
688 # Check the specified hardening options, same order as dpkg-buildflags.
690 @cflags = (@cflags, @def_cflags_pie);
691 @cxxflags = (@cxxflags, @def_cflags_pie);
692 @ldflags = (@ldflags, @def_ldflags_pie);
695 @cflags = (@cflags, @def_cflags_stack);
696 @cxxflags = (@cxxflags, @def_cflags_stack);
698 if ($harden_fortify) {
699 @cflags = (@cflags, @def_cflags_fortify);
700 @cxxflags = (@cxxflags, @def_cflags_fortify);
701 @cppflags = (@cppflags, @def_cppflags_fortify);
703 if ($harden_format) {
704 @cflags = (@cflags, @def_cflags_format);
705 @cxxflags = (@cxxflags, @def_cflags_format);
708 @ldflags = (@ldflags, @def_ldflags_relro);
710 if ($harden_bindnow) {
711 @ldflags = (@ldflags, @def_ldflags_bindnow);
714 for (my $i = 0; $i < scalar @input; $i++) {
715 my $line = $input[$i];
718 if (is_non_verbose_build($line, $input[$i + 1], \$skip)) {
719 if (not $option_buildd) {
720 error_non_verbose_build($line);
722 $statistics{commands_nonverbose}++;
724 $exit |= $exit_code{non_verbose_build};
727 # Even if it's a verbose build, we might have to skip this line.
730 # Remove everything until and including the compiler command. Makes
731 # checks easier and faster.
732 $line =~ s/^.*?$cc_regex//o;
733 # "([...] test.c)" is not detected as 'test.c' - fix this by removing
734 # the brace and similar characters.
735 $line =~ s/['")]+$//;
737 # Skip unnecessary tests when only preprocessing.
738 my $flag_preprocess = 0;
744 # Preprocess, compile, assemble.
745 if ($line =~ /\s(-E|-S|-c)\b/) {
747 $flag_preprocess = 1 if $1 eq '-E';
748 $compile = 1 if $1 eq '-S' or $1 eq '-c';
749 # Otherwise assume we are linking.
754 # Get all file extensions on this line.
755 my @extensions = $line =~ /$file_extension_regex/go;
756 # Ignore all unknown extensions to speedup the search below.
757 @extensions = grep { exists $extension{$_} } @extensions;
759 # These file types don't require preprocessing.
760 if (extension_found(\%extensions_no_preprocess, @extensions)) {
763 # These file types require preprocessing.
764 if (extension_found(\%extensions_preprocess, @extensions)) {
768 # If there are source files then it's compiling/linking in one step
769 # and we must check both. We only check for source files here, because
770 # header files cause too many false positives.
771 if (not $flag_preprocess
772 and extension_found(\%extensions_compile_link, @extensions)) {
773 # Assembly files don't need CFLAGS.
774 if (not extension_found(\%extensions_compile, @extensions)
775 and extension_found(\%extensions_no_compile, @extensions)) {
783 # Assume CXXFLAGS are required when a C++ file is specified in the
787 and extension_found(\%extensions_compile_cpp, @extensions)) {
792 if ($option_buildd) {
793 $statistics{preprocess}++ if $preprocess;
794 $statistics{compile}++ if $compile;
795 $statistics{compile_cpp}++ if $compile_cpp;
796 $statistics{link}++ if $link;
799 # Check hardening flags.
801 if ($compile and not all_flags_used($line, \@missing, @cflags)
802 # Libraries linked with -fPIC don't have to (and can't) be
803 # linked with -fPIE as well. It's no error if only PIE flags
805 and not pic_pie_conflict($line, $harden_pie, \@missing, @def_cflags_pie)
806 # Assume dpkg-buildflags returns the correct flags.
807 and not $line =~ /`dpkg-buildflags --get CFLAGS`/) {
808 if (not $option_buildd) {
809 error_flags('CFLAGS missing', \@missing, \%flag_renames, $input[$i]);
811 $statistics{compile_missing}++;
813 $exit |= $exit_code{flags_missing};
814 } elsif ($compile_cpp and not all_flags_used($line, \@missing, @cflags)
815 # Libraries linked with -fPIC don't have to (and can't) be
816 # linked with -fPIE as well. It's no error if only PIE flags
818 and not pic_pie_conflict($line, $harden_pie, \@missing, @def_cflags_pie)
819 # Assume dpkg-buildflags returns the correct flags.
820 and not $line =~ /`dpkg-buildflags --get CXXFLAGS`/) {
821 if (not $option_buildd) {
822 error_flags('CXXFLAGS missing', \@missing, \%flag_renames, $input[$i]);
824 $statistics{compile_cpp_missing}++;
826 $exit |= $exit_code{flags_missing};
828 if ($preprocess and not all_flags_used($line, \@missing, @cppflags)
829 # Assume dpkg-buildflags returns the correct flags.
830 and not $line =~ /`dpkg-buildflags --get CPPFLAGS`/) {
831 if (not $option_buildd) {
832 error_flags('CPPFLAGS missing', \@missing, \%flag_renames, $input[$i]);
834 $statistics{preprocess_missing}++;
836 $exit |= $exit_code{flags_missing};
838 if ($link and not all_flags_used($line, \@missing, @ldflags)
839 # Same here, -fPIC conflicts with -fPIE.
840 and not pic_pie_conflict($line, $harden_pie, \@missing, @def_ldflags_pie)
841 # Assume dpkg-buildflags returns the correct flags.
842 and not $line =~ /`dpkg-buildflags --get LDFLAGS`/) {
843 if (not $option_buildd) {
844 error_flags('LDFLAGS missing', \@missing, \%flag_renames, $input[$i]);
846 $statistics{link_missing}++;
848 $exit |= $exit_code{flags_missing};
853 # Print statistics for buildd mode, only output in this mode.
854 if ($option_buildd) {
857 if ($statistics{preprocess_missing}) {
858 push @warning, sprintf "CPPFLAGS %d (of %d)",
859 $statistics{preprocess_missing},
860 $statistics{preprocess};
862 if ($statistics{compile_missing}) {
863 push @warning, sprintf "CFLAGS %d (of %d)",
864 $statistics{compile_missing},
865 $statistics{compile};
867 if ($statistics{compile_cpp_missing}) {
868 push @warning, sprintf "CXXFLAGS %d (of %d)",
869 $statistics{compile_cpp_missing},
870 $statistics{compile_cpp};
872 if ($statistics{link_missing}) {
873 push @warning, sprintf "LDFLAGS %d (of %d)",
874 $statistics{link_missing},
877 if (scalar @warning) {
878 local $" = ', '; # array join string
879 print "W-dpkg-buildflags-missing @warning missing\n";
882 if ($statistics{commands_nonverbose}) {
883 printf "W-compiler-flags-hidden %d (of %d) hidden\n",
884 $statistics{commands_nonverbose},
885 $statistics{commands},
897 blhc - build log hardening check, checks build logs for missing hardening flags
901 B<blhc> [I<options>] I<E<lt>dpkg-buildpackage build log fileE<gt>..>
905 blhc is a small tool which checks build logs for missing hardening flags and
906 other important warnings. It's licensed under the GPL 3 or later.
914 Force check for all +all (+pie, +bindnow) hardening flags. By default it's
917 =item B<--arch> I<architecture>
919 Set the specific architecture (e.g. amd64, armel, etc.), automatically
920 disables hardening flags not available on this architecture. Is detected
921 automatically if dpkg-buildpackage is used.
925 Force check for all +bindnow hardening flags. By default it's auto detected.
929 Special mode for buildds when automatically parsing log files. The following
930 changes are in effect:
936 Don't check hardening flags in old log files (if dpkg-dev << 1.16.1 is
943 Use colored (ANSI) output for warning messages.
947 Force check for all +pie hardening flags. By default it's auto detected.
949 =item B<-h -? --help>
951 Print available options.
955 Print version number and license.
959 Auto detection for B<--pie> and B<--bindnow> only works if at least one
960 command uses the required hardening flag (e.g. -fPIE). Then it's required for
961 all other commands as well.
965 The exit status is a "bit mask", each listed status is ORed when the error
966 condition occurs to get the result.
976 No compiler commands were found.
980 Invalid arguments/options given to blhc.
988 Missing hardening flags.
992 Hardening wrapper detected, no tests performed.
998 Simon Ruderich, E<lt>simon@ruderich.orgE<gt>
1000 =head1 COPYRIGHT AND LICENSE
1002 Copyright (C) 2012 by Simon Ruderich
1004 This program is free software: you can redistribute it and/or modify
1005 it under the terms of the GNU General Public License as published by
1006 the Free Software Foundation, either version 3 of the License, or
1007 (at your option) any later version.
1009 This program is distributed in the hope that it will be useful,
1010 but WITHOUT ANY WARRANTY; without even the implied warranty of
1011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1012 GNU General Public License for more details.
1014 You should have received a copy of the GNU General Public License
1015 along with this program. If not, see <http://www.gnu.org/licenses/>.