From: <ps...@us...> - 2009-11-30 18:16:29
|
Revision: 1671 http://znc.svn.sourceforge.net/znc/?rev=1671&view=rev Author: psychon Date: 2009-11-30 18:16:16 +0000 (Mon, 30 Nov 2009) Log Message: ----------- Really check the return value of strftime() If strftime() returns 0, the buffer we passed to it shouldn't be touched at all, because it's not guaranteed to be null-terminated. Someone (*cough*) already tried to fix this in r1394, but failed badly. Thanks to DarthGandalf for spotting this and providing a patch. Modified Paths: -------------- trunk/User.cpp Modified: trunk/User.cpp =================================================================== --- trunk/User.cpp 2009-11-29 15:17:39 UTC (rev 1670) +++ trunk/User.cpp 2009-11-30 18:16:16 UTC (rev 1671) @@ -198,17 +198,16 @@ CString& CUser::AddTimestamp(const CString& sStr, CString& sRet) const { char szTimestamp[1024]; time_t tm; + sRet = sStr; - if (GetTimestampFormat().empty() || (!m_bAppendTimestamp && !m_bPrependTimestamp)) { - sRet = sStr; - } else { + if (!GetTimestampFormat().empty() && (m_bAppendTimestamp || m_bPrependTimestamp)) { time(&tm); tm += (time_t)(m_fTimezoneOffset * 60 * 60); // offset is in hours size_t i = strftime(szTimestamp, sizeof(szTimestamp), GetTimestampFormat().c_str(), localtime(&tm)); - if (i != 0) { - sRet = sStr; - } else { - sRet.clear(); + // If strftime returns 0, an error occured in format, or result is empty + // In both cases just don't prepend/append anything to our string + if (0 == i) { + return sRet; } if (m_bPrependTimestamp) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |