]> ruderich.org/simon Gitweb - blhc/blhc.git/blob - bin/blhc
Use index() in a few more places.
[blhc/blhc.git] / bin / blhc
1 #!/usr/bin/perl
2
3 # Build log hardening check, checks build logs for missing hardening flags.
4
5 # Copyright (C) 2012  Simon Ruderich
6 #
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.
11 #
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.
16 #
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/>.
19
20
21 use strict;
22 use warnings;
23
24 use Getopt::Long ();
25 use Text::ParseWords ();
26
27 our $VERSION = '0.03';
28
29
30 # CONSTANTS/VARIABLES
31
32 # Regex to catch compiler commands.
33 my $cc_regex = qr/
34     (?<!\s-)               # ignore options, e.g. "-c++" [sic!] (used by swig)
35     (?<!\.)                # ignore file names, e.g. "test.gcc"
36     (?:cc|gcc|g\+\+|c\+\+)
37     (?:-[\d.]+)?           # version suffix, e.g. "gcc-4.6"
38     /x;
39 # Full regex which matches the complete compiler name. Used in a few places to
40 # prevent false negatives.
41 my $cc_regex_full = qr/
42     (?:[a-z0-9_]+-(?:linux-|kfreebsd-)?gnu(?:eabi|eabihf)?-)?
43     $cc_regex
44     /x;
45 # Regex to check if a line contains a compiler command.
46 my $cc_regex_normal = qr/
47     \b$cc_regex(?:\s|\\)
48     /x;
49 # Regex to catch (GCC) compiler warnings.
50 my $warning_regex = qr/^(.+?):(\d+):\d+: warning: (.+?) \[(.+?)\]$/;
51
52 # List of source file extensions which require preprocessing.
53 my @source_preprocess_compile_cpp = (
54     # C++
55     qw( cc cp cxx cpp CPP c++ C ),
56     # Objective-C++
57     qw( mm M ),
58 );
59 my @source_preprocess_compile = (
60     # C
61     qw( c ),
62     # Objective-C
63     qw( m ),
64     # (Objective-)C++
65     @source_preprocess_compile_cpp,
66     # Fortran
67     qw( F FOR fpp FPP FTN F90 F95 F03 F08 ),
68 );
69 my @source_preprocess_no_compile = (
70     # Assembly
71     qw( S sx ),
72 );
73 my @source_preprocess = (
74     @source_preprocess_compile,
75     @source_preprocess_no_compile,
76 );
77 # List of source file extensions which don't require preprocessing.
78 my @source_no_preprocess_compile_cpp = (
79     # C++
80     qw( ii ),
81     # Objective-C++
82     qw( mii ),
83 );
84 my @source_no_preprocess_compile = (
85     # C
86     qw( i ),
87     # (Objective-)C++
88     @source_no_preprocess_compile_cpp,
89     # Objective-C
90     qw( mi ),
91     # Fortran
92     qw( f for ftn f90 f95 f03 f08 ),
93 );
94 my @source_no_preprocess_no_compile = (
95     # Assembly
96     qw( s ),
97 );
98 my @source_no_preprocess = (
99     @source_no_preprocess_compile,
100     @source_no_preprocess_no_compile,
101 );
102 # List of header file extensions which require preprocessing.
103 my @header_preprocess = (
104     # C, C++, Objective-C, Objective-C++
105     qw( h ),
106     # C++
107     qw( hh H hp hxx hpp HPP h++ tcc ),
108 );
109 # Object files.
110 my @object = (
111     # Normal object files.
112     qw ( o ),
113     # Libtool object files.
114     qw ( lo la ),
115     # Dynamic libraries. bzip2 uses .sho.
116     qw ( so sho ),
117     # Static libraries.
118     qw ( a ),
119 );
120
121 # Hashes for fast extensions lookup to check if a file falls in one of these
122 # categories.
123 my %extensions_no_preprocess = map { $_ => 1 } (
124     # There's no @header_no_preprocess.
125     @source_no_preprocess,
126 );
127 my %extensions_preprocess = map { $_ => 1 } (
128     @header_preprocess,
129     @source_preprocess,
130 );
131 my %extensions_compile_link = map { $_ => 1 } (
132     @source_preprocess,
133     @source_no_preprocess,
134 );
135 my %extensions_compile = map { $_ => 1 } (
136     @source_preprocess_compile,
137     @source_no_preprocess_compile,
138 );
139 my %extensions_no_compile = map { $_ => 1 } (
140     @source_preprocess_no_compile,
141     @source_no_preprocess_no_compile,
142 );
143 my %extensions_compile_cpp = map { $_ => 1 } (
144     @source_preprocess_compile_cpp,
145     @source_no_preprocess_compile_cpp,
146 );
147 my %extensions_object = map { $_ => 1 } (
148     @object,
149 );
150 my %extension = map { $_ => 1 } (
151     @source_no_preprocess,
152     @header_preprocess,
153     @source_preprocess,
154     @object,
155 );
156
157 # Regexp to match file extensions.
158 my $file_extension_regex = qr/
159     \s
160     \S+             # Filename without extension.
161     \.
162     ([^\/\\.,;:\s]+)# File extension.
163     (?=\s|\\)       # At end of word. Can't use \b because some files have non
164                     # word characters at the end and because \b matches double
165                     # extensions (like .cpp.o). Works always as all lines are
166                     # terminated with "\n".
167     /x;
168
169 # Expected (hardening) flags. All flags are used as regexps.
170 my @def_cflags = (
171     '-g',
172     '-O(?:2|3)',
173 );
174 my @def_cflags_format = (
175     '-Wformat',
176     '-Werror=format-security', # implies -Wformat-security
177 );
178 my @def_cflags_fortify = (
179     # fortify needs at least -O1, but -O2 is recommended anyway
180 );
181 my @def_cflags_stack = (
182     '-fstack-protector',
183     '--param=ssp-buffer-size=4',
184 );
185 my @def_cflags_pie = (
186     '-fPIE',
187 );
188 my @def_cxxflags = (
189     @def_cflags,
190 );
191 # @def_cxxflags_* is the same as @def_cflags_*.
192 my @def_cppflags = ();
193 my @def_cppflags_fortify = (
194     '-D_FORTIFY_SOURCE=2', # must be first, see cppflags_fortify_broken()
195     # If you add another flag fix hack below (search for "Hack to fix").
196 );
197 my @def_cppflags_fortify_bad = (
198     # These flags may overwrite -D_FORTIFY_SOURCE=2.
199     '-U_FORTIFY_SOURCE',
200     '-D_FORTIFY_SOURCE=0',
201     '-D_FORTIFY_SOURCE=1',
202 );
203 my @def_ldflags = ();
204 my @def_ldflags_relro = (
205     '-Wl,(?:-z,)?relro',
206 );
207 my @def_ldflags_bindnow = (
208     '-Wl,(?:-z,)?now',
209 );
210 my @def_ldflags_pie = (
211     '-fPIE',
212     '-pie',
213 );
214 my @def_ldflags_pic = (
215     '-fPIC',
216     '-fpic',
217     '-shared',
218 );
219 # References to all flags checked by the flag checker.
220 my @flag_refs = (
221     \@def_cflags,
222     \@def_cflags_format,
223     \@def_cflags_fortify,
224     \@def_cflags_stack,
225     \@def_cflags_pie,
226     \@def_cxxflags,
227     \@def_cppflags,
228     \@def_cppflags_fortify,
229     \@def_ldflags,
230     \@def_ldflags_relro,
231     \@def_ldflags_bindnow,
232     \@def_ldflags_pie,
233 );
234 # References to all used flags.
235 my @flag_refs_all = (
236     @flag_refs,
237     \@def_cppflags_fortify_bad,
238     \@def_ldflags_pic,
239 );
240 # Renaming rules for the output so the regex parts are not visible. Also
241 # stores string values of flag regexps above, see compile_flag_regexp().
242 my %flag_renames = (
243     '-O(?:2|3)'         => '-O2',
244     '-Wl,(?:-z,)?relro' => '-Wl,-z,relro',
245     '-Wl,(?:-z,)?now'   => '-Wl,-z,now',
246 );
247
248 my %exit_code = (
249     no_compiler_commands => 1 << 0,
250     # used by POD::Usage => 1 << 1,
251     non_verbose_build    => 1 << 2,
252     flags_missing        => 1 << 3,
253     hardening_wrapper    => 1 << 4,
254     invalid_cmake        => 1 << 5,
255 );
256
257 my %buildd_tag = (
258     no_compiler_commands => 'I-no-compiler-commands',
259     non_verbose_build    => 'W-compiler-flags-hidden',
260     flags_missing        => 'W-dpkg-buildflags-missing',
261     hardening_wrapper    => 'I-hardening-wrapper-used',
262     invalid_cmake        => 'I-invalid-cmake-used',
263 );
264
265 # Statistics of missing flags and non-verbose build commands. Used for
266 # $option_buildd.
267 my %statistics = (
268     preprocess          => 0,
269     preprocess_missing  => 0,
270     compile             => 0,
271     compile_missing     => 0,
272     compile_cpp         => 0,
273     compile_cpp_missing => 0,
274     link                => 0,
275     link_missing        => 0,
276     commands            => 0,
277     commands_nonverbose => 0,
278 );
279
280 # Use colored (ANSI) output?
281 my $option_color;
282
283
284 # FUNCTIONS
285
286 sub error_flags {
287     my ($message, $missing_flags_ref, $flag_renames_ref, $line) = @_;
288
289     # Get string value of qr//-escaped regexps and if requested rename them.
290     my @missing_flags = map {
291             $flag_renames_ref->{$_}
292         } @{$missing_flags_ref};
293
294     my $flags = join ' ', @missing_flags;
295     printf '%s (%s)%s %s',
296            error_color($message, 'red'), $flags, error_color(':', 'yellow'),
297            $line;
298 }
299 sub error_non_verbose_build {
300     my ($line) = @_;
301
302     printf '%s%s %s',
303            error_color('NONVERBOSE BUILD', 'red'),
304            error_color(':', 'yellow'),
305            $line;
306 }
307 sub error_invalid_cmake {
308     my ($version) = @_;
309
310     printf "%s%s %s\n",
311             error_color('INVALID CMAKE', 'red'),
312             error_color(':', 'yellow'),
313             $version;
314 }
315 sub error_hardening_wrapper {
316     printf "%s%s %s\n",
317             error_color('HARDENING WRAPPER', 'red'),
318             error_color(':', 'yellow'),
319             'no checks possible, aborting';
320 }
321 sub error_color {
322     my ($message, $color) = @_;
323
324     if ($option_color) {
325         return Term::ANSIColor::colored($message, $color);
326     } else {
327         return $message;
328     }
329 }
330
331 sub any_flags_used {
332     my ($line, @flags) = @_;
333
334     foreach my $flag (@flags) {
335         return 1 if $line =~ /$flag/;
336     }
337
338     return 0;
339 }
340 sub all_flags_used {
341     my ($line, $missing_flags_ref, @flags) = @_;
342
343     my @missing_flags = ();
344     foreach my $flag (@flags) {
345         if (not $line =~ /$flag/) {
346             push @missing_flags, $flag;
347         }
348     }
349
350     return 1 if scalar @missing_flags == 0;
351
352     @{$missing_flags_ref} = @missing_flags;
353     return 0;
354 }
355
356 sub cppflags_fortify_broken {
357     my ($line, $missing_flags) = @_;
358
359     # This doesn't take the position into account, but is a simple solution.
360     # And if the build system tries to force -D_FORTIFY_SOURCE=0/1, something
361     # is wrong anyway.
362
363     if (any_flags_used($line, @def_cppflags_fortify_bad)) {
364         # $def_cppflags_fortify[0] must be -D_FORTIFY_SOURCE=2!
365         push @{$missing_flags}, $def_cppflags_fortify[0];
366         return 1;
367     }
368
369     return 0;
370 }
371
372 # Modifies $missing_flags_ref array.
373 sub pic_pie_conflict {
374     my ($line, $pie, $missing_flags_ref, @flags_pie) = @_;
375
376     return 0 if not $pie;
377     return 0 if not any_flags_used($line, @def_ldflags_pic);
378
379     my %flags = map { $_ => 1 } @flags_pie;
380
381     # Remove all PIE flags from @missing_flags as they are not required with
382     # -fPIC.
383     my @result = grep {
384         not exists $flags{$_}
385     } @{$missing_flags_ref};
386     @{$missing_flags_ref} = @result;
387
388     # We got a conflict when no flags are left, thus only PIE flags were
389     # missing. If other flags were missing abort because the conflict is not
390     # the problem.
391     return scalar @result == 0;
392 }
393
394 sub is_non_verbose_build {
395     my ($line, $next_line, $skip_ref) = @_;
396
397     if (not (index($line, 'checking if you want to see long compiling messages... no') == 0
398                 or $line =~ /^\s*\[?(?:CC|CCLD|C\+\+|CXX|CXXLD|LD|LINK)\]?\s+(.+?)$/
399                 or $line =~ /^\s*[Cc]ompiling\s+(.+?)(?:\.\.\.)?$/
400                 or $line =~ /^\s*[Bb]uilding (?:program|shared library)\s+(.+?)$/
401                 or $line =~ /^\s*\[[\d ]+%\] Building (?:C|CXX) object (.+?)$/)) {
402         return 0;
403     }
404
405     # False positives.
406     #
407     # C++ compiler setting.
408     return 0 if $line =~ /^\s*C\+\+.+?:\s+(?:yes|no)\s*$/;
409     # "Compiling" with no file name.
410     if ($line =~ /^\s*[Cc]ompiling\s+(.+?)(?:\.\.\.)?$/) {
411         # $file_extension_regex may need spaces around the filename.
412         return 0 if not " $1 " =~ /$file_extension_regex/o;
413     }
414
415     my $file = $1;
416
417     # On the first pass we only check if this line is verbose or not.
418     return 1 if not defined $next_line;
419
420     # Second pass, we have access to the next line.
421     ${$skip_ref} = 0;
422
423     # CMake and other build systems print the non-verbose messages also when
424     # building verbose. If a compiler and the file name occurs in the next
425     # line, treat it as verbose build.
426     if (defined $file) {
427         # Get filename, we can't use the complete path as only parts of it are
428         # used in the real compiler command.
429         $file =~ m{/([^/\s]+)$};
430         $file = $1;
431
432         if (index($next_line, $file) != -1 and $next_line =~ /$cc_regex/o) {
433             # We still have to skip the current line as it doesn't contain any
434             # compiler commands.
435             ${$skip_ref} = 1;
436             return 0;
437         }
438     }
439
440     return 1;
441 }
442
443 sub remove_flags {
444     my ($flag_refs_ref, $flag_renames_ref, @flags) = @_;
445
446     my %removes = map { $_ => 1 } @flags;
447     foreach my $flags (@{$flag_refs_ref}) {
448         @{$flags} = grep {
449             # Flag found as string.
450             not exists $removes{$_}
451             # Flag found as string representation of regexp.
452                 and (not defined $flag_renames_ref->{$_}
453                         or not exists $removes{$flag_renames_ref->{$_}})
454         } @{$flags};
455     }
456 }
457
458 sub compile_flag_regexp {
459     my ($flag_renames_ref, @flags) = @_;
460
461     my @result = ();
462     foreach my $flag (@flags) {
463         # Store flag name in replacement string for correct flags in messages
464         # with qr//ed flag regexps.
465         $flag_renames_ref->{qr/\s$flag(?:\s|\\)/}
466             = (exists $flag_renames_ref->{$flag})
467                 ? $flag_renames_ref->{$flag}
468                 : $flag;
469
470         # Compile flag regexp for faster execution.
471         push @result, qr/\s$flag(?:\s|\\)/;
472     }
473     return @result;
474 }
475
476 sub extension_found {
477     my ($extensions_ref, @extensions) = @_;
478
479     my $found = 0;
480     foreach my $extension (@extensions) {
481         if (exists $extensions_ref->{$extension}) {
482             $found = 1;
483             last;
484         }
485     }
486     return $found;
487 }
488
489
490 # MAIN
491
492 # Parse command line arguments.
493 my $option_help             = 0;
494 my $option_version          = 0;
495 my $option_pie              = 0;
496 my $option_bindnow          = 0;
497 my @option_ignore_arch      = ();
498 my @option_ignore_flag      = ();
499 my @option_ignore_arch_flag = ();
500 my @option_ignore_line      = ();
501 my @option_ignore_arch_line = ();
502 my $option_all              = 0;
503 my $option_arch             = undef;
504 my $option_buildd           = 0;
505    $option_color            = 0;
506 if (not Getopt::Long::GetOptions(
507             'help|h|?'           => \$option_help,
508             'version'            => \$option_version,
509             # Hardening options.
510             'pie'                => \$option_pie,
511             'bindnow'            => \$option_bindnow,
512             'all'                => \$option_all,
513             # Ignore.
514             'ignore-arch=s'      => \@option_ignore_arch,
515             'ignore-flag=s'      => \@option_ignore_flag,
516             'ignore-arch-flag=s' => \@option_ignore_arch_flag,
517             'ignore-line=s'      => \@option_ignore_line,
518             'ignore-arch-line=s' => \@option_ignore_arch_line,
519             # Misc.
520             'color'              => \$option_color,
521             'arch=s'             => \$option_arch,
522             'buildd'             => \$option_buildd,
523         )) {
524     require Pod::Usage;
525     Pod::Usage::pod2usage(2);
526 }
527 if ($option_help) {
528     require Pod::Usage;
529     Pod::Usage::pod2usage(1);
530 }
531 if ($option_version) {
532     print "blhc $VERSION  Copyright (C) 2012  Simon Ruderich
533
534 This program is free software: you can redistribute it and/or modify
535 it under the terms of the GNU General Public License as published by
536 the Free Software Foundation, either version 3 of the License, or
537 (at your option) any later version.
538
539 This program is distributed in the hope that it will be useful,
540 but WITHOUT ANY WARRANTY; without even the implied warranty of
541 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
542 GNU General Public License for more details.
543
544 You should have received a copy of the GNU General Public License
545 along with this program.  If not, see <http://www.gnu.org/licenses/>.
546 ";
547     exit 0;
548 }
549
550 # Arguments missing.
551 if (scalar @ARGV == 0) {
552     require Pod::Usage;
553     Pod::Usage::pod2usage(2);
554 }
555
556 # Don't load Term::ANSIColor in buildd mode because Term::ANSIColor is not
557 # installed on Debian's buildds.
558 if (not $option_buildd) {
559     require Term::ANSIColor;
560 }
561
562 if ($option_all) {
563     $option_pie     = 1;
564     $option_bindnow = 1;
565 }
566
567 # Precompiled ignores for faster lookup.
568 my %option_ignore_arch_flag = ();
569 my %option_ignore_arch_line = ();
570
571 # Strip flags which should be ignored.
572 if (scalar @option_ignore_flag > 0) {
573     remove_flags(\@flag_refs, \%flag_renames, @option_ignore_flag);
574 }
575 # Same for arch specific ignore flags, but only prepare here.
576 if (scalar @option_ignore_arch_flag > 0) {
577     foreach my $ignore (@option_ignore_arch_flag) {
578         my ($ignore_arch, $ignore_flag) = split /:/, $ignore, 2;
579
580         if (not $ignore_arch or not $ignore_flag) {
581             printf STDERR 'Value "%s" invalid for option ignore-arch-flag '
582                         . '("arch:flag" expected)' . "\n", $ignore;
583             require Pod::Usage;
584             Pod::Usage::pod2usage(2);
585         }
586
587         push @{$option_ignore_arch_flag{$ignore_arch}}, $ignore_flag;
588     }
589 }
590
591 # Precompile all flag regexps. any_flags_used(), all_flags_used() get a lot
592 # faster with this.
593 foreach my $flags (@flag_refs_all) {
594     @{$flags} = compile_flag_regexp(\%flag_renames, @{$flags});
595 }
596
597 # Precompile ignore line regexps, also anchor at beginning and end of line.
598 foreach my $ignore (@option_ignore_line) {
599     $ignore = qr/^$ignore$/;
600 }
601 # Same for arch specific ignore lines.
602 if (scalar @option_ignore_arch_line > 0) {
603     foreach my $ignore (@option_ignore_arch_line) {
604         my ($ignore_arch, $ignore_line) = split /:/, $ignore, 2;
605
606         if (not $ignore_arch or not $ignore_line) {
607             printf STDERR 'Value "%s" invalid for option ignore-arch-line '
608                         . '("arch:line" expected)' . "\n", $ignore;
609             require Pod::Usage;
610             Pod::Usage::pod2usage(2);
611         }
612
613         push @{$option_ignore_arch_line{$ignore_arch}}, qr/^$ignore_line$/;
614     }
615 }
616
617 # Final exit code.
618 my $exit = 0;
619
620 FILE:
621 foreach my $file (@ARGV) {
622     print "checking '$file'...\n" if scalar @ARGV > 1;
623
624     -f $file or die "No such file: $file";
625
626     open my $fh, '<', $file or die $!;
627
628     # Architecture of this file.
629     my $arch = $option_arch;
630
631     # Hardening options. Not all architectures support all hardening options.
632     my $harden_format  = 1;
633     my $harden_fortify = 1;
634     my $harden_stack   = 1;
635     my $harden_relro   = 1;
636     my $harden_bindnow = $option_bindnow; # defaults to 0
637     my $harden_pie     = $option_pie;     # defaults to 0
638
639     while (my $line = <$fh>) {
640         # Detect architecture automatically unless overridden. For buildd logs
641         # only, doesn't use the dpkg-buildpackage header. Necessary to ignore
642         # build logs which aren't built (wrong architecture, build error,
643         # etc.).
644         if (not $arch and index($line, 'Architecture: ') == 0) {
645             $arch = substr $line, 14, -1; # -1 to ignore '\n' at the end
646         }
647
648         # dpkg-buildflags only provides hardening flags since 1.16.1, don't
649         # check for hardening flags in buildd mode if an older dpkg-dev is
650         # used. Default flags (-g -O2) are still checked.
651         #
652         # Packages which were built before 1.16.1 but used their own hardening
653         # flags are not checked.
654         if ($option_buildd
655                 and index($line, 'Toolchain package versions: ') == 0) {
656             require Dpkg::Version;
657             if (not $line =~ /\bdpkg-dev_(\S+)/
658                     or Dpkg::Version::version_compare($1, '1.16.1') < 0) {
659                 $harden_format  = 0;
660                 $harden_fortify = 0;
661                 $harden_stack   = 0;
662                 $harden_relro   = 0;
663                 $harden_bindnow = 0;
664                 $harden_pie     = 0;
665             }
666         }
667
668         # The following two versions of CMake in Debian obeyed CPPFLAGS, but
669         # this was later dropped because upstream rejected the patch. Thus
670         # build logs with these versions will have fortify hardening flags
671         # enabled, even though they may be not correctly set and are missing
672         # when build with later CMake versions. Thanks to Aron Xu for letting
673         # me know.
674         if (index($line, 'Package versions: ') == 0
675                 and $line =~ /\bcmake_(\S+)/
676                 and ($1 eq '2.8.7-1' or $1 eq '2.8.7-2')) {
677             if (not $option_buildd) {
678                 error_invalid_cmake($1);
679                 $exit |= $exit_code{invalid_cmake};
680             } else {
681                 print "$buildd_tag{invalid_cmake}|$1|\n";
682             }
683         }
684
685         # If hardening wrapper is used (wraps calls to gcc and adds hardening
686         # flags automatically) we can't perform any checks, abort.
687         if (index($line, 'Build-Depends: ') == 0
688                 and $line =~ /\bhardening-wrapper\b/) {
689             if (not $option_buildd) {
690                 error_hardening_wrapper();
691                 $exit |= $exit_code{hardening_wrapper};
692             } else {
693                 print "$buildd_tag{hardening_wrapper}||\n";
694             }
695             next FILE;
696         }
697
698         # We skip over unimportant lines at the beginning of the log to
699         # prevent false positives.
700         last if index($line, 'dpkg-buildpackage: ') == 0;
701     }
702
703     # Input lines, contain only the lines with compiler commands.
704     my @input = ();
705     # Non-verbose lines in the input. Used to reduce calls to
706     # is_non_verbose_build() (which is quite slow) in the second loop when
707     # it's already clear if a line is non-verbose or not.
708     my @input_nonverbose = ();
709
710     my $continuation = 0;
711     my $complete_line = undef;
712     while (my $line = <$fh>) {
713         # And stop at the end of the build log. Package details (reported by
714         # the buildd logs) are not important for us. This also prevents false
715         # positives.
716         last if index($line, 'Build finished at ') == 0
717                 and $line =~ /^Build finished at \d{8}-\d{4}$/;
718
719         # Detect architecture automatically unless overridden.
720         if (not $arch
721                 and index($line, 'dpkg-buildpackage: host architecture ') == 0) {
722             $arch = substr $line, 37, -1; # -1 to ignore '\n' at the end
723         }
724
725         # Ignore compiler warnings for now.
726         next if $line =~ /$warning_regex/o;
727
728         if (not $option_buildd and index($line, "\033") != -1) { # \033 = esc
729             # Remove all ANSI color sequences which are sometimes used in
730             # non-verbose builds.
731             $line = Term::ANSIColor::colorstrip($line);
732             # Also strip '\0xf' (delete previous character), used by Elinks'
733             # build system.
734             $line =~ s/\x0f//g;
735             # And "ESC(B" which seems to be used on armhf and hurd (not sure
736             # what it does).
737             $line =~ s/\033\(B//g;
738         }
739
740         # Check if this line indicates a non verbose build.
741         my $non_verbose = is_non_verbose_build($line);
742
743         # One line may contain multiple commands (";"). Treat each one as
744         # single line. parse_line() is slow, only use it when necessary.
745         my @line = (index($line, ';') == -1)
746                  ? ($line)
747                  : map {
748                        # Ensure newline at the line end - necessary for
749                        # correct parsing later.
750                        $_ =~ s/\s+$//;
751                        $_ .= "\n";
752                    } Text::ParseWords::parse_line(';', 1, $line);
753         foreach my $line (@line) {
754             if ($continuation) {
755                 $continuation = 0;
756
757                 # Join lines, but leave the "\" in place so it's clear where
758                 # the original line break was.
759                 chomp $complete_line;
760                 $complete_line .= ' ' . $line;
761             }
762             # Line continuation, line ends with "\".
763             if ($line =~ /\\$/) {
764                 $continuation = 1;
765                 # Start line continuation.
766                 if (not defined $complete_line) {
767                     $complete_line = $line;
768                 }
769                 next;
770             }
771
772             # Use the complete line if a line continuation occurred.
773             if (defined $complete_line) {
774                 $line = $complete_line;
775                 $complete_line = undef;
776             }
777
778             # Ignore lines with no compiler commands.
779             next if not $non_verbose
780                     and not $line =~ /$cc_regex_normal/o;
781             # Ignore lines with no filenames with extensions. May miss some
782             # non-verbose builds (e.g. "gcc -o test" [sic!]), but shouldn't be
783             # a problem as the log will most likely contain other non-verbose
784             # commands which are detected.
785             next if not $non_verbose
786                     and not $line =~ /$file_extension_regex/o;
787
788             # Ignore false positives.
789             #
790             # `./configure` output.
791             next if not $non_verbose
792                     and $line =~ /^(?:checking|[Cc]onfigure:) /;
793             next if $line =~ /^\s*(?:Host\s+)?(?:C(?:\+\+)?\s+)?
794                                 [Cc]ompiler[\s.]*:?\s+
795                                 /x;
796             next if $line =~ /^\s*(?:- )?(?:HOST_)?(?:CC|CXX)\s*=\s*$cc_regex_full\s*$/o;
797             # `moc-qt4`, contains '-I/usr/share/qt4/mkspecs/linux-g++' (or
798             # similar for other architectures) which gets recognized as a
799             # compiler line. Ignore it.
800             next if $line =~ m{^/usr/bin/moc-qt4
801                                \s.+\s
802                                -I/usr/share/qt4/mkspecs/[a-z]+-g\++(?:-64)?
803                                \s}x;
804             # Ignore false positives when the line contains only CC=gcc but no
805             # other gcc command.
806             if ($line =~ /(.*)CC=$cc_regex_full(.*)/o) {
807                 my $before = $1;
808                 my $after  = $2;
809                 next if     not $before =~ /$cc_regex_normal/o
810                         and not $after  =~ /$cc_regex_normal/o;
811             }
812
813             # Check if additional hardening options were used. Used to ensure
814             # they are used for the complete build.
815             $harden_pie     = 1 if any_flags_used($line, @def_cflags_pie,
816                                                          @def_ldflags_pie);
817             $harden_bindnow = 1 if any_flags_used($line, @def_ldflags_bindnow);
818
819             push @input, $line;
820             push @input_nonverbose, $non_verbose;
821         }
822     }
823
824     close $fh or die $!;
825
826     # Ignore arch if requested.
827     if (scalar @option_ignore_arch > 0 and $arch) {
828         foreach my $ignore (@option_ignore_arch) {
829             if ($arch eq $ignore) {
830                 print "ignoring architecture '$arch'\n";
831                 next FILE;
832             }
833         }
834     }
835
836     if (scalar @input == 0) {
837         if (not $option_buildd) {
838             print "No compiler commands!\n";
839             $exit |= $exit_code{no_compiler_commands};
840         } else {
841             print "$buildd_tag{no_compiler_commands}||\n";
842         }
843         next FILE;
844     }
845
846     if ($option_buildd) {
847         $statistics{commands} += scalar @input;
848     }
849
850     # Option or auto detected.
851     if ($arch) {
852         # The following was partially copied from dpkg-dev 1.16.4.3
853         # (/usr/share/perl5/Dpkg/Vendor/Debian.pm, add_hardening_flags()),
854         # copyright Raphaël Hertzog <hertzog@debian.org>, Kees Cook
855         # <kees@debian.org>, Canonical, Ltd. licensed under GPL version 2 or
856         # later. Keep it in sync.
857
858         require Dpkg::Arch;
859         my ($abi, $os, $cpu) = Dpkg::Arch::debarch_to_debtriplet($arch);
860
861         # Disable unsupported hardening options.
862         if ($cpu =~ /^(?:ia64|alpha|mips|mipsel|hppa)$/ or $arch eq 'arm') {
863             $harden_stack = 0;
864         }
865         if ($cpu =~ /^(?:ia64|hppa|avr32)$/) {
866             $harden_relro   = 0;
867             $harden_bindnow = 0;
868         }
869     }
870
871     # Default values.
872     my @cflags   = @def_cflags;
873     my @cxxflags = @def_cxxflags;
874     my @cppflags = @def_cppflags;
875     my @ldflags  = @def_ldflags;
876     # Check the specified hardening options, same order as dpkg-buildflags.
877     if ($harden_pie) {
878         @cflags   = (@cflags,   @def_cflags_pie);
879         @cxxflags = (@cxxflags, @def_cflags_pie);
880         @ldflags  = (@ldflags,  @def_ldflags_pie);
881     }
882     if ($harden_stack) {
883         @cflags   = (@cflags,   @def_cflags_stack);
884         @cxxflags = (@cxxflags, @def_cflags_stack);
885     }
886     if ($harden_fortify) {
887         @cflags   = (@cflags,   @def_cflags_fortify);
888         @cxxflags = (@cxxflags, @def_cflags_fortify);
889         @cppflags = (@cppflags, @def_cppflags_fortify);
890     }
891     if ($harden_format) {
892         @cflags   = (@cflags,   @def_cflags_format);
893         @cxxflags = (@cxxflags, @def_cflags_format);
894     }
895     if ($harden_relro) {
896         @ldflags = (@ldflags, @def_ldflags_relro);
897     }
898     if ($harden_bindnow) {
899         @ldflags = (@ldflags, @def_ldflags_bindnow);
900     }
901
902     # Hack to fix cppflags_fortify_broken() if --ignore-flag
903     # -D_FORTIFY_SOURCE=2 is used to ignore missing fortification. Only works
904     # as long as @def_cppflags_fortify contains only one variable.
905     if (scalar @def_cppflags_fortify == 0) {
906         $harden_fortify = 0;
907     }
908
909     # Ignore flags for this arch if requested.
910     if ($arch and exists $option_ignore_arch_flag{$arch}) {
911         my @local_flag_refs = (\@cflags, \@cxxflags, \@cppflags, \@ldflags);
912
913         remove_flags(\@local_flag_refs,
914                      \%flag_renames,
915                      @{$option_ignore_arch_flag{$arch}});
916     }
917
918     my @ignore_line = @option_ignore_line;
919     # Ignore lines for this arch if requested.
920     if ($arch and exists $option_ignore_arch_line{$arch}) {
921         @ignore_line = (@ignore_line, @{$option_ignore_arch_line{$arch}});
922     }
923
924 LINE:
925     for (my $i = 0; $i < scalar @input; $i++) {
926         my $line = $input[$i];
927
928         # Ignore line if requested.
929         foreach my $ignore (@ignore_line) {
930             next LINE if $line =~ /$ignore/;
931         }
932
933         my $skip = 0;
934         if ($input_nonverbose[$i]
935                 and is_non_verbose_build($line, $input[$i + 1], \$skip)) {
936             if (not $option_buildd) {
937                 error_non_verbose_build($line);
938                 $exit |= $exit_code{non_verbose_build};
939             } else {
940                 $statistics{commands_nonverbose}++;
941             }
942             next;
943         }
944         # Even if it's a verbose build, we might have to skip this line.
945         next if $skip;
946
947         # Remove everything until and including the compiler command. Makes
948         # checks easier and faster.
949         $line =~ s/^.*?$cc_regex//o;
950         # "([...] test.c)" is not detected as 'test.c' - fix this by removing
951         # the brace and similar characters at the line end.
952         $line =~ s/['")]+$//;
953
954         # Skip unnecessary tests when only preprocessing.
955         my $flag_preprocess = 0;
956
957         my $dependency = 0;
958         my $preprocess = 0;
959         my $compile    = 0;
960         my $link       = 0;
961
962         # Preprocess, compile, assemble.
963         if ($line =~ /\s(-E|-S|-c)\b/) {
964             $preprocess      = 1;
965             $flag_preprocess = 1 if $1 eq '-E';
966             $compile         = 1 if $1 eq '-S' or $1 eq '-c';
967         # Dependency generation for Makefiles. The other flags (-MF -MG -MP
968         # -MT -MQ) are always used with -M/-MM.
969         } elsif ($line =~ /\s(?:-M|-MM)\b/) {
970             $dependency = 1;
971         # Otherwise assume we are linking.
972         } else {
973             $link = 1;
974         }
975
976         # -MD/-MMD also cause dependency generation, but they don't imply -E!
977         if ($line =~ /\s(?:-MD|-MMD)\b/) {
978             $dependency      = 0;
979             $flag_preprocess = 0;
980         }
981
982         # Dependency generation for Makefiles, no preprocessing or other flags
983         # needed.
984         next if $dependency;
985
986         # Get all file extensions on this line.
987         my @extensions = $line =~ /$file_extension_regex/go;
988         # Ignore all unknown extensions to speedup the search below.
989         @extensions = grep { exists $extension{$_} } @extensions;
990
991         # These file types don't require preprocessing.
992         if (extension_found(\%extensions_no_preprocess, @extensions)) {
993             $preprocess = 0;
994         }
995         # These file types require preprocessing.
996         if (extension_found(\%extensions_preprocess, @extensions)) {
997             $preprocess = 1;
998         }
999
1000         if (not $flag_preprocess) {
1001             # If there are source files then it's compiling/linking in one
1002             # step and we must check both. We only check for source files
1003             # here, because header files cause too many false positives.
1004             if (extension_found(\%extensions_compile_link, @extensions)) {
1005                 # Assembly files don't need CFLAGS.
1006                 if (not extension_found(\%extensions_compile, @extensions)
1007                         and extension_found(\%extensions_no_compile, @extensions)) {
1008                     $compile = 0;
1009                 # But the rest does.
1010                 } else {
1011                     $compile = 1;
1012                 }
1013             # No compilable extensions found, either linking or compiling
1014             # header flags.
1015             #
1016             # If there are also no object files we are just compiling headers
1017             # (.h -> .h.gch). Don't check for linker flags in this case. Due
1018             # to our liberal checks for compiler lines, this also reduces the
1019             # number of false positives considerably.
1020             } elsif ($link
1021                     and not extension_found(\%extensions_object, @extensions)) {
1022                 $link = 0;
1023             }
1024         }
1025
1026         # Assume CXXFLAGS are required when a C++ file is specified in the
1027         # compiler line.
1028         my $compile_cpp = 0;
1029         if ($compile
1030                 and extension_found(\%extensions_compile_cpp, @extensions)) {
1031             $compile     = 0;
1032             $compile_cpp = 1;
1033         }
1034
1035         if ($option_buildd) {
1036             $statistics{preprocess}++  if $preprocess;
1037             $statistics{compile}++     if $compile;
1038             $statistics{compile_cpp}++ if $compile_cpp;
1039             $statistics{link}++        if $link;
1040         }
1041
1042         # Check hardening flags.
1043         my @missing;
1044         if ($compile and not all_flags_used($line, \@missing, @cflags)
1045                 # Libraries linked with -fPIC don't have to (and can't) be
1046                 # linked with -fPIE as well. It's no error if only PIE flags
1047                 # are missing.
1048                 and not pic_pie_conflict($line, $harden_pie, \@missing, @def_cflags_pie)
1049                 # Assume dpkg-buildflags returns the correct flags.
1050                 and index($line, '`dpkg-buildflags --get CFLAGS`') == -1) {
1051             if (not $option_buildd) {
1052                 error_flags('CFLAGS missing', \@missing, \%flag_renames, $input[$i]);
1053                 $exit |= $exit_code{flags_missing};
1054             } else {
1055                 $statistics{compile_missing}++;
1056             }
1057         } elsif ($compile_cpp and not all_flags_used($line, \@missing, @cflags)
1058                 # Libraries linked with -fPIC don't have to (and can't) be
1059                 # linked with -fPIE as well. It's no error if only PIE flags
1060                 # are missing.
1061                 and not pic_pie_conflict($line, $harden_pie, \@missing, @def_cflags_pie)
1062                 # Assume dpkg-buildflags returns the correct flags.
1063                 and index($line, '`dpkg-buildflags --get CXXFLAGS`') == -1) {
1064             if (not $option_buildd) {
1065                 error_flags('CXXFLAGS missing', \@missing, \%flag_renames, $input[$i]);
1066                 $exit |= $exit_code{flags_missing};
1067             } else {
1068                 $statistics{compile_cpp_missing}++;
1069             }
1070         }
1071         if ($preprocess
1072                 and (not all_flags_used($line, \@missing, @cppflags)
1073                     # The fortify flag might be overwritten, detect that.
1074                      or ($harden_fortify
1075                          and cppflags_fortify_broken($line, \@missing)))
1076                 # Assume dpkg-buildflags returns the correct flags.
1077                 and index($line, '`dpkg-buildflags --get CPPFLAGS`') == -1) {
1078             if (not $option_buildd) {
1079                 error_flags('CPPFLAGS missing', \@missing, \%flag_renames, $input[$i]);
1080                 $exit |= $exit_code{flags_missing};
1081             } else {
1082                 $statistics{preprocess_missing}++;
1083             }
1084         }
1085         if ($link and not all_flags_used($line, \@missing, @ldflags)
1086                 # Same here, -fPIC conflicts with -fPIE.
1087                 and not pic_pie_conflict($line, $harden_pie, \@missing, @def_ldflags_pie)
1088                 # Assume dpkg-buildflags returns the correct flags.
1089                 and index($line, '`dpkg-buildflags --get LDFLAGS`') == -1) {
1090             if (not $option_buildd) {
1091                 error_flags('LDFLAGS missing', \@missing, \%flag_renames, $input[$i]);
1092                 $exit |= $exit_code{flags_missing};
1093             } else {
1094                 $statistics{link_missing}++;
1095             }
1096         }
1097     }
1098 }
1099
1100 # Print statistics for buildd mode, only output in this mode.
1101 if ($option_buildd) {
1102     my @warning;
1103
1104     if ($statistics{preprocess_missing}) {
1105         push @warning, sprintf 'CPPFLAGS %d (of %d)',
1106                                $statistics{preprocess_missing},
1107                                $statistics{preprocess};
1108     }
1109     if ($statistics{compile_missing}) {
1110         push @warning, sprintf 'CFLAGS %d (of %d)',
1111                                $statistics{compile_missing},
1112                                $statistics{compile};
1113     }
1114     if ($statistics{compile_cpp_missing}) {
1115         push @warning, sprintf 'CXXFLAGS %d (of %d)',
1116                                $statistics{compile_cpp_missing},
1117                                $statistics{compile_cpp};
1118     }
1119     if ($statistics{link_missing}) {
1120         push @warning, sprintf 'LDFLAGS %d (of %d)',
1121                                $statistics{link_missing},
1122                                $statistics{link};
1123     }
1124     if (scalar @warning) {
1125         local $" = ', '; # array join string
1126         print "$buildd_tag{flags_missing}|@warning missing|\n";
1127     }
1128
1129     if ($statistics{commands_nonverbose}) {
1130         printf "$buildd_tag{non_verbose_build}|%d (of %d) hidden|\n",
1131                $statistics{commands_nonverbose},
1132                $statistics{commands},
1133     }
1134 }
1135
1136
1137 exit $exit;
1138
1139
1140 __END__
1141
1142 =head1 NAME
1143
1144 blhc - build log hardening check, checks build logs for missing hardening flags
1145
1146 =head1 SYNOPSIS
1147
1148 B<blhc> [I<options>] I<< <dpkg-buildpackage build log file>.. >>
1149
1150 =head1 DESCRIPTION
1151
1152 blhc is a small tool which checks build logs for missing hardening flags. It's
1153 licensed under the GPL 3 or later.
1154
1155 It's designed to check build logs generated by Debian's dpkg-buildpackage (or
1156 tools using dpkg-buildpackage like pbuilder or the official buildd build logs)
1157 to help maintainers detect missing hardening flags in their packages.
1158
1159 Only gcc is detected as compiler at the moment. If other compilers support
1160 hardening flags as well, please report them.
1161
1162 If there's no output, no flags are missing and the build log is fine.
1163
1164 =head1 OPTIONS
1165
1166 =over 8
1167
1168 =item B<--all>
1169
1170 Force check for all +all (+pie, +bindnow) hardening flags. By default it's
1171 auto detected.
1172
1173 =item B<--arch> I<architecture>
1174
1175 Set the specific architecture (e.g. amd64, armel, etc.), automatically
1176 disables hardening flags not available on this architecture. Is detected
1177 automatically if dpkg-buildpackage is used.
1178
1179 =item B<--bindnow>
1180
1181 Force check for all +bindnow hardening flags. By default it's auto detected.
1182
1183 =item B<--buildd>
1184
1185 Special mode for buildds when automatically parsing log files. The following
1186 changes are in effect:
1187
1188 =over 2
1189
1190 =item *
1191
1192 Print tags instead of normal warnings, see L</"BUILDD TAGS"> for a list of
1193 possible tags.
1194
1195 =item *
1196
1197 Don't check hardening flags in old log files (if dpkg-dev << 1.16.1 is
1198 detected).
1199
1200 =item *
1201
1202 Don't require Term::ANSIColor.
1203
1204 =item *
1205
1206 Return exit code 0, unless there was a error (-I, -W messages don't count as
1207 error).
1208
1209 =back
1210
1211 =item B<--color>
1212
1213 Use colored (ANSI) output for warning messages.
1214
1215 =item B<--ignore-arch> I<arch>
1216
1217 Ignore build logs from architectures matching I<arch>. I<arch> is a string.
1218
1219 Used to prevent false positives. This option can be specified multiple times.
1220
1221 =item B<--ignore-arch-flag> I<arch>:I<flag>
1222
1223 Like B<--ignore-flag>, but only ignore flag on I<arch>.
1224
1225 =item B<--ignore-arch-line> I<arch>:I<line>
1226
1227 Like B<--ignore-line>, but only ignore line on I<arch>.
1228
1229 =item B<--ignore-flag> I<flag>
1230
1231 Don't print an error when the specific flag is missing in a compiler line.
1232 I<flag> is a string.
1233
1234 Used to prevent false positives. This option can be specified multiple times.
1235
1236 =item B<--ignore-line> I<regex>
1237
1238 Ignore lines matching the given Perl regex. I<regex> is automatically anchored
1239 at the beginning and end of the line to prevent false negatives.
1240
1241 B<NOTE>: Not the input lines are checked, but the lines which are displayed in
1242 warnings (which have line continuation resolved).
1243
1244 Used to prevent false positives. This option can be specified multiple times.
1245
1246 =item B<--pie>
1247
1248 Force check for all +pie hardening flags. By default it's auto detected.
1249
1250 =item B<-h -? --help>
1251
1252 Print available options.
1253
1254 =item B<--version>
1255
1256 Print version number and license.
1257
1258 =back
1259
1260 Auto detection for B<--pie> and B<--bindnow> only works if at least one
1261 command uses the required hardening flag (e.g. -fPIE). Then it's required for
1262 all other commands as well.
1263
1264 =head1 EXAMPLES
1265
1266 Normal usage, parse a single log file.
1267
1268     blhc path/to/log/file
1269
1270 If there's no output, no flags are missing and the build log is fine.
1271
1272 Parse multiple log files. The exit code is ORed over all files.
1273
1274     blhc path/to/directory/with/log/files/*
1275
1276 Don't treat missing C<-g> as error:
1277
1278     blhc --ignore-flag -g path/to/log/file
1279
1280 Don't treat missing C<-pie> on kfreebsd-amd64 as error:
1281
1282     blhc --ignore-arch-flag kfreebsd-amd64:-pie path/to/log/file
1283
1284 Ignore lines consisting exactly of C<./script gcc file> which would cause a
1285 false positive.
1286
1287     blhc --ignore-line '\./script gcc file' path/to/log/file
1288
1289 Ignore lines matching C<./script gcc file> somewhere in the line.
1290
1291     blhc --ignore-line '.*\./script gcc file.*' path/to/log/file
1292
1293 Use blhc with pbuilder.
1294
1295     pbuilder path/to/package.dsc | tee path/log/file
1296     blhc path/to/file || echo flags missing
1297
1298 =head1 BUILDD TAGS
1299
1300 The following tags are used in I<--buildd> mode. In braces the additional data
1301 which is displayed.
1302
1303 =over 2
1304
1305 =item B<I-hardening-wrapper-used>
1306
1307 The package uses hardening-wrapper which intercepts calls to gcc and adds
1308 hardening flags. The build log doesn't contain any hardening flags and thus
1309 can't be checked by blhc.
1310
1311 =item B<W-compiler-flags-hidden> (summary of hidden lines)
1312
1313 Build log contains lines which hide the real compiler flags. For example:
1314
1315     CC test-a.c
1316     CC test-b.c
1317     CC test-c.c
1318     LD test
1319
1320 Most of the time either C<export V=1> or C<export verbose=1> in
1321 F<debian/rules> fixes builds with hidden compiler flags. Sometimes C<.SILENT>
1322 in a F<Makefile> must be removed. And as last resort the F<Makefile> must be
1323 patched to remove the C<@>s hiding the real compiler commands.
1324
1325 =item B<W-dpkg-buildflags-missing> (summary of missing flags)
1326
1327 CPPFLAGS, CFLAGS, CXXFLAGS, LDFLAGS missing.
1328
1329 =item B<I-invalid-cmake-used> (version)
1330
1331 By default CMake ignores CPPFLAGS thus missing those hardening flags. Debian
1332 patched CMake in versions 2.8.7-1 and 2.8.7-2 to respect CPPFLAGS, but this
1333 patch was rejected by upstream and later reverted in Debian. Thus those two
1334 versions show correct usage of CPPFLAGS even if the package doesn't correctly
1335 handle them (for example by passing them to CFLAGS). To prevent false
1336 negatives just blacklist those two versions.
1337
1338 =item B<I-no-compiler-commands>
1339
1340 No compiler commands were detected. Either the log contains none or they were
1341 not correctly detected by blhc (please report the bug in this case).
1342
1343 =back
1344
1345 =head1 EXIT STATUS
1346
1347 The exit status is a "bit mask", each listed status is ORed when the error
1348 condition occurs to get the result.
1349
1350 =over 4
1351
1352 =item B<0>
1353
1354 Success.
1355
1356 =item B<1>
1357
1358 No compiler commands were found.
1359
1360 =item B<2>
1361
1362 Invalid arguments/options given to blhc.
1363
1364 =item B<4>
1365
1366 Non verbose build.
1367
1368 =item B<8>
1369
1370 Missing hardening flags.
1371
1372 =item B<16>
1373
1374 Hardening wrapper detected, no tests performed.
1375
1376 =item B<32>
1377
1378 Invalid CMake version used. See B<I-invalid-cmake-used> under L</"BUILDD
1379 TAGS"> for a detailed explanation.
1380
1381 =back
1382
1383 =head1 AUTHOR
1384
1385 Simon Ruderich, E<lt>simon@ruderich.orgE<gt>
1386
1387 Thanks to to Bernhard R. Link E<lt>brlink@debian.orgE<gt> and Jaria Alto
1388 E<lt>jari.aalto@cante.netE<gt> for their valuable input and suggestions.
1389
1390 =head1 LICENSE AND COPYRIGHT
1391
1392 Copyright (C) 2012 by Simon Ruderich
1393
1394 This program is free software: you can redistribute it and/or modify
1395 it under the terms of the GNU General Public License as published by
1396 the Free Software Foundation, either version 3 of the License, or
1397 (at your option) any later version.
1398
1399 This program is distributed in the hope that it will be useful,
1400 but WITHOUT ANY WARRANTY; without even the implied warranty of
1401 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1402 GNU General Public License for more details.
1403
1404 You should have received a copy of the GNU General Public License
1405 along with this program.  If not, see <http://www.gnu.org/licenses/>.
1406
1407 =head1 SEE ALSO
1408
1409 L<hardening-check(1)>, L<dpkg-buildflags(1)>
1410
1411 =cut