Skip to content

Commit e32bc85

Browse files
committed
Fix default installation paths on mingw
Mingw config targets assumed that resulting programs and libraries are installed in a Unix-like environment and the default installation prefix was therefore set to '/usr/local'. However, mingw programs are installed in a Windows environment, and the installation directories should therefore have Windows defaults, i.e. the same kind of defaults as the VC config targets. A difficulty is, however, that a "cross compiled" build can't figure out the system defaults from environment the same way it's done when building "natively", so we have to fall back to hard coded defaults in that case. Tests can still be performed when cross compiled on a non-Windows platform, since all tests only depend on the source and build directory, and otherwise relies on normal local paths. CVE-2019-1552 Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from #9460)
1 parent 92a2f01 commit e32bc85

File tree

4 files changed

+120
-1
lines changed

4 files changed

+120
-1
lines changed

Diff for: CHANGES

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99

1010
Changes between 1.1.0k and 1.1.0l [xx XXX xxxx]
1111

12-
*)
12+
*) Use Windows installation paths in the mingw builds
13+
14+
Mingw isn't a POSIX environment per se, which means that Windows
15+
paths should be used for installation.
16+
(CVE-2019-1552)
17+
[Richard Levitte]
18+
1319

1420
Changes between 1.1.0j and 1.1.0k [28 May 2019]
1521

Diff for: Configurations/10-main.conf

