mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-30 23:11:10 +00:00
Quit using readdir_r()
Prone to buffer overflows on some platforms.
This commit is contained in:
parent
fbae2a1f53
commit
964bf9b92f
|
@ -93,17 +93,6 @@
|
||||||
*/
|
*/
|
||||||
//#define POLARSSL_HAVE_SSE2
|
//#define POLARSSL_HAVE_SSE2
|
||||||
|
|
||||||
/**
|
|
||||||
* \def POLARSSL_HAVE_READDIR_R
|
|
||||||
*
|
|
||||||
* (Non Windows) System has readdir_r().
|
|
||||||
*
|
|
||||||
* Required for x509_crt_parse_path() in non-Windows systems.
|
|
||||||
*
|
|
||||||
* Comment if your system does not have support.
|
|
||||||
*/
|
|
||||||
#define POLARSSL_HAVE_READDIR_R
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \def POLARSSL_HAVE_TIME
|
* \def POLARSSL_HAVE_TIME
|
||||||
*
|
*
|
||||||
|
|
|
@ -991,26 +991,20 @@ int x509_crt_parse_path( x509_crt *chain, const char *path )
|
||||||
|
|
||||||
FindClose( hFind );
|
FindClose( hFind );
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
#if defined(POLARSSL_HAVE_READDIR_R)
|
int t_ret;
|
||||||
int t_ret, i;
|
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
struct dirent entry, *result = NULL;
|
struct dirent *entry;
|
||||||
char entry_name[255];
|
char entry_name[255];
|
||||||
DIR *dir = opendir( path );
|
DIR *dir = opendir( path );
|
||||||
|
|
||||||
if( dir == NULL)
|
if( dir == NULL)
|
||||||
return( POLARSSL_ERR_X509_FILE_IO_ERROR );
|
return( POLARSSL_ERR_X509_FILE_IO_ERROR );
|
||||||
|
|
||||||
while( ( t_ret = readdir_r( dir, &entry, &result ) ) == 0 )
|
while( ( entry = readdir( dir ) ) != NULL )
|
||||||
{
|
{
|
||||||
if( result == NULL )
|
snprintf( entry_name, sizeof entry_name, "%s/%s", path, entry->d_name );
|
||||||
break;
|
|
||||||
|
|
||||||
snprintf( entry_name, sizeof(entry_name), "%s/%s", path, entry.d_name );
|
if( stat( entry_name, &sb ) == -1 )
|
||||||
|
|
||||||
i = stat( entry_name, &sb );
|
|
||||||
|
|
||||||
if( i == -1 )
|
|
||||||
{
|
{
|
||||||
closedir( dir );
|
closedir( dir );
|
||||||
return( POLARSSL_ERR_X509_FILE_IO_ERROR );
|
return( POLARSSL_ERR_X509_FILE_IO_ERROR );
|
||||||
|
@ -1028,11 +1022,6 @@ int x509_crt_parse_path( x509_crt *chain, const char *path )
|
||||||
ret += t_ret;
|
ret += t_ret;
|
||||||
}
|
}
|
||||||
closedir( dir );
|
closedir( dir );
|
||||||
#else /* POLARSSL_HAVE_READDIR_R */
|
|
||||||
((void) chain);
|
|
||||||
((void) path);
|
|
||||||
ret = POLARSSL_ERR_X509_FEATURE_UNAVAILABLE;
|
|
||||||
#endif /* POLARSSL_HAVE_READDIR_R */
|
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
|
|
Loading…
Reference in a new issue