Blame SOURCES/0001-tctildr-remove-the-private-implementation-of-strndup.patch

232964
From 464da22b71e26421f55d4e8abc14711f89c89a28 Mon Sep 17 00:00:00 2001
232964
From: Tadeusz Struk <tadeusz.struk@intel.com>
232964
Date: Thu, 20 Feb 2020 14:11:43 -0800
232964
Subject: [PATCH] tctildr: remove the private implementation of strndup
232964
232964
In fact the private implementation of strndup is only
232964
needed for windows.
232964
232964
Fixes: #1633
232964
232964
Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>
232964
---
232964
 configure.ac            |  2 +-
232964
 src/tss2-tcti/tctildr.c | 37 +++++++++++++++++--------------------
232964
 2 files changed, 18 insertions(+), 21 deletions(-)
232964
232964
diff --git a/configure.ac b/configure.ac
232964
index d7724805966b..aa4ffb1b78a1 100644
232964
--- a/configure.ac
232964
+++ b/configure.ac
232964
@@ -45,7 +45,6 @@ case "${host_os}" in
232964
 esac
232964
 AC_SUBST([LIBSOCKET_LDFLAGS])
232964
 
232964
-AC_CHECK_FUNCS([strndup])
232964
 AC_ARG_ENABLE([unit],
232964
             [AS_HELP_STRING([--enable-unit],
232964
                             [build cmocka unit tests])],,
232964
@@ -65,6 +64,7 @@ AC_ARG_ENABLE([esapi],
232964
 
232964
 AM_CONDITIONAL(ESAPI, test "x$enable_esapi" = "xyes")
232964
 
232964
+AC_CHECK_FUNC([strndup],[],[AC_MSG_ERROR([strndup function not found])])
232964
 AC_ARG_ENABLE([tcti-device-async],
232964
     AS_HELP_STRING([--enable-tcti-device-async],
232964
 	           [Enable asynchronus operation on TCTI device
232964
diff --git a/src/tss2-tcti/tctildr.c b/src/tss2-tcti/tctildr.c
232964
index a46b301b3ea7..92af1d3a787d 100644
232964
--- a/src/tss2-tcti/tctildr.c
232964
+++ b/src/tss2-tcti/tctildr.c
232964
@@ -15,8 +15,25 @@
232964
 #include <linux/limits.h>
232964
 #elif defined(_MSC_VER)
232964
 #include <windows.h>
232964
+#include <limits.h>
232964
 #ifndef PATH_MAX
232964
 #define PATH_MAX MAX_PATH
232964
+
232964
+static char *strndup(const char* s, size_t n)
232964
+{
232964
+    char *dst = NULL;
232964
+
232964
+    if (n + 1 >= USHRT_MAX)
232964
+        return NULL;
232964
+
232964
+    dst = calloc(1, n + 1);
232964
+
232964
+    if (dst == NULL)
232964
+        return NULL;
232964
+
232964
+    memcpy(dst, s, n);
232964
+    return dst;
232964
+}
232964
 #endif
232964
 #else
232964
 #include <limits.h>
232964
@@ -268,26 +285,6 @@ Tss2_TctiLdr_Finalize (TSS2_TCTI_CONTEXT **tctiContext)
232964
     *tctiContext = NULL;
232964
 }
232964
 
232964
-#if !defined(HAVE_STRNDUP)
232964
-char*
232964
-strndup (const char* s,
232964
-         size_t n)
232964
-{
232964
-    char* dst = NULL;
232964
-
232964
-    if (n + 1 < n) {
232964
-        return NULL;
232964
-    }
232964
-    dst = calloc(1, n + 1);
232964
-    if (dst == NULL) {
232964
-        return NULL;
232964
-    }
232964
-    memcpy(dst, s, n);
232964
-
232964
-    return dst;
232964
-}
232964
-#endif /* HAVE_STRNDUP */
232964
-
232964
 TSS2_RC
232964
 copy_info (const TSS2_TCTI_INFO *info_src,
232964
            TSS2_TCTI_INFO *info_dst)
232964
-- 
232964
2.30.1
232964