From 7831c4bfef2c340de01ff08461bd7f6a0e54ce32 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 18 Apr 2014 00:14:12 -0700 Subject: Cleanup, dead code removal, some pretty insignificant security stuff that's based on recommendations. --- node/Utils.hpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'node/Utils.hpp') diff --git a/node/Utils.hpp b/node/Utils.hpp index 4f79aa85..fdec54d1 100644 --- a/node/Utils.hpp +++ b/node/Utils.hpp @@ -85,6 +85,20 @@ public: return (diff == 0ULL); } + /** + * 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 * @@ -432,21 +446,12 @@ 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 -- cgit v1.2.3