shithub: openh264

Download patch

ref: c7b74b2b129e02981c1decb0aa98452a4d0381b3
parent: 7884e77b2dca11583d0e92c779db4f2d0feb8957
author: Martin Storsjö <martin@martin.st>
date: Sun Jan 26 09:48:38 EST 2014

Make sure the buffer is null terminated after strftime

If the buffer is too small, there's no guarantee that it is
null terminated. The docs (on both unix and MSVC) say explicitly
that the function returns 0 and the buffer contents are
indeterminate in this case.

--- a/codec/common/crt_util_safe_x.cpp
+++ b/codec/common/crt_util_safe_x.cpp
@@ -110,10 +110,14 @@
 
 int32_t WelsStrftime (str_t* pBuffer, int32_t iSize, const str_t* kpFormat, const SWelsTime* kpTp) {
   struct tm   sTimeNow;
+  int32_t iRc;
 
   localtime_s (&sTimeNow, &kpTp->time);
 
-  return strftime (pBuffer, iSize, kpFormat, &sTimeNow);
+  iRc = strftime (pBuffer, iSize, kpFormat, &sTimeNow);
+  if (iRc == 0)
+      pBuffer[0] = '\0';
+  return iRc;
 }
 
 #else
@@ -166,10 +170,14 @@
 
 int32_t WelsStrftime (str_t* pBuffer, int32_t iSize, const str_t* kpFormat, const SWelsTime* kpTp) {
   struct tm*   pTnow;
+  int32_t iRc;
 
   pTnow = localtime (&kpTp->time);
 
-  return strftime (pBuffer, iSize, kpFormat, pTnow);
+  iRc = strftime (pBuffer, iSize, kpFormat, pTnow);
+  if (iRc == 0)
+      pBuffer[0] = '\0';
+  return iRc;
 }
 
 
@@ -241,10 +249,14 @@
 
 int32_t WelsStrftime (str_t* pBuffer, int32_t iSize, const str_t* kpFormat, const SWelsTime* kpTp) {
   struct tm*   pTnow;
+  int32_t iRc;
 
   pTnow = localtime (&kpTp->time);
 
-  return strftime (pBuffer, iSize, kpFormat, pTnow);
+  iRc = strftime (pBuffer, iSize, kpFormat, pTnow);
+  if (iRc == 0)
+      pBuffer[0] = '\0';
+  return iRc;
 }
 
 #endif