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,
136 # Regexp to match file extensions.
137 my $file_extension_regex = qr/
139 \S+ # Filename without extension.
141 ([^\\.,;:\s]+) # File extension.
142 (?=\s|\\) # At end of word. Can't use \b because some files have non
143 # word characters at the end and because \b matches double
144 # extensions (like .cpp.o). Works always as all lines are
145 # terminated with "\n".
148 # Expected (hardening) flags. All flags are used as regexps.
153 my @def_cflags_format = (
156 '-Werror=format-security',
158 my @def_cflags_fortify = (
159 # fortify needs at least -O1, but -O2 is recommended anyway
161 my @def_cflags_stack = (
163 '--param=ssp-buffer-size=4',
165 my @def_cflags_pie = (
171 # @def_cxxflags_* is the same as @def_cflags_*.
172 my @def_cppflags = ();
173 my @def_cppflags_fortify = (
174 '-D_FORTIFY_SOURCE=2',
176 my @def_ldflags = ();
177 my @def_ldflags_relro = (
180 my @def_ldflags_bindnow = (
183 my @def_ldflags_pie = (
187 my @def_ldflags_pic = (
192 # Renaming rules for the output so the regex parts are not visible. Also
193 # stores string values of flag regexps above, see compile_flag_regexp().
195 '-O(?:2|3)' => '-O2',
196 '-Wl,(?:-z,)?relro' => '-Wl,-z,relro',
197 '-Wl,(?:-z,)?now' => '-Wl,-z,now',
201 no_compiler_commands => 1 << 0,
202 # used by POD::Usage => 1 << 1,
203 non_verbose_build => 1 << 2,
204 flags_missing => 1 << 3,
205 hardening_wrapper => 1 << 4,
206 invalid_cmake => 1 << 5,
209 # Statistics of missing flags and non-verbose build commands. Used for
213 preprocess_missing => 0,
215 compile_missing => 0,
217 compile_cpp_missing => 0,
221 commands_nonverbose => 0,
224 # Use colored (ANSI) output?
231 my ($message, $missing_flags_ref, $flag_renames_ref, $line) = @_;
233 # Get string value of qr//-escaped regexps and if requested rename them.
234 my @missing_flags = map {
235 $flag_renames_ref->{$_}
236 } @{$missing_flags_ref};
238 my $flags = join ' ', @missing_flags;
239 printf "%s (%s)%s %s",
240 error_color($message, 'red'), $flags, error_color(':', 'yellow'),
243 sub error_non_verbose_build {
247 error_color('NONVERBOSE BUILD', 'red'),
248 error_color(':', 'yellow'),
251 sub error_invalid_cmake {
255 error_color('INVALID CMAKE', 'red'),
256 error_color(':', 'yellow'),
259 sub error_hardening_wrapper {
261 error_color('HARDENING WRAPPER', 'red'),
262 error_color(':', 'yellow'),
263 'no checks possible, aborting';
266 my ($message, $color) = @_;
269 return Term::ANSIColor::colored($message, $color);
276 my ($line, @flags) = @_;
278 foreach my $flag (@flags) {
279 return 1 if $line =~ /$flag/;
285 my ($line, $missing_flags_ref, @flags) = @_;
287 my @missing_flags = ();
288 foreach my $flag (@flags) {
289 if (not $line =~ /$flag/) {
290 push @missing_flags, $flag;
294 return 1 if scalar @missing_flags == 0;
296 @{$missing_flags_ref} = @missing_flags;
300 # Modifies $missing_flags_ref array.
301 sub pic_pie_conflict {
302 my ($line, $pie, $missing_flags_ref, @flags_pie) = @_;
304 return 0 if not $pie;
305 return 0 if not any_flags_used($line, @def_ldflags_pic);
307 my %flags = map { $_ => 1 } @flags_pie;
309 # Remove all PIE flags from @missing_flags as they are not required with
312 not exists $flags{$_}
313 } @{$missing_flags_ref};
314 @{$missing_flags_ref} = @result;
316 # We got a conflict when no flags are left, thus only PIE flags were
317 # missing. If other flags were missing abort because the conflict is not
319 return scalar @result == 0;
322 sub is_non_verbose_build {
323 my ($line, $next_line, $skip_ref) = @_;
325 if (not ($line =~ /^checking if you want to see long compiling messages\.\.\. no/
326 or $line =~ /^\s*\[?(?:CC|CCLD|C\+\+|CXX|CXXLD|LD|LINK)\]?\s+(.+?)$/
327 or $line =~ /^\s*(?:C|c)ompiling\s+(.+?)(?:\.\.\.)?$/
328 or $line =~ /^\s*(?:B|b)uilding (?:program|shared library)\s+(.+?)$/
329 or $line =~ /^\s*\[[\d ]+%\] Building (?:C|CXX) object (.+?)$/)) {
334 return 0 if $line =~ /^\s*C\+\+.+?:\s+(?:yes|no)\s*$/;
338 # On the first pass we only check if this line is verbose or not.
339 return 1 if not defined $next_line;
341 # Second pass, we have access to the next line.
344 # CMake and other build systems print the non-verbose messages also when
345 # building verbose. If a compiler and the file name occurs in the next
346 # line, treat it as verbose build.
348 # Get filename, we can't use the complete path as only parts of it are
349 # used in the real compiler command.
350 $file =~ m{/([^/\s]+)$};
353 if ($next_line =~ /\Q$file\E/ and $next_line =~ /$cc_regex/o) {
354 # We still have to skip the current line as it doesn't contain any
364 sub compile_flag_regexp {
365 my ($flag_renames_ref, @flags) = @_;
368 foreach my $flag (@flags) {
369 # Store flag name in replacement string for correct flags in messages
370 # with qr//ed flag regexps.
371 $flag_renames_ref->{qr/\s$flag(?:\s|\\)/}
372 = (exists $flag_renames_ref->{$flag})
373 ? $flag_renames_ref->{$flag}
376 # Compile flag regexp for faster execution.
377 push @result, qr/\s$flag(?:\s|\\)/;
382 sub extension_found {
383 my ($extensions_ref, @extensions) = @_;
386 foreach my $extension (@extensions) {
387 if (exists $extensions_ref->{$extension}) {
398 # Parse command line arguments.
400 my $option_version = 0;
402 my $option_bindnow = 0;
404 my $option_arch = undef;
405 my $option_buildd = 0;
407 if (not Getopt::Long::GetOptions(
408 'help|h|?' => \$option_help,
409 'version' => \$option_version,
411 'pie' => \$option_pie,
412 'bindnow' => \$option_bindnow,
413 'all' => \$option_all,
415 'color' => \$option_color,
416 'arch=s' => \$option_arch,
417 'buildd' => \$option_buildd,
420 Pod::Usage::pod2usage(2);
424 Pod::Usage::pod2usage(1);
426 if ($option_version) {
427 print "blhc $VERSION Copyright (C) 2012 Simon Ruderich
429 This program is free software: you can redistribute it and/or modify
430 it under the terms of the GNU General Public License as published by
431 the Free Software Foundation, either version 3 of the License, or
432 (at your option) any later version.
434 This program is distributed in the hope that it will be useful,
435 but WITHOUT ANY WARRANTY; without even the implied warranty of
436 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
437 GNU General Public License for more details.
439 You should have received a copy of the GNU General Public License
440 along with this program. If not, see <http://www.gnu.org/licenses/>.
450 # Precompile all flag regexps. any_flags_used(), all_flags_used() get a lot
452 @def_cflags = compile_flag_regexp(\%flag_renames, @def_cflags);
453 @def_cflags_format = compile_flag_regexp(\%flag_renames, @def_cflags_format);
454 @def_cflags_fortify = compile_flag_regexp(\%flag_renames, @def_cflags_fortify);
455 @def_cflags_stack = compile_flag_regexp(\%flag_renames, @def_cflags_stack);
456 @def_cflags_pie = compile_flag_regexp(\%flag_renames, @def_cflags_pie);
457 @def_cxxflags = compile_flag_regexp(\%flag_renames, @def_cxxflags);
458 @def_cppflags = compile_flag_regexp(\%flag_renames, @def_cppflags);
459 @def_cppflags_fortify = compile_flag_regexp(\%flag_renames, @def_cppflags_fortify);
460 @def_ldflags = compile_flag_regexp(\%flag_renames, @def_ldflags);
461 @def_ldflags_relro = compile_flag_regexp(\%flag_renames, @def_ldflags_relro);
462 @def_ldflags_bindnow = compile_flag_regexp(\%flag_renames, @def_ldflags_bindnow);
463 @def_ldflags_pie = compile_flag_regexp(\%flag_renames, @def_ldflags_pie);
464 @def_ldflags_pic = compile_flag_regexp(\%flag_renames, @def_ldflags_pic);
469 FILE: foreach my $file (@ARGV) {
470 print "checking '$file'...\n" if scalar @ARGV > 1;
472 open my $fh, '<', $file or die "$!: $file";
474 # Architecture of this file.
475 my $arch = $option_arch;
477 # Hardening options. Not all architectures support all hardening options.
478 my $harden_format = 1;
479 my $harden_fortify = 1;
480 my $harden_stack = 1;
481 my $harden_relro = 1;
482 my $harden_bindnow = $option_bindnow; # defaults to 0
483 my $harden_pie = $option_pie; # defaults to 0
485 while (my $line = <$fh>) {
486 # dpkg-buildflags only provides hardening flags since 1.16.1, don't
487 # check for hardening flags in buildd mode if an older dpkg-dev is
488 # used. Default flags (-g -O2) are still checked.
490 # Packages which were built before 1.16.1 but used their own hardening
491 # flags are not checked.
492 if ($option_buildd and $line =~ /^Toolchain package versions: /) {
493 require Dpkg::Version;
494 if ($line !~ /\bdpkg-dev_(\S+)/
495 or Dpkg::Version::version_compare($1, '1.16.1') < 0) {
505 # The following two versions of CMake in Debian obeyed CPPFLAGS, but
506 # this was later dropped because upstream rejected the patch. Thus
507 # build logs with these versions will have fortify hardening flags
508 # enabled, even though they may be not correctly set and are missing
509 # when build with later CMake versions. Thanks to Aron Xu for letting
511 if ($line =~ /^Package versions: /
512 and $line =~ /\bcmake_(\S+)/
513 and ($1 eq '2.8.7-1' or $1 eq '2.8.7-2')) {
514 if (not $option_buildd) {
515 error_invalid_cmake($1);
517 print "W-invalid-cmake-used $1\n";
519 $exit |= $exit_code{invalid_cmake};
522 # If hardening wrapper is used (wraps calls to gcc and adds hardening
523 # flags automatically) we can't perform any checks, abort.
524 if ($line =~ /^Build-Depends: .*\bhardening-wrapper\b/) {
525 if (not $option_buildd) {
526 error_hardening_wrapper();
528 print "I-hardening-wrapper-used\n";
530 $exit |= $exit_code{hardening_wrapper};
534 # We skip over unimportant lines at the beginning of the log to
535 # prevent false positives.
536 last if $line =~ /^dpkg-buildpackage:/;
539 # Input lines, contain only the lines with compiler commands.
542 my $continuation = 0;
543 my $complete_line = undef;
544 while (my $line = <$fh>) {
545 # And stop at the end of the build log. Package details (reported by
546 # the buildd logs) are not important for us. This also prevents false
548 last if $line =~ /^Build finished at \d{8}-\d{4}$/;
550 # Detect architecture automatically unless overridden.
552 and $line =~ /^dpkg-buildpackage: host architecture (.+)$/) {
556 # Ignore compiler warnings for now.
557 next if $line =~ /$warning_regex/o;
559 if ($line =~ /\033/) { # esc
560 # Remove all ANSI color sequences which are sometimes used in
561 # non-verbose builds.
562 $line = Term::ANSIColor::colorstrip($line);
563 # Also strip '\0xf' (delete previous character), used by Elinks'
566 # And "ESC(B" which seems to be used on armhf and hurd (not sure
568 $line =~ s/\033\(B//g;
571 # Check if this line indicates a non verbose build.
572 my $non_verbose = is_non_verbose_build($line);
574 # One line may contain multiple commands (";"). Treat each one as
575 # single line. parse_line() is slow, only use it when necessary.
576 my @line = (not $line =~ /;/)
579 # Ensure newline at the line end - necessary for
580 # correct parsing later.
583 } Text::ParseWords::parse_line(';', 1, $line);
584 foreach $line (@line) {
588 # Join lines, but leave the "\" in place so it's clear where
589 # the original line break was.
590 chomp $complete_line;
591 $complete_line .= ' ' . $line;
593 # Line continuation, line ends with "\".
594 if ($line =~ /\\\s*$/) {
596 # Start line continuation.
597 if (not defined $complete_line) {
598 $complete_line = $line;
603 if (not $continuation) {
604 # Use the complete line if a line continuation occurred.
605 if (defined $complete_line) {
606 $line = $complete_line;
607 $complete_line = undef;
610 # Ignore lines with no compiler commands.
611 next if not $non_verbose
612 and not $line =~ /\b$cc_regex(?:\s|\\)/o;
613 # Ignore lines with no filenames with extensions. May miss
614 # some non-verbose builds (e.g. "gcc -o test" [sic!]), but
615 # shouldn't be a problem as the log will most likely contain
616 # other non-verbose commands which are detected.
617 next if not $non_verbose
618 and not $line =~ /$file_extension_regex/o;
620 # Ignore false positives.
622 # `./configure` output.
623 next if not $non_verbose
624 and $line =~ /^(?:checking|(?:C|c)onfigure:) /;
625 next if $line =~ /^\s*(?:Host\s+)?(?:C(?:\+\+)?\s+)?
626 (?:C|c)ompiler[\s.]*:?\s+
628 next if $line =~ /^\s*(?:- )?(?:HOST_)?(?:CC|CXX)\s*=\s*$cc_regex_full\s*$/o;
630 # Check if additional hardening options were used. Used to
631 # ensure they are used for the complete build.
632 $harden_pie = 1 if any_flags_used($line, @def_cflags_pie, @def_ldflags_pie);
633 $harden_bindnow = 1 if any_flags_used($line, @def_ldflags_bindnow);
642 if (scalar @input == 0) {
643 if (not $option_buildd) {
644 print "No compiler commands!\n";
646 print "W-no-compiler-commands\n";
648 $exit |= $exit_code{no_compiler_commands};
652 if ($option_buildd) {
653 $statistics{commands} += scalar @input;
656 # Option or auto detected.
658 # The following was partially copied from dpkg-dev 1.16.1.2
659 # (/usr/share/perl5/Dpkg/Vendor/Debian.pm, add_hardening_flags()),
660 # copyright Raphaël Hertzog <hertzog@debian.org>, Kees Cook
661 # <kees@debian.org>, Canonical, Ltd. licensed under GPL version 2 or
662 # later. Keep it in sync.
665 my ($abi, $os, $cpu) = Dpkg::Arch::debarch_to_debtriplet($arch);
667 # Disable unsupported hardening options.
668 if ($cpu =~ /^(ia64|alpha|mips|mipsel|hppa)$/ or $arch eq 'arm') {
671 if ($cpu =~ /^(ia64|hppa|avr32)$/) {
678 my @cflags = @def_cflags;
679 my @cxxflags = @def_cxxflags;
680 my @cppflags = @def_cppflags;
681 my @ldflags = @def_ldflags;
682 # Check the specified hardening options, same order as dpkg-buildflags.
684 @cflags = (@cflags, @def_cflags_pie);
685 @cxxflags = (@cxxflags, @def_cflags_pie);
686 @ldflags = (@ldflags, @def_ldflags_pie);
689 @cflags = (@cflags, @def_cflags_stack);
690 @cxxflags = (@cxxflags, @def_cflags_stack);
692 if ($harden_fortify) {
693 @cflags = (@cflags, @def_cflags_fortify);
694 @cxxflags = (@cxxflags, @def_cflags_fortify);
695 @cppflags = (@cppflags, @def_cppflags_fortify);
697 if ($harden_format) {
698 @cflags = (@cflags, @def_cflags_format);
699 @cxxflags = (@cxxflags, @def_cflags_format);
702 @ldflags = (@ldflags, @def_ldflags_relro);
704 if ($harden_bindnow) {
705 @ldflags = (@ldflags, @def_ldflags_bindnow);
708 for (my $i = 0; $i < scalar @input; $i++) {
709 my $line = $input[$i];
712 if (is_non_verbose_build($line, $input[$i + 1], \$skip)) {
713 if (not $option_buildd) {
714 error_non_verbose_build($line);
716 $statistics{commands_nonverbose}++;
718 $exit |= $exit_code{non_verbose_build};
721 # Even if it's a verbose build, we might have to skip this line.
724 # Remove everything until and including the compiler command. Makes
725 # checks easier and faster.
726 $line =~ s/^.*?$cc_regex//o;
727 # "([...] test.c)" is not detected as 'test.c' - fix this by removing
728 # the brace and similar characters.
729 $line =~ s/['")]+$//;
731 # Skip unnecessary tests when only preprocessing.
732 my $flag_preprocess = 0;
738 # Preprocess, compile, assemble.
739 if ($line =~ /\s(-E|-S|-c)\b/) {
741 $flag_preprocess = 1 if $1 eq '-E';
742 $compile = 1 if $1 eq '-S' or $1 eq '-c';
743 # Otherwise assume we are linking.
748 # Get all file extensions on this line.
749 my @extensions = $line =~ /$file_extension_regex/go;
750 # Ignore all unknown extensions to speedup the search below.
751 @extensions = grep { exists $extension{$_} } @extensions;
753 # These file types don't require preprocessing.
754 if (extension_found(\%extensions_no_preprocess, @extensions)) {
757 # These file types require preprocessing.
758 if (extension_found(\%extensions_preprocess, @extensions)) {
762 # If there are source files then it's compiling/linking in one step
763 # and we must check both. We only check for source files here, because
764 # header files cause too many false positives.
765 if (not $flag_preprocess
766 and extension_found(\%extensions_compile_link, @extensions)) {
767 # Assembly files don't need CFLAGS.
768 if (not extension_found(\%extensions_compile, @extensions)
769 and extension_found(\%extensions_no_compile, @extensions)) {
777 # Assume CXXFLAGS are required when a C++ file is specified in the
781 and extension_found(\%extensions_compile_cpp, @extensions)) {
786 if ($option_buildd) {
787 $statistics{preprocess}++ if $preprocess;
788 $statistics{compile}++ if $compile;
789 $statistics{compile_cpp}++ if $compile_cpp;
790 $statistics{link}++ if $link;
793 # Check hardening flags.
795 if ($compile and not all_flags_used($line, \@missing, @cflags)
796 # Libraries linked with -fPIC don't have to (and can't) be
797 # linked with -fPIE as well. It's no error if only PIE flags
799 and not pic_pie_conflict($line, $harden_pie, \@missing, @def_cflags_pie)
800 # Assume dpkg-buildflags returns the correct flags.
801 and not $line =~ /`dpkg-buildflags --get CFLAGS`/) {
802 if (not $option_buildd) {
803 error_flags('CFLAGS missing', \@missing, \%flag_renames, $input[$i]);
805 $statistics{compile_missing}++;
807 $exit |= $exit_code{flags_missing};
808 } elsif ($compile_cpp and not all_flags_used($line, \@missing, @cflags)
809 # Libraries linked with -fPIC don't have to (and can't) be
810 # linked with -fPIE as well. It's no error if only PIE flags
812 and not pic_pie_conflict($line, $harden_pie, \@missing, @def_cflags_pie)
813 # Assume dpkg-buildflags returns the correct flags.
814 and not $line =~ /`dpkg-buildflags --get CXXFLAGS`/) {
815 if (not $option_buildd) {
816 error_flags('CXXFLAGS missing', \@missing, \%flag_renames, $input[$i]);
818 $statistics{compile_cpp_missing}++;
820 $exit |= $exit_code{flags_missing};
822 if ($preprocess and not all_flags_used($line, \@missing, @cppflags)
823 # Assume dpkg-buildflags returns the correct flags.
824 and not $line =~ /`dpkg-buildflags --get CPPFLAGS`/) {
825 if (not $option_buildd) {
826 error_flags('CPPFLAGS missing', \@missing, \%flag_renames, $input[$i]);
828 $statistics{preprocess_missing}++;
830 $exit |= $exit_code{flags_missing};
832 if ($link and not all_flags_used($line, \@missing, @ldflags)
833 # Same here, -fPIC conflicts with -fPIE.
834 and not pic_pie_conflict($line, $harden_pie, \@missing, @def_ldflags_pie)
835 # Assume dpkg-buildflags returns the correct flags.
836 and not $line =~ /`dpkg-buildflags --get LDFLAGS`/) {
837 if (not $option_buildd) {
838 error_flags('LDFLAGS missing', \@missing, \%flag_renames, $input[$i]);
840 $statistics{link_missing}++;
842 $exit |= $exit_code{flags_missing};
847 # Print statistics for buildd mode, only output in this mode.
848 if ($option_buildd) {
851 if ($statistics{preprocess_missing}) {
852 push @warning, sprintf "CPPFLAGS %d (of %d)",
853 $statistics{preprocess_missing},
854 $statistics{preprocess};
856 if ($statistics{compile_missing}) {
857 push @warning, sprintf "CFLAGS %d (of %d)",
858 $statistics{compile_missing},
859 $statistics{compile};
861 if ($statistics{compile_cpp_missing}) {
862 push @warning, sprintf "CXXFLAGS %d (of %d)",
863 $statistics{compile_cpp_missing},
864 $statistics{compile_cpp};
866 if ($statistics{link_missing}) {
867 push @warning, sprintf "LDFLAGS %d (of %d)",
868 $statistics{link_missing},
871 if (scalar @warning) {
872 local $" = ', '; # array join string
873 print "W-dpkg-buildflags-missing @warning missing\n";
876 if ($statistics{commands_nonverbose}) {
877 printf "W-compiler-flags-hidden %d (of %d) hidden\n",
878 $statistics{commands_nonverbose},
879 $statistics{commands},
891 blhc - build log hardening check, checks build logs for missing hardening flags
895 B<blhc> [I<options>] I<E<lt>dpkg-buildpackage build log fileE<gt>..>
899 blhc is a small tool which checks build logs for missing hardening flags and
900 other important warnings. It's licensed under the GPL 3 or later.
908 Force check for all +all (+pie, +bindnow) hardening flags. By default it's
911 =item B<--arch> I<architecture>
913 Set the specific architecture (e.g. amd64, armel, etc.), automatically
914 disables hardening flags not available on this architecture. Is detected
915 automatically if dpkg-buildpackage is used.
919 Force check for all +bindnow hardening flags. By default it's auto detected.
923 Special mode for buildds when automatically parsing log files. The following
924 changes are in effect:
930 Don't check hardening flags in old log files (if dpkg-dev << 1.16.1 is
937 Use colored (ANSI) output for warning messages.
941 Force check for all +pie hardening flags. By default it's auto detected.
943 =item B<-h -? --help>
945 Print available options.
949 Print version number and license.
953 Auto detection for B<--pie> and B<--bindnow> only works if at least one
954 command uses the required hardening flag (e.g. -fPIE). Then it's required for
955 all other commands as well.
959 The exit status is a "bit mask", each listed status is ORed when the error
960 condition occurs to get the result.
970 No compiler commands were found.
974 Invalid arguments/options given to blhc.
982 Missing hardening flags.
986 Hardening wrapper detected, no tests performed.
992 Simon Ruderich, E<lt>simon@ruderich.orgE<gt>
994 =head1 COPYRIGHT AND LICENSE
996 Copyright (C) 2012 by Simon Ruderich
998 This program is free software: you can redistribute it and/or modify
999 it under the terms of the GNU General Public License as published by
1000 the Free Software Foundation, either version 3 of the License, or
1001 (at your option) any later version.
1003 This program is distributed in the hope that it will be useful,
1004 but WITHOUT ANY WARRANTY; without even the implied warranty of
1005 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1006 GNU General Public License for more details.
1008 You should have received a copy of the GNU General Public License
1009 along with this program. If not, see <http://www.gnu.org/licenses/>.