chantra / rpms / tpm2-tss

Forked from rpms/tpm2-tss 2 years ago
Clone

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

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