Skip to content

Commit

Permalink
crypto: strip unwanted space from openssl version
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
sam-github authored and targos committed Oct 24, 2018
1 parent 86cf014 commit 4112a10
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5702,9 +5702,9 @@ std::string GetOpenSSLVersion() {
// for reference: "OpenSSL 1.1.0i 14 Aug 2018"
char buf[128];
const int start = search(OPENSSL_VERSION_TEXT, 0, ' ') + 1;
const int end = search(OPENSSL_VERSION_TEXT + start, start, ' ') + 1;
const int end = search(OPENSSL_VERSION_TEXT + start, start, ' ');
const int len = end - start;
snprintf(buf, sizeof(buf), "%.*s\n", len, &OPENSSL_VERSION_TEXT[start]);
snprintf(buf, sizeof(buf), "%.*s", len, &OPENSSL_VERSION_TEXT[start]);
return std::string(buf);
}

Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-process-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ assert(/^\d+\.\d+\.\d+(?:\.\d+)?-node\.\d+(?: \(candidate\))?$/
.test(process.versions.v8));
assert(/^\d+$/.test(process.versions.modules));

if (common.hasCrypto) {
assert(/^\d+\.\d+\.\d+[a-z]?$/.test(process.versions.openssl));
}

for (let i = 0; i < expected_keys.length; i++) {
const key = expected_keys[i];
const descriptor = Object.getOwnPropertyDescriptor(process.versions, key);
Expand Down

0 comments on commit 4112a10

Please sign in to comment.