mirror of
https://github.com/znc/znc.git
synced 2026-05-08 22:34:45 +02:00
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. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1671 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
@@ -198,17 +198,16 @@ CString CUser::AddTimestamp(const CString& sStr) const {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user