# Build log hardening check, checks build logs for missing hardening flags.
-# Copyright (C) 2012-2016 Simon Ruderich
+# Copyright (C) 2012-2017 Simon Ruderich
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
use Getopt::Long ();
use Text::ParseWords ();
-our $VERSION = '0.06';
+our $VERSION = '0.07';
# CONSTANTS/VARIABLES
my $cc_regex = qr/
(?<!\s-) # ignore options, e.g. "-c++" [sic!] (used by swig)
(?<!\.) # ignore file names, e.g. "test.gcc"
- (?:cc|gcc|g\+\+|c\+\+)
+ (?:cc|gcc|g\+\+|c\+\+|mpicc|mpicxx)
(?:-[\d.]+)? # version suffix, e.g. "gcc-4.6"
/x;
# Full regex which matches the complete compiler name. Used in a few places to
qw( mii ),
);
my @source_no_preprocess_compile_ada = (
+ # Ada source
+ qw( ada ),
# Ada body
qw( adb ),
- # If you add another file, fix use of @source_no_preprocess_compile_ada
- # below (search for $compile_ada).
);
my @source_no_preprocess_compile = (
# C
# Ada
@source_no_preprocess_compile_ada,
);
+my @source_no_preprocess_no_compile_ada = (
+ # Ada specification
+ qw( ads ),
+);
my @source_no_preprocess_no_compile = (
# Assembly
qw( s ),
- # Ada specification
- qw( ads ),
+ # Ada
+ @source_no_preprocess_no_compile_ada,
);
my @source_no_preprocess = (
@source_no_preprocess_compile,
@source_preprocess_compile_cpp,
@source_no_preprocess_compile_cpp,
);
+my %extensions_ada = map { $_ => 1 } (
+ @source_no_preprocess_compile_ada,
+ @source_no_preprocess_no_compile_ada,
+);
my %extensions_object = map { $_ => 1 } (
@object,
);
}
if ($option_version) {
print <<"EOF";
-blhc $VERSION Copyright (C) 2012-2016 Simon Ruderich
+blhc $VERSION Copyright (C) 2012-2017 Simon Ruderich
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
# Option or auto detected.
if ($arch) {
- # The following was partially copied from dpkg-dev 1.18.10
+ # The following was partially copied from dpkg-dev 1.18.15
# (/usr/share/perl5/Dpkg/Vendor/Debian.pm, _add_hardening_flags()),
# copyright Raphaƫl Hertzog <hertzog@debian.org>, Kees Cook
# <kees@debian.org>, Canonical, Ltd. licensed under GPL version 2 or
# later. Keep it in sync.
require Dpkg::Arch;
- my ($abi, $os, $cpu) = Dpkg::Arch::debarch_to_debtriplet($arch);
+ my ($os, $cpu);
+ # Recent dpkg versions use a quadruplet for arch. Support both.
+ eval {
+ (undef, undef, $os, $cpu) = Dpkg::Arch::debarch_to_debtuple($arch);
+ };
+ if ($@) {
+ (undef, $os, $cpu) = Dpkg::Arch::debarch_to_debtriplet($arch);
+ }
# Disable unsupported hardening options.
if ($os !~ /^(?:linux|kfreebsd|knetbsd|hurd)$/
@ldflags = (@ldflags, @def_ldflags_bindnow);
}
- # Stores normal CFLAGS when @cflags_ada are temporarily used.
- my @cflags_backup;
- # Ada CFLAGS, only set if ada is used.
- my @cflags_ada;
# Ada doesn't support format hardening flags, see #680117 for more
# information. Filter them out if ada is used.
+ my @cflags_backup;
+ my @cflags_noformat;
if ($ada and $harden_format) {
- @cflags_ada = grep {
+ @cflags_noformat = grep {
my $ok = 1;
foreach my $flag (@def_cflags_format) {
$ok = 0 if $_ eq $flag;
}
my $compile_cpp = 0;
- my $compile_ada = 0;
+ my $restore_cflags = 0;
# Assume CXXFLAGS are required when a C++ file is specified in the
# compiler line.
if ($compile
$compile_cpp = 1;
# Ada needs special CFLAGS, use them if only ada files are compiled.
} elsif ($ada
- and $compile
- and array_equal(\@extensions,
- \@source_no_preprocess_compile_ada)) {
- $compile_ada = 1;
+ and extension_found(\%extensions_ada, @extensions)) {
+ $restore_cflags = 1;
+ $preprocess = 0; # Ada uses no CPPFLAGS
@cflags_backup = @cflags;
- @cflags = @cflags_ada;
+ @cflags = @cflags_noformat;
}
if ($option_buildd) {
}
# Restore normal CFLAGS.
- if ($compile_ada) {
+ if ($restore_cflags) {
@cflags = @cflags_backup;
}
}
=head1 LICENSE AND COPYRIGHT
-Copyright (C) 2012-2016 by Simon Ruderich
+Copyright (C) 2012-2017 by Simon Ruderich
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by