Skip to content

Commit 35344e8

Browse files
jasnellrvagg
authored andcommittedNov 27, 2018
src: minor cleanup for node_revert
Make the revert related functions inline to eliminate the need for node_revert.cc, prefitx the constants and the def, other misc cleanup PR-URL: #14864 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 811b63c commit 35344e8

File tree

5 files changed

+44
-76
lines changed

5 files changed

+44
-76
lines changed
 

‎node.gyp

-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@
252252
'src/node_file.cc',
253253
'src/node_http_parser.cc',
254254
'src/node_os.cc',
255-
'src/node_revert.cc',
256255
'src/node_url.cc',
257256
'src/node_util.cc',
258257
'src/node_v8.cc',
@@ -887,7 +886,6 @@
887886
'<(OBJ_PATH)/string_search.<(OBJ_SUFFIX)',
888887
'<(OBJ_PATH)/stream_base.<(OBJ_SUFFIX)',
889888
'<(OBJ_PATH)/node_constants.<(OBJ_SUFFIX)',
890-
'<(OBJ_PATH)/node_revert.<(OBJ_SUFFIX)',
891889
],
892890

893891
'defines': [

‎src/node.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ static node_module* modlist_builtin;
162162
static node_module* modlist_linked;
163163
static node_module* modlist_addon;
164164

165+
// Bit flag used to track security reverts (see node_revert.h)
166+
unsigned int reverted = 0;
167+
165168
#if defined(NODE_HAVE_I18N_SUPPORT)
166169
// Path to ICU data (for i18n / Intl)
167170
static std::string icu_data_dir; // NOLINT(runtime/string)
@@ -3413,11 +3416,11 @@ void SetupProcessObject(Environment* env,
34133416
// --security-revert flags
34143417
#define V(code, _, __) \
34153418
do { \
3416-
if (IsReverted(REVERT_ ## code)) { \
3419+
if (IsReverted(SECURITY_REVERT_ ## code)) { \
34173420
READONLY_PROPERTY(process, "REVERT_" #code, True(env->isolate())); \
34183421
} \
34193422
} while (0);
3420-
REVERSIONS(V)
3423+
SECURITY_REVERSIONS(V)
34213424
#undef V
34223425

34233426
size_t exec_path_len = 2 * PATH_MAX;

‎src/node_config.cc

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "env-inl.h"
44
#include "util-inl.h"
55

6-
76
namespace node {
87

98
using v8::Context;

‎src/node_revert.cc

-53
This file was deleted.

‎src/node_revert.h

+39-18
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,55 @@
1212
* 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)