shithub: openh264

Download patch

ref: 9b5915326346794a994e574c0d3364a13f52796d
parent: 92fa4eb4000a9f3c33e14d917f133806d857a4a4
author: Martin Storsjö <martin@martin.st>
date: Tue Jan 28 06:35:31 EST 2014

Remove the STRNLEN/WelsStrnlen compatibility functions

These were essentially useless - if strlen() ever was used as
fallback, it either indicated that those ports of the library
were insecure, or that strnlen never was required at all.
In this case it turned out to be the latter (at least after
the preceding cleanups) - all uses of it were with known null
terminated strings.

--- a/codec/common/crt_util_safe_x.cpp
+++ b/codec/common/crt_util_safe_x.cpp
@@ -48,9 +48,6 @@
 #include <sys/timeb.h>
 #ifndef _MSC_VER
 #include <sys/time.h>
-#ifndef HAVE_STRNLEN
-#define strnlen(a,b) strlen(a)
-#endif //!HAVE_STRNLEN
 #endif //!_MSC_VER
 #else
 #include <sys/time.h>
@@ -83,10 +80,6 @@
   return pDest;
 }
 
-int32_t WelsStrnlen (const str_t* kpStr,  int32_t iMaxlen) {
-  return strnlen_s (kpStr, iMaxlen);
-}
-
 int32_t WelsVsnprintf (str_t* pBuffer, int32_t iSizeOfBuffer, const str_t* kpFormat, va_list pArgPtr) {
   return vsnprintf_s (pBuffer, iSizeOfBuffer, _TRUNCATE, kpFormat, pArgPtr);
 }
@@ -143,10 +136,6 @@
   return pDest;
 }
 
-int32_t WelsStrnlen (const str_t* kpStr,  int32_t iMaxlen) {
-  return strlen (kpStr); //confirmed_safe_unsafe_usage
-}
-
 int32_t WelsVsnprintf (str_t* pBuffer, int32_t iSizeOfBuffer, const str_t* kpFormat, va_list pArgPtr) {
   int32_t iRc = vsnprintf (pBuffer, iSizeOfBuffer, kpFormat, pArgPtr); //confirmed_safe_unsafe_usage
   if (iRc < 0)
@@ -201,26 +190,6 @@
 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
 }
-
-#if !defined(MACOS) && !defined(UNIX) && !defined(APPLE_IOS)
-int32_t WelsStrnlen (const str_t* kpStr,  int32_t iMaxlen) {
-  return strnlen (kpStr, iMaxlen); //confirmed_safe_unsafe_usage
-}
-#else
-int32_t WelsStrnlen (const str_t* kpString, int32_t iMaxlen) {
-  // In mac os, there is no strnlen in string.h, we can only use strlen instead of strnlen or
-  // implement strnlen by ourself
-
-#if 1
-  return strlen (kpString); //confirmed_safe_unsafe_usage
-#else
-  const str_t* kpSrc;
-  for (kpSrc = kpString; iMaxlen-- && *kpSrc != '\0'; ++kpSrc)
-    return kpSrc - kpString;
-#endif
-
-}
-#endif
 
 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
--- a/codec/common/crt_util_safe_x.h
+++ b/codec/common/crt_util_safe_x.h
@@ -78,7 +78,6 @@
 int32_t   WelsSnprintf (str_t* buffer,  int32_t sizeOfBuffer,  const str_t* format, ...);
 str_t*   WelsStrncpy (str_t* dest, int32_t sizeInBytes, const str_t* src, int32_t count);
 str_t*   WelsStrcat (str_t* dest, int32_t sizeInBytes, str_t* src);
-int32_t   WelsStrnlen (const str_t* str,  int32_t maxlen);
 int32_t   WelsVsnprintf (str_t* buffer, int32_t sizeOfBuffer, const str_t* format, va_list argptr);
 
 WelsFileHandle*        WelsFopen (const str_t* filename,  const str_t* mode);
@@ -387,35 +386,6 @@
   return (ESNOSPC);
 }
 
-static inline int wels_strnlen_s (const char* dest, int dmax) {
-  int count;
-
-  if (dest == NULL) {
-    return (0);
-  }
-
-  if (dmax <= 0) {
-//        invoke_safe_lib_constraint_handler("strnlen_s: dmax is 0",
-//                   NULL, ESZEROL);
-    return (0);
-  }
-
-//    if (dmax > RSIZE_MAX_STR) {
-//        invoke_safe_lib_constraint_handler("strnlen_s: dmax exceeds max",
-//                   NULL, ESLEMAX);
-//        return (0);
-//    }
-
-  count = 0;
-  while (*dest && dmax) {
-    count++;
-    dmax--;
-    dest++;
-  }
-
-  return (count);
-}
-
 #endif//(WIN32 && _MSC_VER && _MSC_VER<1500) || __GNUC__
 
 #if defined(WIN32) && defined(_MSC_VER)
@@ -422,11 +392,9 @@
 #if _MSC_VER >= 1500	// VS2008
 #define STRNCPY		strncpy_s
 #define STRCAT		strcat_s
-#define STRNLEN		strnlen_s
 #else	// mainly for VC6
 #define STRNCPY		wels_strncpy_s	// override s.t.r.n.c.p.y here for safe
 #define STRCAT		wels_strcat_s	// override s.t.r.c.a.t here for safe
-#define STRNLEN		wels_strnlen_s	// override s.t.r.n.l.e.n here for safe
 #endif//_MSC_VER >= 1500
 
 #else//__GNUC__
@@ -433,7 +401,6 @@
 
 #define STRNCPY		wels_strncpy_s	// override s.t.r.n.c.p.y here for safe
 #define STRCAT		wels_strcat_s	// override s.t.r.c.a.t here for safe
-#define STRNLEN		wels_strnlen_s	// override s.t.r.n.l.e.n here for safe
 
 #endif//WIN32