From 2ee1cb18cb667875ae285a70e074e982f311a01e Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Mon, 15 Oct 2018 15:15:26 -0700 Subject: [PATCH] crypto: strip unwanted space from openssl version Remove trailing " \n" from `process.versions.openssl`. d3d6cd3ecad19 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. 9ed4646df05b9 corrected the target buffer size, but then the trailer started to appear in process.versions. Added a test to check for regressions. --- src/node_crypto.cc | 4 ++-- test/parallel/test-process-versions.js | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index ec7d4f2bb5be3d..122334351afaf3 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -5715,9 +5715,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); } diff --git a/test/parallel/test-process-versions.js b/test/parallel/test-process-versions.js index 8f706c6954cd2c..9a211286770586 100644 --- a/test/parallel/test-process-versions.js +++ b/test/parallel/test-process-versions.js @@ -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);