Fixed potential heap buffer overflow on large file reading
This commit is contained in:
parent
04784f57e4
commit
694d3aeb47
1 changed files with 2 additions and 1 deletions
|
@ -1925,7 +1925,8 @@ static int load_file( const char *path, unsigned char **buf, size_t *n )
|
||||||
*n = (size_t) ftell( f );
|
*n = (size_t) ftell( f );
|
||||||
fseek( f, 0, SEEK_SET );
|
fseek( f, 0, SEEK_SET );
|
||||||
|
|
||||||
if( ( *buf = (unsigned char *) polarssl_malloc( *n + 1 ) ) == NULL )
|
if( *n + 1 == 0 ||
|
||||||
|
( *buf = (unsigned char *) polarssl_malloc( *n + 1 ) ) == NULL )
|
||||||
{
|
{
|
||||||
fclose( f );
|
fclose( f );
|
||||||
return( POLARSSL_ERR_X509_MALLOC_FAILED );
|
return( POLARSSL_ERR_X509_MALLOC_FAILED );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue