diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-04-18 00:14:12 -0700 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-04-18 00:14:12 -0700 |
| commit | 7831c4bfef2c340de01ff08461bd7f6a0e54ce32 (patch) | |
| tree | 0726bc6c54ea7c389fcb972a8f672fbee0183153 /node/Utils.hpp | |
| parent | 5f45977e3e3b912269ed5745423ad330be803964 (diff) | |
| download | infinitytier-7831c4bfef2c340de01ff08461bd7f6a0e54ce32.tar.gz infinitytier-7831c4bfef2c340de01ff08461bd7f6a0e54ce32.zip | |
Cleanup, dead code removal, some pretty insignificant security stuff that's based on recommendations.
Diffstat (limited to 'node/Utils.hpp')
| -rw-r--r-- | node/Utils.hpp | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/node/Utils.hpp b/node/Utils.hpp index 4f79aa85..fdec54d1 100644 --- a/node/Utils.hpp +++ b/node/Utils.hpp @@ -86,6 +86,20 @@ public: } /** + * Securely zero memory + * + * This just uses volatile to ensure that it's never optimized out. + */ + static inline void burn(void *ptr,unsigned int len) + throw() + { + volatile unsigned char *p = (unsigned char *)ptr; + volatile unsigned char *e = p + len; + while (p != e) + *(p++) = (unsigned char)0; + } + + /** * Delete a file * * @param path Path to delete @@ -433,20 +447,11 @@ public: static std::string trim(const std::string &s); /** - * Like sprintf, but appends to std::string - * - * @param s String to append to - * @param fmt Printf format string - * @param ... Format arguments - * @throws std::bad_alloc Memory allocation failure - * @throws std::length_error Format + args exceeds internal buffer maximum - */ - static void stdsprintf(std::string &s,const char *fmt,...) - throw(std::bad_alloc,std::length_error); - - /** * Variant of snprintf that is portable and throws an exception * + * This just wraps the local implementation whatever it's called, while + * performing a few other checks and adding exceptions for overflow. + * * @param buf Buffer to write to * @param len Length of buffer in bytes * @param fmt Format string |
