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 Text::ParseWords ();
27 our $VERSION = '0.01';
32 # Regex to catch compiler commands.
34 (?<!\.)(?:cc|gcc|g\+\+|c\+\+)
37 # Full regex which matches the complete compiler name. Used in a few places to
38 # prevent false negatives.
39 my $cc_regex_full = qr/
40 (?:[a-z0-9_]+-(?:linux-|kfreebsd-)?gnu(?:eabi|eabihf)?-)?
43 # Regex to catch (GCC) compiler warnings.
44 my $warning_regex = qr/^(.+?):([0-9]+):[0-9]+: warning: (.+?) \[(.+?)\]$/;
46 # List of source file extensions which require preprocessing.
47 my @source_preprocess_compile_cpp = (
49 qw( cc cp cxx cpp CPP c++ C ),
53 my @source_preprocess_compile = (
59 @source_preprocess_compile_cpp,
61 qw( F FOR fpp FPP FTN F90 F95 F03 F08 ),
63 my @source_preprocess_no_compile = (
67 my @source_preprocess = (
68 @source_preprocess_compile,
69 @source_preprocess_no_compile,
71 # List of source file extensions which don't require preprocessing.
72 my @source_no_preprocess_compile_cpp = (
78 my @source_no_preprocess_compile = (
82 @source_no_preprocess_compile_cpp,
86 qw( f for ftn f90 f95 f03 f08 ),
88 my @source_no_preprocess_no_compile = (
92 my @source_no_preprocess = (
93 @source_no_preprocess_compile,
94 @source_no_preprocess_no_compile,
96 # List of header file extensions which require preprocessing.
97 my @header_preprocess = (
98 # C, C++, Objective-C, Objective-C++
101 qw( hh H hp hxx hpp HPP h++ tcc ),
104 # Hashes for fast extensions lookup to check if a file falls in one of these
106 my %extensions_no_preprocess = map { $_ => 1 } (
107 @source_no_preprocess,
109 my %extensions_preprocess = map { $_ => 1 } (
113 my %extensions_compile_link = map { $_ => 1 } (
115 @source_no_preprocess,
117 my %extensions_compile = map { $_ => 1 } (
118 @source_preprocess_compile,
119 @source_no_preprocess_compile,
121 my %extensions_no_compile = map { $_ => 1 } (
122 @source_preprocess_no_compile,
123 @source_no_preprocess_no_compile,
125 my %extensions_compile_cpp = map { $_ => 1 } (
126 @source_preprocess_compile_cpp,
127 @source_no_preprocess_compile_cpp,
129 my %extension = map { $_ => 1 } (
130 @source_no_preprocess,
135 # Regexp to match file extensions.
136 my $file_extension_regex = qr/
138 \S+ # Filename without extension.
140 ([^\/\\.,;:\s]+)# File extension.
141 (?=\s|\\) # At end of word. Can't use \b because some files have non
142 # word characters at the end and because \b matches double
143 # extensions (like .cpp.o). Works always as all lines are
144 # terminated with "\n".
147 # Expected (hardening) flags. All flags are used as regexps.
152 my @def_cflags_format = (
155 '-Werror=format-security',
157 my @def_cflags_fortify = (
158 # fortify needs at least -O1, but -O2 is recommended anyway
160 my @def_cflags_stack = (
162 '--param=ssp-buffer-size=4',
164 my @def_cflags_pie = (
170 # @def_cxxflags_* is the same as @def_cflags_*.
171 my @def_cppflags = ();
172 my @def_cppflags_fortify = (
173 '-D_FORTIFY_SOURCE=2',
175 my @def_ldflags = ();
176 my @def_ldflags_relro = (
179 my @def_ldflags_bindnow = (
182 my @def_ldflags_pie = (
186 my @def_ldflags_pic = (
191 # References to all flags checked by the parser.
195 \@def_cflags_fortify,
200 \@def_cppflags_fortify,
203 \@def_ldflags_bindnow,
205 # References to all used flags.
206 my @flag_refs_all = (
211 # Renaming rules for the output so the regex parts are not visible. Also
212 # stores string values of flag regexps above, see compile_flag_regexp().
214 '-O(?:2|3)' => '-O2',
215 '-Wl,(?:-z,)?relro' => '-Wl,-z,relro',
216 '-Wl,(?:-z,)?now' => '-Wl,-z,now',
220 no_compiler_commands => 1 << 0,
221 # used by POD::Usage => 1 << 1,
222 non_verbose_build => 1 << 2,
223 flags_missing => 1 << 3,
224 hardening_wrapper => 1 << 4,
225 invalid_cmake => 1 << 5,
228 # Statistics of missing flags and non-verbose build commands. Used for
232 preprocess_missing => 0,
234 compile_missing => 0,
236 compile_cpp_missing => 0,
240 commands_nonverbose => 0,
243 # Use colored (ANSI) output?
250 my ($message, $missing_flags_ref, $flag_renames_ref, $line) = @_;
252 # Get string value of qr//-escaped regexps and if requested rename them.
253 my @missing_flags = map {
254 $flag_renames_ref->{$_}
255 } @{$missing_flags_ref};
257 my $flags = join ' ', @missing_flags;
258 printf "%s (%s)%s %s",
259 error_color($message, 'red'), $flags, error_color(':', 'yellow'),
262 sub error_non_verbose_build {
266 error_color('NONVERBOSE BUILD', 'red'),
267 error_color(':', 'yellow'),
270 sub error_invalid_cmake {
274 error_color('INVALID CMAKE', 'red'),
275 error_color(':', 'yellow'),
278 sub error_hardening_wrapper {
280 error_color('HARDENING WRAPPER', 'red'),
281 error_color(':', 'yellow'),
282 'no checks possible, aborting';
285 my ($message, $color) = @_;
288 return Term::ANSIColor::colored($message, $color);
295 my ($line, @flags) = @_;
297 foreach my $flag (@flags) {
298 return 1 if $line =~ /$flag/;
304 my ($line, $missing_flags_ref, @flags) = @_;
306 my @missing_flags = ();
307 foreach my $flag (@flags) {
308 if (not $line =~ /$flag/) {
309 push @missing_flags, $flag;
313 return 1 if scalar @missing_flags == 0;
315 @{$missing_flags_ref} = @missing_flags;
319 # Modifies $missing_flags_ref array.
320 sub pic_pie_conflict {
321 my ($line, $pie, $missing_flags_ref, @flags_pie) = @_;
323 return 0 if not $pie;
324 return 0 if not any_flags_used($line, @def_ldflags_pic);
326 my %flags = map { $_ => 1 } @flags_pie;
328 # Remove all PIE flags from @missing_flags as they are not required with
331 not exists $flags{$_}
332 } @{$missing_flags_ref};
333 @{$missing_flags_ref} = @result;
335 # We got a conflict when no flags are left, thus only PIE flags were
336 # missing. If other flags were missing abort because the conflict is not
338 return scalar @result == 0;
341 sub is_non_verbose_build {
342 my ($line, $next_line, $skip_ref) = @_;
344 if (not ($line =~ /^checking if you want to see long compiling messages\.\.\. no/
345 or $line =~ /^\s*\[?(?:CC|CCLD|C\+\+|CXX|CXXLD|LD|LINK)\]?\s+(.+?)$/
346 or $line =~ /^\s*(?:C|c)ompiling\s+(.+?)(?:\.\.\.)?$/
347 or $line =~ /^\s*(?:B|b)uilding (?:program|shared library)\s+(.+?)$/
348 or $line =~ /^\s*\[[\d ]+%\] Building (?:C|CXX) object (.+?)$/)) {
354 # C++ compiler setting.
355 return 0 if $line =~ /^\s*C\+\+.+?:\s+(?:yes|no)\s*$/;
356 # "Compiling" with no file name.
357 if ($line =~ /^\s*(?:C|c)ompiling\s+(.+?)(?:\.\.\.)?$/) {
358 # $file_extension_regex may need spaces around the filename.
359 return 0 if not " $1 " =~ /$file_extension_regex/o;
364 # On the first pass we only check if this line is verbose or not.
365 return 1 if not defined $next_line;
367 # Second pass, we have access to the next line.
370 # CMake and other build systems print the non-verbose messages also when
371 # building verbose. If a compiler and the file name occurs in the next
372 # line, treat it as verbose build.
374 # Get filename, we can't use the complete path as only parts of it are
375 # used in the real compiler command.
376 $file =~ m{/([^/\s]+)$};
379 if ($next_line =~ /\Q$file\E/ and $next_line =~ /$cc_regex/o) {
380 # We still have to skip the current line as it doesn't contain any
390 sub compile_flag_regexp {
391 my ($flag_renames_ref, @flags) = @_;
394 foreach my $flag (@flags) {
395 # Store flag name in replacement string for correct flags in messages
396 # with qr//ed flag regexps.
397 $flag_renames_ref->{qr/\s$flag(?:\s|\\)/}
398 = (exists $flag_renames_ref->{$flag})
399 ? $flag_renames_ref->{$flag}
402 # Compile flag regexp for faster execution.
403 push @result, qr/\s$flag(?:\s|\\)/;
408 sub extension_found {
409 my ($extensions_ref, @extensions) = @_;
412 foreach my $extension (@extensions) {
413 if (exists $extensions_ref->{$extension}) {
424 # Parse command line arguments.
426 my $option_version = 0;
428 my $option_bindnow = 0;
430 my $option_arch = undef;
431 my $option_buildd = 0;
433 if (not Getopt::Long::GetOptions(
434 'help|h|?' => \$option_help,
435 'version' => \$option_version,
437 'pie' => \$option_pie,
438 'bindnow' => \$option_bindnow,
439 'all' => \$option_all,
441 'color' => \$option_color,
442 'arch=s' => \$option_arch,
443 'buildd' => \$option_buildd,
445 or scalar @ARGV == 0) {
447 Pod::Usage::pod2usage(2);
451 Pod::Usage::pod2usage(1);
453 if ($option_version) {
454 print "blhc $VERSION Copyright (C) 2012 Simon Ruderich
456 This program is free software: you can redistribute it and/or modify
457 it under the terms of the GNU General Public License as published by
458 the Free Software Foundation, either version 3 of the License, or
459 (at your option) any later version.
461 This program is distributed in the hope that it will be useful,
462 but WITHOUT ANY WARRANTY; without even the implied warranty of
463 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
464 GNU General Public License for more details.
466 You should have received a copy of the GNU General Public License
467 along with this program. If not, see <http://www.gnu.org/licenses/>.
472 # Don't load Term::ANSIColor in buildd mode because Term::ANSIColor is not
473 # installed on Debian's buildds.
474 if (not $option_buildd) {
475 require Term::ANSIColor;
483 # Precompile all flag regexps. any_flags_used(), all_flags_used() get a lot
485 foreach my $flags (@flag_refs_all) {
486 @{$flags} = compile_flag_regexp(\%flag_renames, @{$flags});
492 FILE: foreach my $file (@ARGV) {
493 print "checking '$file'...\n" if scalar @ARGV > 1;
495 open my $fh, '<', $file or die "$!: $file";
497 # Architecture of this file.
498 my $arch = $option_arch;
500 # Hardening options. Not all architectures support all hardening options.
501 my $harden_format = 1;
502 my $harden_fortify = 1;
503 my $harden_stack = 1;
504 my $harden_relro = 1;
505 my $harden_bindnow = $option_bindnow; # defaults to 0
506 my $harden_pie = $option_pie; # defaults to 0
508 while (my $line = <$fh>) {
509 # dpkg-buildflags only provides hardening flags since 1.16.1, don't
510 # check for hardening flags in buildd mode if an older dpkg-dev is
511 # used. Default flags (-g -O2) are still checked.
513 # Packages which were built before 1.16.1 but used their own hardening
514 # flags are not checked.
515 if ($option_buildd and $line =~ /^Toolchain package versions: /) {
516 require Dpkg::Version;
517 if ($line !~ /\bdpkg-dev_(\S+)/
518 or Dpkg::Version::version_compare($1, '1.16.1') < 0) {
528 # The following two versions of CMake in Debian obeyed CPPFLAGS, but
529 # this was later dropped because upstream rejected the patch. Thus
530 # build logs with these versions will have fortify hardening flags
531 # enabled, even though they may be not correctly set and are missing
532 # when build with later CMake versions. Thanks to Aron Xu for letting
534 if ($line =~ /^Package versions: /
535 and $line =~ /\bcmake_(\S+)/
536 and ($1 eq '2.8.7-1' or $1 eq '2.8.7-2')) {
537 if (not $option_buildd) {
538 error_invalid_cmake($1);
540 print "W-invalid-cmake-used $1\n";
542 $exit |= $exit_code{invalid_cmake};
545 # If hardening wrapper is used (wraps calls to gcc and adds hardening
546 # flags automatically) we can't perform any checks, abort.
547 if ($line =~ /^Build-Depends: .*\bhardening-wrapper\b/) {
548 if (not $option_buildd) {
549 error_hardening_wrapper();
551 print "I-hardening-wrapper-used\n";
553 $exit |= $exit_code{hardening_wrapper};
557 # We skip over unimportant lines at the beginning of the log to
558 # prevent false positives.
559 last if $line =~ /^dpkg-buildpackage:/;
562 # Input lines, contain only the lines with compiler commands.
565 my $continuation = 0;
566 my $complete_line = undef;
567 while (my $line = <$fh>) {
568 # And stop at the end of the build log. Package details (reported by
569 # the buildd logs) are not important for us. This also prevents false
571 last if $line =~ /^Build finished at \d{8}-\d{4}$/;
573 # Detect architecture automatically unless overridden.
575 and $line =~ /^dpkg-buildpackage: host architecture (.+)$/) {
579 # Ignore compiler warnings for now.
580 next if $line =~ /$warning_regex/o;
582 if (not $option_buildd and $line =~ /\033/) { # esc
583 # Remove all ANSI color sequences which are sometimes used in
584 # non-verbose builds.
585 $line = Term::ANSIColor::colorstrip($line);
586 # Also strip '\0xf' (delete previous character), used by Elinks'
589 # And "ESC(B" which seems to be used on armhf and hurd (not sure
591 $line =~ s/\033\(B//g;
594 # Check if this line indicates a non verbose build.
595 my $non_verbose = is_non_verbose_build($line);
597 # One line may contain multiple commands (";"). Treat each one as
598 # single line. parse_line() is slow, only use it when necessary.
599 my @line = (not $line =~ /;/)
602 # Ensure newline at the line end - necessary for
603 # correct parsing later.
606 } Text::ParseWords::parse_line(';', 1, $line);
607 foreach $line (@line) {
611 # Join lines, but leave the "\" in place so it's clear where
612 # the original line break was.
613 chomp $complete_line;
614 $complete_line .= ' ' . $line;
616 # Line continuation, line ends with "\".
617 if ($line =~ /\\\s*$/) {
619 # Start line continuation.
620 if (not defined $complete_line) {
621 $complete_line = $line;
626 if (not $continuation) {
627 # Use the complete line if a line continuation occurred.
628 if (defined $complete_line) {
629 $line = $complete_line;
630 $complete_line = undef;
633 # Ignore lines with no compiler commands.
634 next if not $non_verbose
635 and not $line =~ /\b$cc_regex(?:\s|\\)/o;
636 # Ignore lines with no filenames with extensions. May miss
637 # some non-verbose builds (e.g. "gcc -o test" [sic!]), but
638 # shouldn't be a problem as the log will most likely contain
639 # other non-verbose commands which are detected.
640 next if not $non_verbose
641 and not $line =~ /$file_extension_regex/o;
643 # Ignore false positives.
645 # `./configure` output.
646 next if not $non_verbose
647 and $line =~ /^(?:checking|(?:C|c)onfigure:) /;
648 next if $line =~ /^\s*(?:Host\s+)?(?:C(?:\+\+)?\s+)?
649 (?:C|c)ompiler[\s.]*:?\s+
651 next if $line =~ /^\s*(?:- )?(?:HOST_)?(?:CC|CXX)\s*=\s*$cc_regex_full\s*$/o;
653 # Check if additional hardening options were used. Used to
654 # ensure they are used for the complete build.
655 $harden_pie = 1 if any_flags_used($line, @def_cflags_pie, @def_ldflags_pie);
656 $harden_bindnow = 1 if any_flags_used($line, @def_ldflags_bindnow);
665 if (scalar @input == 0) {
666 if (not $option_buildd) {
667 print "No compiler commands!\n";
669 print "W-no-compiler-commands\n";
671 $exit |= $exit_code{no_compiler_commands};
675 if ($option_buildd) {
676 $statistics{commands} += scalar @input;
679 # Option or auto detected.
681 # The following was partially copied from dpkg-dev 1.16.1.2
682 # (/usr/share/perl5/Dpkg/Vendor/Debian.pm, add_hardening_flags()),
683 # copyright Raphaël Hertzog <hertzog@debian.org>, Kees Cook
684 # <kees@debian.org>, Canonical, Ltd. licensed under GPL version 2 or
685 # later. Keep it in sync.
688 my ($abi, $os, $cpu) = Dpkg::Arch::debarch_to_debtriplet($arch);
690 # Disable unsupported hardening options.
691 if ($cpu =~ /^(ia64|alpha|mips|mipsel|hppa)$/ or $arch eq 'arm') {
694 if ($cpu =~ /^(ia64|hppa|avr32)$/) {
701 my @cflags = @def_cflags;
702 my @cxxflags = @def_cxxflags;
703 my @cppflags = @def_cppflags;
704 my @ldflags = @def_ldflags;
705 # Check the specified hardening options, same order as dpkg-buildflags.
707 @cflags = (@cflags, @def_cflags_pie);
708 @cxxflags = (@cxxflags, @def_cflags_pie);
709 @ldflags = (@ldflags, @def_ldflags_pie);
712 @cflags = (@cflags, @def_cflags_stack);
713 @cxxflags = (@cxxflags, @def_cflags_stack);
715 if ($harden_fortify) {
716 @cflags = (@cflags, @def_cflags_fortify);
717 @cxxflags = (@cxxflags, @def_cflags_fortify);
718 @cppflags = (@cppflags, @def_cppflags_fortify);
720 if ($harden_format) {
721 @cflags = (@cflags, @def_cflags_format);
722 @cxxflags = (@cxxflags, @def_cflags_format);
725 @ldflags = (@ldflags, @def_ldflags_relro);
727 if ($harden_bindnow) {
728 @ldflags = (@ldflags, @def_ldflags_bindnow);
731 for (my $i = 0; $i < scalar @input; $i++) {
732 my $line = $input[$i];
735 if (is_non_verbose_build($line, $input[$i + 1], \$skip)) {
736 if (not $option_buildd) {
737 error_non_verbose_build($line);
739 $statistics{commands_nonverbose}++;
741 $exit |= $exit_code{non_verbose_build};
744 # Even if it's a verbose build, we might have to skip this line.
747 # Remove everything until and including the compiler command. Makes
748 # checks easier and faster.
749 $line =~ s/^.*?$cc_regex//o;
750 # "([...] test.c)" is not detected as 'test.c' - fix this by removing
751 # the brace and similar characters.
752 $line =~ s/['")]+$//;
754 # Skip unnecessary tests when only preprocessing.
755 my $flag_preprocess = 0;
762 # Preprocess, compile, assemble.
763 if ($line =~ /\s(-E|-S|-c)\b/) {
765 $flag_preprocess = 1 if $1 eq '-E';
766 $compile = 1 if $1 eq '-S' or $1 eq '-c';
767 # Dependency generation for Makefiles. The other flags (-MF -MG -MP
768 # -MT -MQ) are always used with -M/-MM.
769 } elsif ($line =~ /\s(?:-M|-MM)\b/) {
771 # Otherwise assume we are linking.
776 # -MD/-MMD also cause dependency generation, but they don't imply -E!
777 if ($line =~ /\s(?:-MD|-MMD)\b/) {
779 $flag_preprocess = 0;
782 # Dependency generation for Makefiles, no preprocessing or other flags
786 # Get all file extensions on this line.
787 my @extensions = $line =~ /$file_extension_regex/go;
788 # Ignore all unknown extensions to speedup the search below.
789 @extensions = grep { exists $extension{$_} } @extensions;
791 # These file types don't require preprocessing.
792 if (extension_found(\%extensions_no_preprocess, @extensions)) {
795 # These file types require preprocessing.
796 if (extension_found(\%extensions_preprocess, @extensions)) {
800 # If there are source files then it's compiling/linking in one step
801 # and we must check both. We only check for source files here, because
802 # header files cause too many false positives.
803 if (not $flag_preprocess
804 and extension_found(\%extensions_compile_link, @extensions)) {
805 # Assembly files don't need CFLAGS.
806 if (not extension_found(\%extensions_compile, @extensions)
807 and extension_found(\%extensions_no_compile, @extensions)) {
815 # Assume CXXFLAGS are required when a C++ file is specified in the
819 and extension_found(\%extensions_compile_cpp, @extensions)) {
824 if ($option_buildd) {
825 $statistics{preprocess}++ if $preprocess;
826 $statistics{compile}++ if $compile;
827 $statistics{compile_cpp}++ if $compile_cpp;
828 $statistics{link}++ if $link;
831 # Check hardening flags.
833 if ($compile and not all_flags_used($line, \@missing, @cflags)
834 # Libraries linked with -fPIC don't have to (and can't) be
835 # linked with -fPIE as well. It's no error if only PIE flags
837 and not pic_pie_conflict($line, $harden_pie, \@missing, @def_cflags_pie)
838 # Assume dpkg-buildflags returns the correct flags.
839 and not $line =~ /`dpkg-buildflags --get CFLAGS`/) {
840 if (not $option_buildd) {
841 error_flags('CFLAGS missing', \@missing, \%flag_renames, $input[$i]);
843 $statistics{compile_missing}++;
845 $exit |= $exit_code{flags_missing};
846 } elsif ($compile_cpp and not all_flags_used($line, \@missing, @cflags)
847 # Libraries linked with -fPIC don't have to (and can't) be
848 # linked with -fPIE as well. It's no error if only PIE flags
850 and not pic_pie_conflict($line, $harden_pie, \@missing, @def_cflags_pie)
851 # Assume dpkg-buildflags returns the correct flags.
852 and not $line =~ /`dpkg-buildflags --get CXXFLAGS`/) {
853 if (not $option_buildd) {
854 error_flags('CXXFLAGS missing', \@missing, \%flag_renames, $input[$i]);
856 $statistics{compile_cpp_missing}++;
858 $exit |= $exit_code{flags_missing};
860 if ($preprocess and not all_flags_used($line, \@missing, @cppflags)
861 # Assume dpkg-buildflags returns the correct flags.
862 and not $line =~ /`dpkg-buildflags --get CPPFLAGS`/) {
863 if (not $option_buildd) {
864 error_flags('CPPFLAGS missing', \@missing, \%flag_renames, $input[$i]);
866 $statistics{preprocess_missing}++;
868 $exit |= $exit_code{flags_missing};
870 if ($link and not all_flags_used($line, \@missing, @ldflags)
871 # Same here, -fPIC conflicts with -fPIE.
872 and not pic_pie_conflict($line, $harden_pie, \@missing, @def_ldflags_pie)
873 # Assume dpkg-buildflags returns the correct flags.
874 and not $line =~ /`dpkg-buildflags --get LDFLAGS`/) {
875 if (not $option_buildd) {
876 error_flags('LDFLAGS missing', \@missing, \%flag_renames, $input[$i]);
878 $statistics{link_missing}++;
880 $exit |= $exit_code{flags_missing};
885 # Print statistics for buildd mode, only output in this mode.
886 if ($option_buildd) {
889 if ($statistics{preprocess_missing}) {
890 push @warning, sprintf "CPPFLAGS %d (of %d)",
891 $statistics{preprocess_missing},
892 $statistics{preprocess};
894 if ($statistics{compile_missing}) {
895 push @warning, sprintf "CFLAGS %d (of %d)",
896 $statistics{compile_missing},
897 $statistics{compile};
899 if ($statistics{compile_cpp_missing}) {
900 push @warning, sprintf "CXXFLAGS %d (of %d)",
901 $statistics{compile_cpp_missing},
902 $statistics{compile_cpp};
904 if ($statistics{link_missing}) {
905 push @warning, sprintf "LDFLAGS %d (of %d)",
906 $statistics{link_missing},
909 if (scalar @warning) {
910 local $" = ', '; # array join string
911 print "W-dpkg-buildflags-missing @warning missing\n";
914 if ($statistics{commands_nonverbose}) {
915 printf "W-compiler-flags-hidden %d (of %d) hidden\n",
916 $statistics{commands_nonverbose},
917 $statistics{commands},
929 blhc - build log hardening check, checks build logs for missing hardening flags
933 B<blhc> [I<options>] I<E<lt>dpkg-buildpackage build log fileE<gt>..>
937 blhc is a small tool which checks build logs for missing hardening flags and
938 other important warnings. It's licensed under the GPL 3 or later.
946 Force check for all +all (+pie, +bindnow) hardening flags. By default it's
949 =item B<--arch> I<architecture>
951 Set the specific architecture (e.g. amd64, armel, etc.), automatically
952 disables hardening flags not available on this architecture. Is detected
953 automatically if dpkg-buildpackage is used.
957 Force check for all +bindnow hardening flags. By default it's auto detected.
961 Special mode for buildds when automatically parsing log files. The following
962 changes are in effect:
968 Print tags instead of normal warnings, see README file for a list of possible
973 Don't check hardening flags in old log files (if dpkg-dev << 1.16.1 is
978 Don't require Term::ANSIColor.
984 Use colored (ANSI) output for warning messages.
988 Force check for all +pie hardening flags. By default it's auto detected.
990 =item B<-h -? --help>
992 Print available options.
996 Print version number and license.
1000 Auto detection for B<--pie> and B<--bindnow> only works if at least one
1001 command uses the required hardening flag (e.g. -fPIE). Then it's required for
1002 all other commands as well.
1006 The exit status is a "bit mask", each listed status is ORed when the error
1007 condition occurs to get the result.
1017 No compiler commands were found.
1021 Invalid arguments/options given to blhc.
1029 Missing hardening flags.
1033 Hardening wrapper detected, no tests performed.
1039 Simon Ruderich, E<lt>simon@ruderich.orgE<gt>
1041 =head1 COPYRIGHT AND LICENSE
1043 Copyright (C) 2012 by Simon Ruderich
1045 This program is free software: you can redistribute it and/or modify
1046 it under the terms of the GNU General Public License as published by
1047 the Free Software Foundation, either version 3 of the License, or
1048 (at your option) any later version.
1050 This program is distributed in the hope that it will be useful,
1051 but WITHOUT ANY WARRANTY; without even the implied warranty of
1052 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1053 GNU General Public License for more details.
1055 You should have received a copy of the GNU General Public License
1056 along with this program. If not, see <http://www.gnu.org/licenses/>.