Configure: Don't fail if there were "make variables" set in env

The original intent was that if someone had a "make variable" set in
any kind of way, be it as an environment variable or as an argument to
Configure, we wouldn't allow compiler or linker flags as arguments as
well.  That made both of these configurations equivalently impossible:

    ./Configure target CFLAGS=-foo -lextra

     CFLAGS=-foo ./Configure target -lextra

While this makes things look nice and consistent, real world use makes
this hard, as many projects where OpenSSL is a component also set
these variables for other components that use GNU autotools.

Therefore, we need to adapt our Configure accordingly.  By
consequence, the two Configure lines above will not be equivalent any
more:

    ./Configure target CFLAGS=-foo -lextra

This command line will still fail, because the "make variable" was
given as a command line argument.  This cannot be a mistake and is
therefore not allowed.

     CFLAGS=-foo ./Configure target -lextra

This command line will work, but because there is a linker flag as
a command line argument, the environment (i.e. CFLAGS) is ignored.
That isn't quite consistent with the previous command, but is the old
Configure behavior, before the support for "make variables" was added,
and is therefore the backward compatible behavior.

Fixes google/oss-fuzz#1244

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5641)
This commit is contained in:
Richard Levitte 2018-03-16 08:24:50 +01:00
parent 8ed5f09458
commit ac6ae8a9fe

View file

@ -602,6 +602,7 @@ $config{options}="";
$config{build_type} = "release"; $config{build_type} = "release";
my $target=""; my $target="";
my %cmdvars = (); # Stores FOO='blah' type arguments
my %unsupported_options = (); my %unsupported_options = ();
my %deprecated_options = (); my %deprecated_options = ();
# If you change this, update apps/version.c # If you change this, update apps/version.c
@ -614,7 +615,7 @@ while (@argvcopy)
# Support env variable assignments among the options # Support env variable assignments among the options
if (m|^(\w+)=(.+)?$|) if (m|^(\w+)=(.+)?$|)
{ {
$config{perlenv}->{$1} = $2; $cmdvars{$1} = $2;
# Every time a variable is given as a configuration argument, # Every time a variable is given as a configuration argument,
# it acts as a reset if the variable. # it acts as a reset if the variable.
if (exists $user{$1}) if (exists $user{$1})
@ -891,36 +892,46 @@ while (@argvcopy)
} }
} }
# If any %useradd entry has been set, we must check that the environment # If any %useradd entry has been set, we must check that the "make
# variables haven't been set. We start by checking of any %useradd entry # variables" haven't been set. We start by checking of any %useradd entry
# is set. # is set.
if (grep { scalar @$_ > 0 } values %useradd) { if (grep { scalar @$_ > 0 } values %useradd) {
# Hash of env / make variables names. The possible values are: # Hash of env / make variables names. The possible values are:
# 1 - environment set # 1 - "make vars"
# 2 - %useradd entry set # 2 - %useradd entry set
# 3 - both set # 3 - both set
my %detected_env = my %detected_vars =
map { my $v = 0; map { my $v = 0;
$v += 1 if env($_); $v += 1 if $cmdvars{$_};
$v += 2 if @{$useradd{$_}}; $v += 2 if @{$useradd{$_}};
$_ => $v } $_ => $v }
keys %useradd; keys %useradd;
# If any of the corresponding environment variables is set, we error # If any of the corresponding "make variables" is set, we error
if (grep { $_ & 1 } values %detected_env) { if (grep { $_ & 1 } values %detected_vars) {
my $names = join(', ', grep { $detected_env{$_} > 0 } my $names = join(', ', grep { $detected_vars{$_} > 0 }
sort keys %detected_env); sort keys %detected_vars);
die <<"_____"; die <<"_____";
***** Mixing env / make variables and additional compiler/linker flags as ***** Mixing make variables and additional compiler/linker flags as
***** configure command line option is not permitted. ***** configure command line option is not permitted.
***** Affected env / make variables: $names ***** Affected make variables: $names
_____ _____
} }
} }
# Check through all supported command line variables to see if any of them
# were set, and canonicalise the values we got. If no compiler or linker
# flag or anything else that affects %useradd was set, we also check the
# environment for values.
my $anyuseradd =
grep { defined $_ && (ref $_ ne 'ARRAY' || @$_) } values %useradd;
foreach (keys %user) { foreach (keys %user) {
my $value = env($_); my $value = $cmdvars{$_};
$value //= defined $user_synonyms{$_} ? env($user_synonyms{$_}) : undef; $value //= env($_) unless $anyuseradd;
$value //=
defined $user_synonyms{$_} ? $cmdvars{$user_synonyms{$_}} : undef;
$value //= defined $user_synonyms{$_} ? env($user_synonyms{$_}) : undef
unless $anyuseradd;
if (defined $value) { if (defined $value) {
if (ref $user{$_} eq 'ARRAY') { if (ref $user{$_} eq 'ARRAY') {
@ -3090,13 +3101,16 @@ sub which
sub env sub env
{ {
my $name = shift; my $name = shift;
my %opts = @_;
unless ($opts{cacheonly}) {
# Note that if $ENV{$name} doesn't exist or is undefined, # Note that if $ENV{$name} doesn't exist or is undefined,
# $config{perlenv}->{$name} will be created with the value # $config{perlenv}->{$name} will be created with the value
# undef. This is intentional. # undef. This is intentional.
$config{perlenv}->{$name} = $ENV{$name} $config{perlenv}->{$name} = $ENV{$name}
if ! exists $config{perlenv}->{$name}; if ! exists $config{perlenv}->{$name};
}
return $config{perlenv}->{$name}; return $config{perlenv}->{$name};
} }