ref: 7884e77b2dca11583d0e92c779db4f2d0feb8957
parent: 4a8f54d7679ad1f4dc58e5d621635920694a59ea
author: Martin Storsjö <martin@martin.st>
date: Sun Jan 26 09:50:30 EST 2014
Make sure the buffer always is null terminated in the *snprintf calls for old MSVC These functions leave the buffer unterminated in case it was too small.
--- a/codec/common/crt_util_safe_x.cpp
+++ b/codec/common/crt_util_safe_x.cpp
@@ -125,6 +125,8 @@
va_start (pArgPtr, kpFormat);
iRc = vsnprintf (pBuffer, iSizeOfBuffer, kpFormat, pArgPtr); //confirmed_safe_unsafe_usage
+ if (iRc < 0)
+ pBuffer[iSizeOfBuffer - 1] = '\0';
va_end (pArgPtr);
@@ -142,7 +144,10 @@
}
int32_t WelsVsnprintf (str_t* pBuffer, int32_t iSizeOfBuffer, const str_t* kpFormat, va_list pArgPtr) {
- return vsnprintf (pBuffer, iSizeOfBuffer, kpFormat, pArgPtr); //confirmed_safe_unsafe_usage
+ int32_t iRc = vsnprintf (pBuffer, iSizeOfBuffer, kpFormat, pArgPtr); //confirmed_safe_unsafe_usage
+ if (iRc < 0)
+ pBuffer[iSizeOfBuffer - 1] = '\0';
+ return iRc;
}