Skip to content

Commit 0f3057f

Browse files
committed
src: account for OpenSSL unexpected version
1 parent df478f4 commit 0f3057f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/node_metadata.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,19 @@ Metadata metadata;
5252

5353
#if HAVE_OPENSSL
5454
static constexpr size_t search(const char* s, char c, size_t n = 0) {
55-
return *s == c ? n : search(s + 1, c, n + 1);
55+
return *s == '\0' ? n : (*s == c ? n : search(s + 1, c, n + 1));
5656
}
5757

5858
static inline std::string GetOpenSSLVersion() {
5959
// sample openssl version string format
6060
// for reference: "OpenSSL 1.1.0i 14 Aug 2018"
6161
const char* version = OpenSSL_version(OPENSSL_VERSION);
62-
const size_t start = search(version, ' ') + 1;
62+
const size_t first_space = search(version, ' ');
63+
if (version[first_space] == '\0') {
64+
return std::string("0.0.0");
65+
}
66+
67+
const size_t start = first_space + 1;
6368
const size_t len = search(&version[start], ' ');
6469
return std::string(version, start, len);
6570
}

0 commit comments

Comments
 (0)