From: Kevin Kane Date: Wed, 12 Oct 2016 23:30:01 +0000 (-0700) Subject: [IOT-1449] mbedTLS: Use wcslen instead of lstrlenW on Windows X-Git-Tag: 1.3.0~1055^2~57 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=840701a3c101081a103b3a431f3fe504e759e3ce;p=platform%2Fupstream%2Fiotivity.git [IOT-1449] mbedTLS: Use wcslen instead of lstrlenW on Windows 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/13183 Tested-by: jenkins-iotivity Reviewed-by: Dave Thaler Reviewed-by: Randeep Singh (cherry picked from commit aa49bbd28a78a486df9568b3867a373100e92e2f) Reviewed-on: https://gerrit.iotivity.org/gerrit/13207 --- diff --git a/extlibs/mbedtls/ocf.patch b/extlibs/mbedtls/ocf.patch index f2801a3..a12e74e 100644 --- a/extlibs/mbedtls/ocf.patch +++ b/extlibs/mbedtls/ocf.patch @@ -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 ++#include + #else + #include + #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 )