|
6 | 6 | #include "node.h"
|
7 | 7 |
|
8 | 8 | /**
|
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. |
13 | 13 | *
|
14 | 14 | * For *master* this list should always be empty!
|
15 |
| - * |
16 | 15 | **/
|
17 |
| -#define REVERSIONS(XX) |
18 |
| -// XX(CVE_2016_PEND, "CVE-2016-PEND", "Vulnerability Title") |
19 |
| - |
20 | 16 | namespace node {
|
21 | 17 |
|
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") |
27 | 20 |
|
| 21 | +enum reversion { |
| 22 | +#define V(code, ...) SECURITY_REVERT_##code, |
| 23 | + SECURITY_REVERSIONS(V) |
| 24 | +#undef V |
| 25 | +}; |
28 | 26 |
|
29 |
| -/* A bit field for tracking the active reverts */ |
30 | 27 | extern unsigned int reverted;
|
31 | 28 |
|
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 | +} |
34 | 38 |
|
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 | +} |
37 | 43 |
|
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 | +} |
40 | 52 |
|
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 | +} |
43 | 64 |
|
44 | 65 | } // namespace node
|
45 | 66 |
|
|
0 commit comments