shithub: openh264

Download patch

ref: a16ccc0b4d7abae3e9a02e2ceed4150e2d0ab994
parent: 74e7c9b6d867395e0c60b7a186e0313c088d8961
author: Martin Storsjö <martin@martin.st>
date: Tue Jan 28 07:08:35 EST 2014

Fix the implementations of WelsStrncpy

Make the MSVC "safe" version truncate instead of aborting the
process if the buffer is too small.

Update all the other functions to use the right parameter
(iSizeInBytes, not iCount) as 'n' parameter to strncpy.
(By passing iCount as parameter to the normal strncpy functions,
it meant that the resulting buffer actually never was null
terminated.)

Additionally make sure that the other implementations of WelsStrncpy
always null terminate the resulting buffer, just as the MSVC safe
version does when passed the _TRUNCATE parameter.

--- a/codec/common/crt_util_safe_x.cpp
+++ b/codec/common/crt_util_safe_x.cpp
@@ -75,7 +75,7 @@
 }
 
 str_t* WelsStrncpy (str_t* pDest, int32_t iSizeInBytes, const str_t* kpSrc, int32_t iCount) {
-  strncpy_s (pDest, iSizeInBytes, kpSrc, iCount);
+  strncpy_s (pDest, iSizeInBytes, kpSrc, _TRUNCATE);
 
   return pDest;
 }
@@ -131,7 +131,8 @@
 }
 
 str_t* WelsStrncpy (str_t* pDest, int32_t iSizeInBytes, const str_t* kpSrc, int32_t iCount) {
-  strncpy (pDest, kpSrc, iCount); //confirmed_safe_unsafe_usage
+  strncpy (pDest, kpSrc, iSizeInBytes); //confirmed_safe_unsafe_usage
+  pDest[iSizeInBytes - 1] = '\0';
 
   return pDest;
 }
@@ -188,7 +189,9 @@
 }
 
 str_t* WelsStrncpy (str_t* pDest, int32_t iSizeInBytes, const str_t* kpSrc, int32_t iCount) {
-  return strncpy (pDest, kpSrc, iCount); //confirmed_safe_unsafe_usage
+  strncpy (pDest, kpSrc, iSizeInBytes); //confirmed_safe_unsafe_usage
+  pDest[iSizeInBytes - 1] = '\0';
+  return pDest;
 }
 
 int32_t WelsVsnprintf (str_t* pBuffer, int32_t iSizeOfBuffer, const str_t* kpFormat, va_list pArgPtr) {