Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: account for OpenSSL unexpected version #54038

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/node_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
anonrig marked this conversation as resolved.
Show resolved Hide resolved
}

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') {
codebytere marked this conversation as resolved.
Show resolved Hide resolved
return "0.0.0";
}

const size_t start = first_space + 1;
const size_t len = search(&version[start], ' ');
return std::string(version, start, len);
}
Expand Down
Loading