mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 17:45:44 +01:00
Fixed potential negative value misinterpretation in load_file()
This commit is contained in:
parent
75c1a6f97c
commit
42c3ccf36e
@ -1917,14 +1917,21 @@ int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen )
|
|||||||
static int load_file( const char *path, unsigned char **buf, size_t *n )
|
static int load_file( const char *path, unsigned char **buf, size_t *n )
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
long size;
|
||||||
|
|
||||||
if( ( f = fopen( path, "rb" ) ) == NULL )
|
if( ( f = fopen( path, "rb" ) ) == NULL )
|
||||||
return( POLARSSL_ERR_X509_FILE_IO_ERROR );
|
return( POLARSSL_ERR_X509_FILE_IO_ERROR );
|
||||||
|
|
||||||
fseek( f, 0, SEEK_END );
|
fseek( f, 0, SEEK_END );
|
||||||
*n = (size_t) ftell( f );
|
if( ( size = ftell( f ) ) == -1 )
|
||||||
|
{
|
||||||
|
fclose( f );
|
||||||
|
return( POLARSSL_ERR_X509_FILE_IO_ERROR );
|
||||||
|
}
|
||||||
fseek( f, 0, SEEK_SET );
|
fseek( f, 0, SEEK_SET );
|
||||||
|
|
||||||
|
*n = (size_t) size;
|
||||||
|
|
||||||
if( *n + 1 == 0 ||
|
if( *n + 1 == 0 ||
|
||||||
( *buf = (unsigned char *) polarssl_malloc( *n + 1 ) ) == NULL )
|
( *buf = (unsigned char *) polarssl_malloc( *n + 1 ) ) == NULL )
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user