From f3ad05347e55de2fd2a500464acde0979df9941f Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 30 Aug 2013 17:05:43 -0400 Subject: Improve code security posture by replacing sprintf with a safer function. --- node/Utils.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'node/Utils.hpp') diff --git a/node/Utils.hpp b/node/Utils.hpp index 8bced8ad..0d40e370 100644 --- a/node/Utils.hpp +++ b/node/Utils.hpp @@ -536,6 +536,18 @@ public: 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 + * + * @param buf Buffer to write to + * @param len Length of buffer in bytes + * @param fmt Format string + * @param ... Format arguments + * @throws std::length_error buf[] too short (buf[] will still be left null-terminated) + */ + static unsigned int snprintf(char *buf,unsigned int len,const char *fmt,...) + throw(std::length_error); + /** * Count the number of bits set in an integer * -- cgit v1.2.3