9696// ========== global C headers ==========
9797
9898#include < fcntl.h> // _O_RDWR
99+ #include < sys/stat.h>
99100#include < sys/types.h>
100101
101102#if defined(NODE_HAVE_I18N_SUPPORT)
@@ -1215,6 +1216,28 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args,
12151216 conf_file = per_process::cli_options->openssl_config .c_str ();
12161217 }
12171218
1219+ // If the configured OpenSSL config file is actually a directory (for
1220+ // example when an application sets `OPENSSL_CONF` to a directory), OpenSSL
1221+ // may attempt to fopen() it which yields an error and causes startup to
1222+ // fail. Detect and ignore directory paths here and emit a warning so the
1223+ // process can continue using default OpenSSL config instead.
1224+ if (conf_file != nullptr ) {
1225+ struct stat st;
1226+ if (stat (conf_file, &st) == 0 ) {
1227+ #if defined(S_ISDIR)
1228+ if (S_ISDIR (st.st_mode )) {
1229+ #else
1230+ if ((st.st_mode & S_IFMT) == S_IFDIR) {
1231+ #endif
1232+ std::string warning = " Warning: OPENSSL_CONF path is a directory; "
1233+ " ignoring: " ;
1234+ warning += conf_file;
1235+ fprintf (stderr, " %s\n " , warning.c_str ());
1236+ conf_file = nullptr ;
1237+ }
1238+ }
1239+ }
1240+
12181241 OPENSSL_INIT_SETTINGS* settings = OPENSSL_INIT_new ();
12191242 OPENSSL_INIT_set_config_filename (settings, conf_file);
12201243 OPENSSL_INIT_set_config_appname (settings, conf_section_name);
@@ -1225,14 +1248,11 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args,
12251248 OPENSSL_INIT_free (settings);
12261249
12271250 if (ERR_peek_error () != 0 ) {
1228- // XXX: ERR_GET_REASON does not return something that is
1229- // useful as an exit code at all.
1230- result->exit_code_ =
1231- static_cast <ExitCode>(ERR_GET_REASON (ERR_peek_error ()));
1232- result->early_return_ = true ;
1233- result->errors_ .emplace_back (" OpenSSL configuration error:\n " +
1234- GetOpenSSLErrorString ());
1235- return result;
1251+ std::string warning =
1252+ " Warning: OpenSSL configuration error:\n " + GetOpenSSLErrorString ();
1253+ fprintf (stderr, " %s\n " , warning.c_str ());
1254+
1255+ ERR_clear_error ();
12361256 }
12371257#else // OPENSSL_VERSION_MAJOR < 3
12381258 if (FIPS_mode ()) {
0 commit comments