ref: e7e3b4f37f0bfdadcb779e22d40a77dbe31cc87a
parent: b37cda248234162033e3e11b0335f3131cdfe488
author: Haibo Zhu <haibozhu@cisco.com>
date: Sat Oct 10 04:45:48 EDT 2015
Init the string value and add protection for WelsStrcat()
--- a/codec/common/inc/crt_util_safe_x.h
+++ b/codec/common/inc/crt_util_safe_x.h
@@ -79,7 +79,7 @@
int32_t WelsSnprintf (char* buffer, int32_t sizeOfBuffer, const char* format, ...);
char* WelsStrncpy (char* dest, int32_t sizeInBytes, const char* src);
-char* WelsStrcat (char* dest, int32_t sizeInBytes, const char* src);
+char* WelsStrcat (char* dest, uint32_t sizeInBytes, const char* src);
int32_t WelsVsnprintf (char* buffer, int32_t sizeOfBuffer, const char* format, va_list argptr);
WelsFileHandle* WelsFopen (const char* filename, const char* mode);
--- a/codec/common/src/crt_util_safe_x.cpp
+++ b/codec/common/src/crt_util_safe_x.cpp
@@ -75,8 +75,8 @@
return iRc;
}
-char* WelsStrncpy (char* pDest, int32_t iSizeInBytes, const char* kpSrc) {
- strncpy_s (pDest, iSizeInBytes, kpSrc, _TRUNCATE);
+char* WelsStrncpy (char* pDest, uint32_t uiSizeInBytes, const char* kpSrc) {
+ strncpy_s (pDest, uiSizeInBytes, kpSrc, _TRUNCATE);
return pDest;
}
@@ -242,9 +242,11 @@
#endif
-char* WelsStrcat (char* pDest, int32_t iSizeInBytes, const char* kpSrc) {
- int32_t iCurLen = (int32_t)strlen (pDest);
- return WelsStrncpy (pDest + iCurLen, iSizeInBytes - iCurLen, kpSrc);
+char* WelsStrcat (char* pDest, uint32_t uiSizeInBytes, const char* kpSrc) {
+ uint32_t uiCurLen = strlen (pDest);
+ if (uiSizeInBytes > uiCurLen)
+ return WelsStrncpy (pDest + uiCurLen, uiSizeInBytes - uiCurLen, kpSrc);
+ return pDest;
}
int32_t WelsFwrite (const void* kpBuffer, int32_t iSize, int32_t iCount, WelsFileHandle* pFp) {
--- a/codec/common/src/utils.cpp
+++ b/codec/common/src/utils.cpp
@@ -50,7 +50,7 @@
void WelsLog (SLogContext* logCtx, int32_t iLevel, const char* kpFmt, ...) {
va_list vl;
- char pTraceTag[MAX_LOG_SIZE];
+ char pTraceTag[MAX_LOG_SIZE] = {0};
switch (iLevel) {
case WELS_LOG_ERROR:
WelsSnprintf (pTraceTag, MAX_LOG_SIZE, "[OpenH264] this = 0x%p, Error:", logCtx->pCodecInstance);