chantra / rpms / tpm2-tss

Forked from rpms/tpm2-tss 2 years ago
Clone

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

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