Skip to content

Commit 714c716

Browse files
committed
src: minor cleanup for node_revert
Make the revert related functions inline to eliminate the need for node_revert.cc, prefix the constants and the def, other misc cleanup
1 parent b5bad25 commit 714c716

File tree

5 files changed

+48
-80
lines changed

5 files changed

+48
-80
lines changed

node.gyp

-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@
191191
'src/node_main.cc',
192192
'src/node_os.cc',
193193
'src/node_platform.cc',
194-
'src/node_revert.cc',
195194
'src/node_serdes.cc',
196195
'src/node_url.cc',
197196
'src/node_util.cc',
@@ -647,7 +646,6 @@
647646
'<(OBJ_PATH)<(OBJ_SEPARATOR)string_search.<(OBJ_SUFFIX)',
648647
'<(OBJ_PATH)<(OBJ_SEPARATOR)stream_base.<(OBJ_SUFFIX)',
649648
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_constants.<(OBJ_SUFFIX)',
650-
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_revert.<(OBJ_SUFFIX)',
651649
'<(OBJ_TRACING_PATH)<(OBJ_SEPARATOR)agent.<(OBJ_SUFFIX)',
652650
'<(OBJ_TRACING_PATH)<(OBJ_SEPARATOR)node_trace_buffer.<(OBJ_SUFFIX)',
653651
'<(OBJ_TRACING_PATH)<(OBJ_SEPARATOR)node_trace_writer.<(OBJ_SUFFIX)',

src/node.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ static bool trace_enabled = false;
184184
static std::string trace_enabled_categories; // NOLINT(runtime/string)
185185
static bool abort_on_uncaught_exception = false;
186186

187+
// Bit flag used to track security reverts (see node_revert.h)
188+
unsigned int reverted = 0;
189+
187190
#if defined(NODE_HAVE_I18N_SUPPORT)
188191
// Path to ICU data (for i18n / Intl)
189192
std::string icu_data_dir; // NOLINT(runtime/string)
@@ -3437,11 +3440,11 @@ void SetupProcessObject(Environment* env,
34373440
// --security-revert flags
34383441
#define V(code, _, __) \
34393442
do { \
3440-
if (IsReverted(REVERT_ ## code)) { \
3443+
if (IsReverted(SECURITY_REVERT_ ## code)) { \
34413444
READONLY_PROPERTY(process, "REVERT_" #code, True(env->isolate())); \
34423445
} \
34433446
} while (0);
3444-
REVERSIONS(V)
3447+
SECURITY_REVERSIONS(V)
34453448
#undef V
34463449

34473450
size_t exec_path_len = 2 * PATH_MAX;

src/node_config.cc

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "util-inl.h"
77
#include "node_debug_options.h"
88

9-
109
namespace node {
1110

1211
using v8::Boolean;

src/node_revert.cc

-53
This file was deleted.

src/node_revert.h

+43-22
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,61 @@
66
#include "node.h"
77

88
/**
9-
* Note that it is expected for this list to vary across specific LTS and
10-
* Stable versions! Only CVE's whose fixes require *breaking* changes within
11-
* a given LTS or Stable may be added to this list, and only with CTC
12-
* consensus.
9+
* Note that it is expected for this list to vary across specific LTS and
10+
* Stable versions! Only CVE's whose fixes require *breaking* changes within
11+
* a given LTS or Stable may be added to this list, and only with CTC
12+
* consensus.
1313
*
1414
* For *master* this list should always be empty!
15-
*
1615
**/
17-
#define REVERSIONS(XX)
18-
// XX(CVE_2016_PEND, "CVE-2016-PEND", "Vulnerability Title")
19-
2016
namespace node {
2117

22-
typedef enum {
23-
#define V(code, _, __) REVERT_ ## code,
24-
REVERSIONS(V)
25-
#undef V
26-
} reversions_t;
18+
#define SECURITY_REVERSIONS(XX)
19+
// XX(CVE_2016_PEND, "CVE-2016-PEND", "Vulnerability Title")
2720

21+
enum reversion {
22+
#define V(code, ...) SECURITY_REVERT_##code,
23+
SECURITY_REVERSIONS(V)
24+
#undef V
25+
};
2826

29-
/* A bit field for tracking the active reverts */
3027
extern unsigned int reverted;
3128

32-
/* Revert the given CVE (see reversions_t enum) */
33-
void Revert(const unsigned int cve);
29+
inline const char* RevertMessage(const reversion cve) {
30+
#define V(code, label, msg) case SECURITY_REVERT_##code: return label ": " msg;
31+
switch (cve) {
32+
SECURITY_REVERSIONS(V)
33+
default:
34+
return "Unknown";
35+
}
36+
#undef V
37+
}
3438

35-
/* Revert the given CVE by label */
36-
void Revert(const char* cve);
39+
inline void Revert(const reversion cve) {
40+
reverted |= 1 << cve;
41+
printf("SECURITY WARNING: Reverting %s\n", RevertMessage(cve));
42+
}
3743

38-
/* true if the CVE has been reverted **/
39-
bool IsReverted(const unsigned int cve);
44+
inline void Revert(const char* cve) {
45+
#define V(code, label, _) \
46+
if (strcmp(cve, label) == 0) return Revert(SECURITY_REVERT_##code);
47+
SECURITY_REVERSIONS(V)
48+
#undef V
49+
printf("Error: Attempt to revert an unknown CVE [%s]\n", cve);
50+
exit(12);
51+
}
4052

41-
/* true if the CVE has been reverted **/
42-
bool IsReverted(const char * cve);
53+
inline bool IsReverted(const reversion cve) {
54+
return reverted & (1 << cve);
55+
}
56+
57+
inline bool IsReverted(const char* cve) {
58+
#define V(code, label, _) \
59+
if (strcmp(cve, label) == 0) return IsReverted(SECURITY_REVERT_##code);
60+
SECURITY_REVERSIONS(V)
61+
return false;
62+
#undef V
63+
}
4364

4465
} // namespace node
4566

0 commit comments

Comments
 (0)