[IOT-1449] mbedTLS: Use wcslen instead of lstrlenW on Windows
authorKevin Kane <kkane@microsoft.com>
Wed, 12 Oct 2016 23:30:01 +0000 (16:30 -0700)
committerRandeep Singh <randeep.s@samsung.com>
Thu, 13 Oct 2016 07:54:27 +0000 (07:54 +0000)
lstrlenW is not allowed in Windows Store applications. Use wcslen
instead.

Also fix a nearby narrowing size_t to int conversion to make sure
it's safe.

Change-Id: I14d37b6a0d6c82444f4733f5d54bd8173ca62b71
Signed-off-by: Kevin Kane <kkane@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13183
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Dave Thaler <dthaler@microsoft.com>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
(cherry picked from commit aa49bbd28a78a486df9568b3867a373100e92e2f)
Reviewed-on: https://gerrit.iotivity.org/gerrit/13207

extlibs/mbedtls/ocf.patch

index f2801a3..a12e74e 100644 (file)
@@ -593,3 +593,48 @@ index 5d20ba0..6404a0c 100644
  #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
      "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED",
  #endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED */
+diff --git a/library/x509_crt.c b/library/x509_crt.c
+index af6c2a4..6dcb6aa 100644
+--- a/library/x509_crt.c
++++ b/library/x509_crt.c
+@@ -62,6 +62,7 @@
+ #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
+ #include <windows.h>
++#include <intsafe.h>
+ #else
+ #include <time.h>
+ #endif
+@@ -1108,6 +1109,7 @@ int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path )
+     char filename[MAX_PATH];
+     char *p;
+     size_t len = strlen( path );
++    int lengthAsInt = 0;
+     WIN32_FIND_DATAW file_data;
+     HANDLE hFind;
+@@ -1122,7 +1124,10 @@ int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path )
+     p = filename + len;
+     filename[len++] = '*';
+-    w_ret = MultiByteToWideChar( CP_ACP, 0, filename, len, szDir,
++    if ( FAILED ( SizeTToInt( len, &lengthAsInt ) ) )
++        return( MBEDTLS_ERR_X509_FILE_IO_ERROR );
++
++    w_ret = MultiByteToWideChar( CP_ACP, 0, filename, lengthAsInt, szDir,
+                                  MAX_PATH - 3 );
+     if( w_ret == 0 )
+         return( MBEDTLS_ERR_X509_BAD_INPUT_DATA );
+@@ -1139,8 +1144,11 @@ int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path )
+         if( file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
+             continue;
++        if ( FAILED( SizeTToInt( wcslen( file_data.cFileName ), &lengthAsInt ) ) )
++            return( MBEDTLS_ERR_X509_FILE_IO_ERROR );
++
+         w_ret = WideCharToMultiByte( CP_ACP, 0, file_data.cFileName,
+-                                     lstrlenW( file_data.cFileName ),
++                                     lengthAsInt,
+                                      p, (int) len - 1,
+                                      NULL, NULL );
+         if( w_ret == 0 )