x509parse_crtpath() is now reentrant and uses more portable stat()
Moved from readdir() to readdir_r() and use stat instead of the less portable d_type from struct dirent.
This commit is contained in:
parent
d6d4109adc
commit
cbfcaa9206
2 changed files with 25 additions and 17 deletions
|
@ -23,6 +23,7 @@ Bugfix
|
||||||
* ssl_parse_certificate() now calls x509parse_crt_der() directly
|
* ssl_parse_certificate() now calls x509parse_crt_der() directly
|
||||||
instead of the x509parse_crt() wrapper that can also parse PEM
|
instead of the x509parse_crt() wrapper that can also parse PEM
|
||||||
certificates
|
certificates
|
||||||
|
* x509parse_crtpath() is now reentrant and uses more portable stat()
|
||||||
|
|
||||||
= Version 1.2.7 released 2013-04-13
|
= Version 1.2.7 released 2013-04-13
|
||||||
Features
|
Features
|
||||||
|
|
|
@ -75,6 +75,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -1919,12 +1920,9 @@ int x509parse_crtpath( x509_cert *chain, const char *path )
|
||||||
|
|
||||||
w_ret = x509parse_crtfile( chain, filename );
|
w_ret = x509parse_crtfile( chain, filename );
|
||||||
if( w_ret < 0 )
|
if( w_ret < 0 )
|
||||||
{
|
ret++;
|
||||||
ret = w_ret;
|
else
|
||||||
goto cleanup;
|
ret += w_ret;
|
||||||
}
|
|
||||||
|
|
||||||
ret += w_ret;
|
|
||||||
}
|
}
|
||||||
while( FindNextFileW( hFind, &file_data ) != 0 );
|
while( FindNextFileW( hFind, &file_data ) != 0 );
|
||||||
|
|
||||||
|
@ -1934,28 +1932,37 @@ int x509parse_crtpath( x509_cert *chain, const char *path )
|
||||||
cleanup:
|
cleanup:
|
||||||
FindClose( hFind );
|
FindClose( hFind );
|
||||||
#else
|
#else
|
||||||
int t_ret;
|
int t_ret, i;
|
||||||
struct dirent *entry;
|
struct stat sb;
|
||||||
|
struct dirent entry, *result = NULL;
|
||||||
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( ( entry = readdir( dir ) ) != NULL )
|
while( ( t_ret = readdir_r( dir, &entry, &result ) ) == 0 )
|
||||||
{
|
{
|
||||||
if( entry->d_type != DT_REG )
|
if( result == NULL )
|
||||||
|
break;
|
||||||
|
|
||||||
|
snprintf( entry_name, sizeof(entry_name), "%s/%s", path, entry.d_name );
|
||||||
|
|
||||||
|
i = stat( entry_name, &sb );
|
||||||
|
|
||||||
|
if( i == -1 )
|
||||||
|
return( POLARSSL_ERR_X509_FILE_IO_ERROR );
|
||||||
|
|
||||||
|
if( !S_ISREG( sb.st_mode ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
snprintf( entry_name, sizeof(entry_name), "%s/%s", path, entry->d_name );
|
// Ignore parse errors
|
||||||
|
//
|
||||||
t_ret = x509parse_crtfile( chain, entry_name );
|
t_ret = x509parse_crtfile( chain, entry_name );
|
||||||
if( t_ret < 0 )
|
if( t_ret < 0 )
|
||||||
{
|
ret++;
|
||||||
ret = t_ret;
|
else
|
||||||
break;
|
ret += t_ret;
|
||||||
}
|
|
||||||
|
|
||||||
ret += t_ret;
|
|
||||||
}
|
}
|
||||||
closedir( dir );
|
closedir( dir );
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue