Skip to content

Commit 4112a10

Browse files
sam-githubtargos
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 86cf014 commit 4112a10

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/node_crypto.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -5702,9 +5702,9 @@ std::string GetOpenSSLVersion() {
57025702
// for reference: "OpenSSL 1.1.0i 14 Aug 2018"
57035703
char buf[128];
57045704
const int start = search(OPENSSL_VERSION_TEXT, 0, ' ') + 1;
5705-
const int end = search(OPENSSL_VERSION_TEXT + start, start, ' ') + 1;
5705+
const int end = search(OPENSSL_VERSION_TEXT + start, start, ' ');
57065706
const int len = end - start;
5707-
snprintf(buf, sizeof(buf), "%.*s\n", len, &OPENSSL_VERSION_TEXT[start]);
5707+
snprintf(buf, sizeof(buf), "%.*s", len, &OPENSSL_VERSION_TEXT[start]);
57085708
return std::string(buf);
57095709
}
57105710

test/parallel/test-process-versions.js

+4
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)