Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: pass along errors from --security-reverts #25466

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,14 @@ int ProcessGlobalArgs(std::vector<std::string>* args,

if (!errors->empty()) return 9;

for (const std::string& cve : per_process::cli_options->security_reverts)
Revert(cve.c_str());
std::string revert_error;
for (const std::string& cve : per_process::cli_options->security_reverts) {
Revert(cve.c_str(), &revert_error);
if (!revert_error.empty()) {
errors->emplace_back(std::move(revert_error));
return 12;
}
}

auto env_opts = per_process::cli_options->per_isolate->per_env;
if (std::find(v8_args.begin(), v8_args.end(),
Expand Down
7 changes: 4 additions & 3 deletions src/node_revert.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ inline void Revert(const reversion cve) {
printf("SECURITY WARNING: Reverting %s\n", RevertMessage(cve));
}

inline void Revert(const char* cve) {
inline void Revert(const char* cve, std::string* error) {
#define V(code, label, _) \
if (strcmp(cve, label) == 0) return Revert(SECURITY_REVERT_##code);
SECURITY_REVERSIONS(V)
#undef V
printf("Error: Attempt to revert an unknown CVE [%s]\n", cve);
exit(12);
*error = "Error: Attempt to revert an unknown CVE [";
*error += cve;
*error += ']';
}

inline bool IsReverted(const reversion cve) {
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-security-revert-unknown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';
require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');

const { signal, status, output } =
spawnSync(process.execPath, ['--security-reverts=not-a-cve']);
assert.strictEqual(signal, null);
assert.strictEqual(status, 12);
assert.strictEqual(
output[2].toString(),
`${process.execPath}: Error: ` +
'Attempt to revert an unknown CVE [not-a-cve]\n');