Skip to content

Commit

Permalink
Configure: Refuse to make directories in the source tree
Browse files Browse the repository at this point in the history
Fixes openssl#22907

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from openssl#22908)
  • Loading branch information
levitte authored and wbeck10p committed Jan 8, 2024
1 parent 08176ae commit 19b69a3
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions Configure
Original file line number Diff line number Diff line change
Expand Up @@ -1891,11 +1891,12 @@ if ($builder eq "unified") {
my $base = shift;
my $dir = shift;
my $relativeto = shift || ".";
my $no_mkpath = shift // 0;

$dir = catdir($base,$dir) unless isabsolute($dir);

# Make sure the directories we're building in exists
mkpath($dir);
mkpath($dir) unless $no_mkpath;

my $res = abs2rel(absolutedir($dir), rel2abs($relativeto));
#print STDERR "DEBUG[cleandir]: $dir , $base => $res\n";
Expand All @@ -1906,14 +1907,15 @@ if ($builder eq "unified") {
my $base = shift;
my $file = shift;
my $relativeto = shift || ".";
my $no_mkpath = shift // 0;

$file = catfile($base,$file) unless isabsolute($file);

my $d = dirname($file);
my $f = basename($file);

# Make sure the directories we're building in exists
mkpath($d);
mkpath($d) unless $no_mkpath;

my $res = abs2rel(catfile(absolutedir($d), $f), rel2abs($relativeto));
#print STDERR "DEBUG[cleanfile]: $d , $f => $res\n";
Expand Down Expand Up @@ -1943,7 +1945,7 @@ if ($builder eq "unified") {
}
# Then, look in our standard directory
push @build_file_templates,
( map { cleanfile($srcdir, catfile("Configurations", $_), $blddir) }
( map { cleanfile($srcdir, catfile("Configurations", $_), $blddir, 1) }
@build_file_template_names );

my $build_file_template;
Expand All @@ -1958,7 +1960,7 @@ if ($builder eq "unified") {
}
$config{build_file_templates}
= [ cleanfile($srcdir, catfile("Configurations", "common0.tmpl"),
$blddir),
$blddir, 1),
$build_file_template ];

my @build_dirs = ( [ ] ); # current directory
Expand All @@ -1967,7 +1969,7 @@ if ($builder eq "unified") {

# We want to detect configdata.pm in the source tree, so we
# don't use it if the build tree is different.
my $src_configdata = cleanfile($srcdir, "configdata.pm", $blddir);
my $src_configdata = cleanfile($srcdir, "configdata.pm", $blddir, 1);

# Any source file that we recognise is placed in this hash table, with
# the list of its intended destinations as value. When everything has
Expand Down Expand Up @@ -2320,7 +2322,7 @@ EOF
my $dest = $_;
my $ddest = cleanfile($buildd, $_, $blddir);
foreach (@{$sources{$dest}}) {
my $s = cleanfile($sourced, $_, $blddir);
my $s = cleanfile($sourced, $_, $blddir, 1);

# If it's generated or we simply don't find it in the source
# tree, we assume it's in the build tree.
Expand Down Expand Up @@ -2365,7 +2367,7 @@ EOF
my $dest = $_;
my $ddest = cleanfile($buildd, $_, $blddir);
foreach (@{$shared_sources{$dest}}) {
my $s = cleanfile($sourced, $_, $blddir);
my $s = cleanfile($sourced, $_, $blddir, 1);

# If it's generated or we simply don't find it in the source
# tree, we assume it's in the build tree.
Expand Down Expand Up @@ -2420,7 +2422,7 @@ EOF
if scalar @{$generate{$_}} > 1;
my @generator = split /\s+/, $generate{$dest}->[0];
my $gen = $generator[0];
$generator[0] = cleanfile($sourced, $gen, $blddir);
$generator[0] = cleanfile($sourced, $gen, $blddir, 1);

# If the generator is itself generated, it's in the build tree
if ($generate{$gen} || ! -f $generator[0]) {
Expand All @@ -2446,7 +2448,7 @@ EOF
} elsif ($dest eq '') {
$ddest = '';
} else {
$ddest = cleanfile($sourced, $dest, $blddir);
$ddest = cleanfile($sourced, $dest, $blddir, 1);

# If the destination doesn't exist in source, it can only be
# a generated file in the build tree.
Expand All @@ -2471,12 +2473,12 @@ EOF
&& $f =~ m/^(.*?)\|(.*)$/) {
$i = $1;
$m = $2;
$i = cleanfile($sourced, $i, $blddir);
$i = cleanfile($sourced, $i, $blddir, 1);
$i2 = cleanfile($buildd, $i, $blddir);
$d = cleanfile($sourced, "$i/$m", $blddir);
$d = cleanfile($sourced, "$i/$m", $blddir, 1);
$d2 = cleanfile($buildd, "$i/$m", $blddir);
} else {
$d = cleanfile($sourced, $f, $blddir);
$d = cleanfile($sourced, $f, $blddir, 1);
$d2 = cleanfile($buildd, $f, $blddir);
}

Expand Down Expand Up @@ -2507,15 +2509,15 @@ EOF

foreach (keys %includes) {
my $dest = $_;
my $ddest = cleanfile($sourced, $_, $blddir);
my $ddest = cleanfile($sourced, $_, $blddir, 1);

# If the destination doesn't exist in source, it can only be
# a generated file in the build tree.
if ($ddest eq $src_configdata || ! -f $ddest) {
$ddest = cleanfile($buildd, $_, $blddir);
}
foreach (@{$includes{$dest}}) {
my $is = cleandir($sourced, $_, $blddir);
my $is = cleandir($sourced, $_, $blddir, 1);
my $ib = cleandir($buildd, $_, $blddir);
push @{$unified_info{includes}->{$ddest}->{source}}, $is
unless grep { $_ eq $is } @{$unified_info{includes}->{$ddest}->{source}};
Expand All @@ -2528,7 +2530,7 @@ EOF
my $ddest;

if ($dest ne "") {
$ddest = cleanfile($sourced, $dest, $blddir);
$ddest = cleanfile($sourced, $dest, $blddir, 1);

# If the destination doesn't exist in source, it can only
# be a generated file in the build tree.
Expand Down Expand Up @@ -2912,7 +2914,7 @@ my %template_vars = (
my $configdata_outname = 'configdata.pm';
open CONFIGDATA, ">$configdata_outname.new"
or die "Trying to create $configdata_outname.new: $!";
my $configdata_tmplname = cleanfile($srcdir, "configdata.pm.in", $blddir);
my $configdata_tmplname = cleanfile($srcdir, "configdata.pm.in", $blddir, 1);
my $configdata_tmpl =
OpenSSL::Template->new(TYPE => 'FILE', SOURCE => $configdata_tmplname);
$configdata_tmpl->fill_in(
Expand Down

0 comments on commit 19b69a3

Please sign in to comment.