mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
src: account for OpenSSL unexpected version
PR-URL: https://github.com/nodejs/node/pull/54038 Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
33633eebd9
commit
b52c2fff75
1 file changed
+11
-2
+11
-2
@@ -52,14 +52,23 @@ Metadata metadata;
|
||||
|
||||
#if HAVE_OPENSSL
|
||||
static constexpr size_t search(const char* s, char c, size_t n = 0) {
|
||||
return *s == c ? n : search(s + 1, c, n + 1);
|
||||
return *s == '\0' ? n : (*s == c ? n : search(s + 1, c, n + 1));
|
||||
}
|
||||
|
||||
static inline std::string GetOpenSSLVersion() {
|
||||
// sample openssl version string format
|
||||
// for reference: "OpenSSL 1.1.0i 14 Aug 2018"
|
||||
const char* version = OpenSSL_version(OPENSSL_VERSION);
|
||||
const size_t start = search(version, ' ') + 1;
|
||||
const size_t first_space = search(version, ' ');
|
||||
|
||||
// When Node.js is linked to an alternative library implementing the
|
||||
// OpenSSL API e.g. BoringSSL, the version string may not match the
|
||||
// expected pattern. In this case just return “0.0.0” as placeholder.
|
||||
if (version[first_space] == '\0') {
|
||||
return "0.0.0";
|
||||
}
|
||||
|
||||
const size_t start = first_space + 1;
|
||||
const size_t len = search(&version[start], ' ');
|
||||
return std::string(version, start, len);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user