diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2017-02-13 09:03:48 -0800 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2017-02-13 09:03:48 -0800 |
| commit | 42f28bce52c3342e3aac68488260a02c71691177 (patch) | |
| tree | 230f1d73d8ea82ee4804d2dcc982a1c6bbe9a833 /node/Utils.cpp | |
| parent | cdc289fa9c5d7d19990c14946ede5f3642e235d2 (diff) | |
| download | infinitytier-42f28bce52c3342e3aac68488260a02c71691177.tar.gz infinitytier-42f28bce52c3342e3aac68488260a02c71691177.zip | |
Cleanup and make moons (federated roots) a little easier to deal with.
Diffstat (limited to 'node/Utils.cpp')
| -rw-r--r-- | node/Utils.cpp | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/node/Utils.cpp b/node/Utils.cpp index 00b0db06..fb448dd6 100644 --- a/node/Utils.cpp +++ b/node/Utils.cpp @@ -47,21 +47,14 @@ namespace ZeroTier { const char Utils::HEXCHARS[16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' }; -static void _Utils_doBurn(char *ptr,unsigned int len) +// Crazy hack to force memory to be securely zeroed in spite of the best efforts of optimizing compilers. +static void _Utils_doBurn(volatile uint8_t *ptr,unsigned int len) { - for(unsigned int i=0;i<len;++i) - ptr[i] = (char)0; -} -void (*volatile _Utils_doBurn_ptr)(char *,unsigned int) = _Utils_doBurn; -void Utils::burn(void *ptr,unsigned int len) - throw() -{ - // Ridiculous hack: call _doBurn() via a volatile function pointer to - // hold down compiler optimizers and beat them mercilessly until they - // cry and mumble something about never eliding secure memory zeroing - // again. - (_Utils_doBurn_ptr)((char *)ptr,len); + volatile uint8_t *const end = ptr + len; + while (ptr != end) *(ptr++) = (uint8_t)0; } +static void (*volatile _Utils_doBurn_ptr)(volatile uint8_t *,unsigned int) = _Utils_doBurn; +void Utils::burn(void *ptr,unsigned int len) { (_Utils_doBurn_ptr)((volatile uint8_t *)ptr,len); } std::string Utils::hex(const void *data,unsigned int len) { |
