Skip to content

Commit cbc54d4

Browse files
sam-githubMylesBorins
authored andcommitted
crypto: strip unwanted space from openssl version
Remove trailing " \n" from `process.versions.openssl`. d3d6cd3 was incorrectly printing this trailer, but because the target buffer size was claimed to be the length of the version string, the trailer was truncated off. 9ed4646 corrected the target buffer size, but then the trailer started to appear in process.versions. Added a test to check for regressions. PR-URL: #23678 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
1 parent d1c0827 commit cbc54d4

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/node_crypto.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5733,9 +5733,9 @@ std::string GetOpenSSLVersion() {
57335733
// for reference: "OpenSSL 1.1.0i 14 Aug 2018"
57345734
char buf[128];
57355735
const int start = search(OPENSSL_VERSION_TEXT, 0, ' ') + 1;
5736-
const int end = search(OPENSSL_VERSION_TEXT + start, start, ' ') + 1;
5736+
const int end = search(OPENSSL_VERSION_TEXT + start, start, ' ');
57375737
const int len = end - start;
5738-
snprintf(buf, sizeof(buf), "%.*s\n", len, &OPENSSL_VERSION_TEXT[start]);
5738+
snprintf(buf, sizeof(buf), "%.*s", len, &OPENSSL_VERSION_TEXT[start]);
57395739
return std::string(buf);
57405740
}
57415741

test/parallel/test-process-versions.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ assert(/^\d+\.\d+\.\d+(?:\.\d+)?-node\.\d+(?: \(candidate\))?$/
3333
.test(process.versions.v8));
3434
assert(/^\d+$/.test(process.versions.modules));
3535

36+
if (common.hasCrypto) {
37+
assert(/^\d+\.\d+\.\d+[a-z]?$/.test(process.versions.openssl));
38+
}
39+
3640
for (let i = 0; i < expected_keys.length; i++) {
3741
const key = expected_keys[i];
3842
const descriptor = Object.getOwnPropertyDescriptor(process.versions, key);

0 commit comments

Comments
 (0)