+2
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,7 @@ sub vms_info {
14441444
shared_extension => ".dll",
14451445
multilib => "",
14461446
apps_aux_src => add("win32_init.c"),
1447+
build_scheme => add("mingw", { separator => undef }),
14471448
},
14481449
"mingw64" => {
14491450
# As for OPENSSL_USE_APPLINK. Applink makes it possible to use
@@ -1473,6 +1474,7 @@ sub vms_info {
14731474
shared_extension => ".dll",
14741475
multilib => "64",
14751476
apps_aux_src => add("win32_init.c"),
1477+
build_scheme => add("mingw64", { separator => undef }),
14761478
},
14771479

14781480
#### UEFI

Diff for: Configurations/unix-Makefile.tmpl

+96
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@
1313
our $shlibextimport = $target{shared_import_extension} || "";
1414
our $dsoext = $target{dso_extension} || ".so";
1515

16+
# $mingw_installroot and $mingw_commonroot is relevant for mingw only.
17+
my $mingw_installenv =
18+
$target{build_scheme}->[2] eq "mingw"
19+
? "ProgramFiles(x86)" : "ProgramW6432";
20+
my $mingw_commonenv =
21+
$target{build_scheme}->[2] eq "mingw"
22+
? "CommonProgramFiles(x86)" : "CommonProgramW6432";
23+
our $mingw_installroot =
24+
defined($ENV{$mingw_installenv})
25+
? $mingw_installenv : 'ProgramFiles';
26+
our $mingw_commonroot =
27+
defined($ENV{$mingw_commonenv})
28+
? $mingw_commonenv : 'CommonProgramFiles';
29+
my $mingw_installdflt =
30+
defined($ENV{$mingw_installenv})
31+
? "C:/Program Files (x86)" : "C:/Program Files";
32+
my $mingw_commondflt = "$mingw_installdflt/Common Files";
33+
34+
# expand variables early
35+
$mingw_installroot = $ENV{$mingw_installroot} // $mingw_installdflt;
36+
$mingw_commonroot = $ENV{$mingw_commonroot} // $mingw_commondflt;
37+
1638
sub windowsdll { $config{target} =~ /^(?:Cygwin|mingw)/ }
1739

1840
our $sover = $config{target} =~ /^mingw/
@@ -121,6 +143,7 @@ APPS_OPENSSL={- use File::Spec::Functions;
121143
# Normally it is left empty.
122144
DESTDIR=
123145

146+
{- output_off() if $config{target} =~ /^mingw/; "" -}
124147
# Do not edit these manually. Use Configure with --prefix or --openssldir
125148
# to change this! Short explanation in the top comment in Configure
126149
INSTALLTOP={- # $prefix is used in the OPENSSLDIR perl snippet
@@ -159,6 +182,79 @@ ENGINESDIR={- use File::Spec::Functions;
159182
# Convenience variable for those who want to set the rpath in shared
160183
# libraries and applications
161184
LIBRPATH=$(INSTALLTOP)/$(LIBDIR)
185+
{- output_on() if $config{target} =~ /^mingw/;
186+
output_off() if $config{target} !~ /^mingw/;
187+
"" -}
188+
# Do not edit these manually. Use Configure with --prefix or --openssldir
189+
# to change this! Short explanation in the top comment in Configure
190+
INSTALLTOP_dev={- # $prefix is used in the OPENSSLDIR perl snippet
191+
#
192+
use File::Spec::Win32;
193+
my $prefix_default = "$mingw_installroot/OpenSSL";
194+
our $prefix =
195+
File::Spec::Win32->canonpath($config{prefix}
196+
|| $prefix_default);
197+
our ($prefix_dev, $prefix_dir, $prefix_file) =
198+
File::Spec::Win32->splitpath($prefix, 1);
199+
$prefix =~ s|\\|/|g;
200+
$prefix_dir =~ s|\\|/|g;
201+
$prefix_dev -}
202+
INSTALLTOP_dir={- my $x = File::Spec::Win32->canonpath($prefix_dir);
203+
$x =~ s|\\|/|g;
204+
$x -}
205+
OPENSSLDIR_dev={- #
206+
# The logic here is that if no --openssldir was given,
207+
# OPENSSLDIR will get the value "$mingw_commonroot/SSL".
208+
# If --openssldir was given and the value is an absolute
209+
# path, OPENSSLDIR will get its value without change.
210+
# If the value from --openssldir is a relative path,
211+
# OPENSSLDIR will get $prefix with the --openssldir
212+
# value appended as a subdirectory.
213+
#
214+
use File::Spec::Win32;
215+
our $openssldir =
216+
$config{openssldir} ?
217+
(File::Spec::Win32->file_name_is_absolute($config{openssldir}) ?
218+
File::Spec::Win32->canonpath($config{openssldir})
219+
: File::Spec::Win32->catdir($prefix, $config{openssldir}))
220+
: File::Spec::Win32->canonpath("$mingw_commonroot/SSL");
221+
our ($openssldir_dev, $openssldir_dir, $openssldir_file) =
222+
File::Spec::Win32->splitpath($openssldir, 1);
223+
$openssldir =~ s|\\|/|g;
224+
$openssldir_dir =~ s|\\|/|g;
225+
$openssldir_dev -}
226+
OPENSSLDIR_dir={- my $x = File::Spec::Win32->canonpath($openssldir_dir);
227+
$x =~ s|\\|/|g;
228+
$x -}
229+
LIBDIR={- our $libdir = $config{libdir} || "lib";
230+
$libdir -}
231+
ENGINESDIR_dev={- use File::Spec::Win32;
232+
our $enginesdir =
233+
File::Spec::Win32->catdir($prefix,$libdir,
234+
"engines-$sover_dirname");
235+
our ($enginesdir_dev, $enginesdir_dir, $enginesdir_file) =
236+
File::Spec::Win32->splitpath($enginesdir, 1);
237+
$enginesdir =~ s|\\|/|g;
238+
$enginesdir_dir =~ s|\\|/|g;
239+
$enginesdir_dev -}
240+
ENGINESDIR_dir={- my $x = File::Spec::Win32->canonpath($enginesdir_dir);
241+
$x =~ s|\\|/|g;
242+
$x -}
243+
# In a Windows environment, $(DESTDIR) is harder to contatenate with other
244+
# directory variables, because both may contain devices. What we do here is
245+
# to adapt INSTALLTOP, OPENSSLDIR and ENGINESDIR depending on if $(DESTDIR)
246+
# has a value or not, to ensure that concatenation will always work further
247+
# down.
248+
ifneq "$(DESTDIR)" ""
249+
INSTALLTOP=$(INSTALLTOP_dir)
250+
OPENSSLDIR=$(OPENSSLDIR_dir)
251+
ENGINESDIR=$(ENGINESDIR_dir)
252+
else
253+
INSTALLTOP=$(INSTALLTOP_dev)$(INSTALLTOP_dir)
254+
OPENSSLDIR=$(OPENSSLDIR_dev)$(OPENSSLDIR_dir)
255+
ENGINESDIR=$(ENGINESDIR_dev)$(ENGINESDIR_dir)
256+
endif
257+
{- output_on() if $config{target} !~ /^mingw/; "" -}
162258

163259
MANDIR=$(INSTALLTOP)/share/man
164260
DOCDIR=$(INSTALLTOP)/share/doc/$(BASENAME)

Diff for: NOTES.WIN

+15
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,21 @@
107107
and i686-w64-mingw32-.
108108

109109

110+
Independently of the method chosen to build for mingw, the installation
111+
paths are similar to those used when building with VC-* targets, except
112+
that in case the fallbacks mentioned there aren't possible (typically
113+
when cross compiling on Linux), the paths will be the following:
114+
115+
For mingw:
116+
117+
PREFIX: C:/Program Files (x86)/OpenSSL
118+
OPENSSLDIR C:/Program Files (x86)/Common Files/SSL
119+
120+
For mingw64:
121+
122+
PREFIX: C:/Program Files/OpenSSL
123+
OPENSSLDIR C:/Program Files/Common Files/SSL
124+
110125
Linking your application
111126
------------------------
112127

0 commit comments

Comments
 (0)