diff --git a/src/node_metadata.cc b/src/node_metadata.cc index 819f41e2ab4384..5ff67eb3bd0d73 100644 --- a/src/node_metadata.cc +++ b/src/node_metadata.cc @@ -52,14 +52,19 @@ 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, ' '); + if (version[first_space] == '\0') { + return std::string("0.0.0"); + } + + const size_t start = first_space + 1; const size_t len = search(&version[start], ' '); return std::string(version, start, len); }