Quit using readdir_r()
Prone to buffer overflows on some platforms.
diff --git a/library/x509_crt.c b/library/x509_crt.c
index 6382c53..5330bf1 100644
--- a/library/x509_crt.c
+++ b/library/x509_crt.c
@@ -991,26 +991,20 @@
FindClose( hFind );
#else /* _WIN32 */
-#if defined(POLARSSL_HAVE_READDIR_R)
- int t_ret, i;
+ int t_ret;
struct stat sb;
- struct dirent entry, *result = NULL;
+ struct dirent *entry;
char entry_name[255];
DIR *dir = opendir( path );
if( dir == NULL)
return( POLARSSL_ERR_X509_FILE_IO_ERROR );
- while( ( t_ret = readdir_r( dir, &entry, &result ) ) == 0 )
+ while( ( entry = readdir( dir ) ) != NULL )
{
- if( result == NULL )
- break;
+ snprintf( entry_name, sizeof entry_name, "%s/%s", path, entry->d_name );
- snprintf( entry_name, sizeof(entry_name), "%s/%s", path, entry.d_name );
-
- i = stat( entry_name, &sb );
-
- if( i == -1 )
+ if( stat( entry_name, &sb ) == -1 )
{
closedir( dir );
return( POLARSSL_ERR_X509_FILE_IO_ERROR );
@@ -1028,11 +1022,6 @@
ret += t_ret;
}
closedir( dir );
-#else /* POLARSSL_HAVE_READDIR_R */
- ((void) chain);
- ((void) path);
- ret = POLARSSL_ERR_X509_FEATURE_UNAVAILABLE;
-#endif /* POLARSSL_HAVE_READDIR_R */
#endif /* _WIN32 */
return( ret );