src: add --security-revert command line flag
[platform/upstream/nodejs.git] / src / node_revert.cc
1 #include "node_revert.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 namespace node {
6
7 unsigned int reverted = 0;
8
9 const char* RevertMessage(const unsigned int cve) {
10 #define V(code, label, msg) case REVERT_ ## code: return label ": " msg;
11   switch (cve) {
12     REVERSIONS(V)
13     default:
14       return "Unknown";
15   }
16 #undef V
17 }
18
19 void Revert(const unsigned int cve) {
20   reverted |= 1 << cve;
21   printf("SECURITY WARNING: Reverting %s\n", RevertMessage(cve));
22 }
23
24 void Revert(const char* cve) {
25 #define V(code, label, _)                                                     \
26   do {                                                                        \
27     if (strcmp(cve, label) == 0) {                                            \
28       Revert(REVERT_ ## code);                                                \
29       return;                                                                 \
30     }                                                                         \
31   } while (0);
32   REVERSIONS(V)
33 #undef V
34   printf("Error: Attempt to revert an unknown CVE [%s]\n", cve);
35   exit(12);
36 }
37
38 bool IsReverted(const unsigned int cve) {
39   return reverted & (1 << cve);
40 }
41
42 bool IsReverted(const char * cve) {
43 #define V(code, label, _)                                                     \
44   do {                                                                        \
45     if (strcmp(cve, label) == 0)                                              \
46       return IsReverted(REVERT_ ## code);                                    \
47   } while (0);
48   REVERSIONS(V)
49   return false;
50 #undef V
51 }
52
53 }  // namespace node