Skip to content

Commit ca54087

Browse files
committed
Raise an error when the specified OpenSSL library directory doesn't exist.
OpenSSL built from the source creates the library directory to the `/path/to/openssl_dir/lib64` as a default. In the case, the `bundle exec rake compile -- --with-openssl-dir=<openssl_dir>` cannot compile with the lib64 directory, and may compile with system OpenSSL's libraries unintentionally. This commit is to check this case to avoid linking with an unintentional library directory.
1 parent ee03210 commit ca54087

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

ext/openssl/extconf.rb

+22-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,32 @@
1313

1414
require "mkmf"
1515

16+
ssl_dirs = nil
1617
if defined?(::TruffleRuby)
1718
# Always respect the openssl prefix chosen by truffle/openssl-prefix
1819
require 'truffle/openssl-prefix'
19-
dir_config_given = dir_config("openssl", ENV["OPENSSL_PREFIX"]).any?
20+
ssl_dirs = dir_config("openssl", ENV["OPENSSL_PREFIX"])
2021
else
21-
dir_config_given = dir_config("openssl").any?
22+
ssl_dirs = dir_config("openssl")
23+
end
24+
dir_config_given = ssl_dirs.any?
25+
26+
_, ssl_ldir = ssl_dirs
27+
if ssl_ldir&.split(File::PATH_SEPARATOR)&.none? { |dir| File.directory?(dir) }
28+
# According to the `mkmf.rb#dir_config`, the `--with-openssl-dir=<dir>` uses
29+
# the value of the `File.basename(RbConfig::MAKEFILE_CONFIG["libdir"])` as a
30+
# loaded library directory name.
31+
ruby_ldir_name = File.basename(RbConfig::MAKEFILE_CONFIG["libdir"])
32+
33+
raise "OpenSSL library directory could not be found in '#{ssl_ldir}'. " \
34+
"You might want to fix this error in one of the following ways.\n" \
35+
" * Recompile OpenSSL by configuring it with --libdir=#{ruby_ldir_name} " \
36+
" to specify the OpenSSL library directory.\n" \
37+
" * Recompile Ruby by configuring it with --libdir=<dir> to specify the " \
38+
"Ruby library directory.\n" \
39+
" * Compile this openssl gem with --with-openssl-include=<dir> and " \
40+
"--with-openssl-lib=<dir> options to specify the OpenSSL include and " \
41+
"library directories."
2242
end
2343

2444
dir_config("kerberos")

0 commit comments

Comments
 (0)