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

PR-URL: https://github.com/nodejs/node/pull/14864
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
James M Snell 2017-08-16 09:34:37 -07:00
parent b5bad25110
commit 35f6e59dfc
5 changed files with 48 additions and 80 deletions

View File

@ -191,7 +191,6 @@
'src/node_main.cc', 'src/node_main.cc',
'src/node_os.cc', 'src/node_os.cc',
'src/node_platform.cc', 'src/node_platform.cc',
'src/node_revert.cc',
'src/node_serdes.cc', 'src/node_serdes.cc',
'src/node_url.cc', 'src/node_url.cc',
'src/node_util.cc', 'src/node_util.cc',
@ -647,7 +646,6 @@
'<(OBJ_PATH)<(OBJ_SEPARATOR)string_search.<(OBJ_SUFFIX)', '<(OBJ_PATH)<(OBJ_SEPARATOR)string_search.<(OBJ_SUFFIX)',
'<(OBJ_PATH)<(OBJ_SEPARATOR)stream_base.<(OBJ_SUFFIX)', '<(OBJ_PATH)<(OBJ_SEPARATOR)stream_base.<(OBJ_SUFFIX)',
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_constants.<(OBJ_SUFFIX)', '<(OBJ_PATH)<(OBJ_SEPARATOR)node_constants.<(OBJ_SUFFIX)',
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_revert.<(OBJ_SUFFIX)',
'<(OBJ_TRACING_PATH)<(OBJ_SEPARATOR)agent.<(OBJ_SUFFIX)', '<(OBJ_TRACING_PATH)<(OBJ_SEPARATOR)agent.<(OBJ_SUFFIX)',
'<(OBJ_TRACING_PATH)<(OBJ_SEPARATOR)node_trace_buffer.<(OBJ_SUFFIX)', '<(OBJ_TRACING_PATH)<(OBJ_SEPARATOR)node_trace_buffer.<(OBJ_SUFFIX)',
'<(OBJ_TRACING_PATH)<(OBJ_SEPARATOR)node_trace_writer.<(OBJ_SUFFIX)', '<(OBJ_TRACING_PATH)<(OBJ_SEPARATOR)node_trace_writer.<(OBJ_SUFFIX)',

View File

@ -184,6 +184,9 @@ static bool trace_enabled = false;
static std::string trace_enabled_categories; // NOLINT(runtime/string) static std::string trace_enabled_categories; // NOLINT(runtime/string)
static bool abort_on_uncaught_exception = false; static bool abort_on_uncaught_exception = false;
// Bit flag used to track security reverts (see node_revert.h)
unsigned int reverted = 0;
#if defined(NODE_HAVE_I18N_SUPPORT) #if defined(NODE_HAVE_I18N_SUPPORT)
// Path to ICU data (for i18n / Intl) // Path to ICU data (for i18n / Intl)
std::string icu_data_dir; // NOLINT(runtime/string) std::string icu_data_dir; // NOLINT(runtime/string)
@ -3437,11 +3440,11 @@ void SetupProcessObject(Environment* env,
// --security-revert flags // --security-revert flags
#define V(code, _, __) \ #define V(code, _, __) \
do { \ do { \
if (IsReverted(REVERT_ ## code)) { \ if (IsReverted(SECURITY_REVERT_ ## code)) { \
READONLY_PROPERTY(process, "REVERT_" #code, True(env->isolate())); \ READONLY_PROPERTY(process, "REVERT_" #code, True(env->isolate())); \
} \ } \
} while (0); } while (0);
REVERSIONS(V) SECURITY_REVERSIONS(V)
#undef V #undef V
size_t exec_path_len = 2 * PATH_MAX; size_t exec_path_len = 2 * PATH_MAX;

View File

@ -6,7 +6,6 @@
#include "util-inl.h" #include "util-inl.h"
#include "node_debug_options.h" #include "node_debug_options.h"
namespace node { namespace node {
using v8::Boolean; using v8::Boolean;

View File

@ -1,53 +0,0 @@
#include "node_revert.h"
#include <stdio.h>
#include <string.h>
namespace node {
unsigned int reverted = 0;
static const char* RevertMessage(const unsigned int cve) {
#define V(code, label, msg) case REVERT_ ## code: return label ": " msg;
switch (cve) {
REVERSIONS(V)
default:
return "Unknown";
}
#undef V
}
void Revert(const unsigned int cve) {
reverted |= 1 << cve;
printf("SECURITY WARNING: Reverting %s\n", RevertMessage(cve));
}
void Revert(const char* cve) {
#define V(code, label, _) \
do { \
if (strcmp(cve, label) == 0) { \
Revert(static_cast<unsigned int>(REVERT_ ## code)); \
return; \
} \
} while (0);
REVERSIONS(V)
#undef V
printf("Error: Attempt to revert an unknown CVE [%s]\n", cve);
exit(12);
}
bool IsReverted(const unsigned int cve) {
return reverted & (1 << cve);
}
bool IsReverted(const char * cve) {
#define V(code, label, _) \
do { \
if (strcmp(cve, label) == 0) \
return IsReverted(static_cast<unsigned int>(REVERT_ ## code)); \
} while (0);
REVERSIONS(V)
return false;
#undef V
}
} // namespace node

View File

@ -12,34 +12,55 @@
* consensus. * consensus.
* *
* For *master* this list should always be empty! * For *master* this list should always be empty!
*
**/ **/
#define REVERSIONS(XX)
// XX(CVE_2016_PEND, "CVE-2016-PEND", "Vulnerability Title")
namespace node { namespace node {
typedef enum { #define SECURITY_REVERSIONS(XX)
#define V(code, _, __) REVERT_ ## code, // XX(CVE_2016_PEND, "CVE-2016-PEND", "Vulnerability Title")
REVERSIONS(V)
enum reversion {
#define V(code, ...) SECURITY_REVERT_##code,
SECURITY_REVERSIONS(V)
#undef V #undef V
} reversions_t; };
/* A bit field for tracking the active reverts */
extern unsigned int reverted; extern unsigned int reverted;
/* Revert the given CVE (see reversions_t enum) */ inline const char* RevertMessage(const reversion cve) {
void Revert(const unsigned int cve); #define V(code, label, msg) case SECURITY_REVERT_##code: return label ": " msg;
switch (cve) {
SECURITY_REVERSIONS(V)
default:
return "Unknown";
}
#undef V
}
/* Revert the given CVE by label */ inline void Revert(const reversion cve) {
void Revert(const char* cve); reverted |= 1 << cve;
printf("SECURITY WARNING: Reverting %s\n", RevertMessage(cve));
}
/* true if the CVE has been reverted **/ inline void Revert(const char* cve) {
bool IsReverted(const unsigned int cve); #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);
}
/* true if the CVE has been reverted **/ inline bool IsReverted(const reversion cve) {
bool IsReverted(const char * cve); return reverted & (1 << cve);
}
inline bool IsReverted(const char* cve) {
#define V(code, label, _) \
if (strcmp(cve, label) == 0) return IsReverted(SECURITY_REVERT_##code);
SECURITY_REVERSIONS(V)
return false;
#undef V
}
} // namespace node } // namespace node