mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-23 12:01:11 +00:00
Merge remote-tracking branch 'hanno/mpi_read_file_underflow_backport-2.1' into mbedtls-2.1
* hanno/mpi_read_file_underflow_backport-2.1: Fix potential stack underflow in mpi_read_file.
This commit is contained in:
commit
640edc7810
|
@ -34,6 +34,8 @@ Bugfix
|
||||||
Found by blaufish. Fixes #641.
|
Found by blaufish. Fixes #641.
|
||||||
* Fix incorrect sign computation in modular exponentiation
|
* Fix incorrect sign computation in modular exponentiation
|
||||||
when dealing with negative MPI. Found by Guido Vranken.
|
when dealing with negative MPI. Found by Guido Vranken.
|
||||||
|
* Fix potential stack underflow in mpi_read_file.
|
||||||
|
Found by Guido Vranken.
|
||||||
|
|
||||||
Changes
|
Changes
|
||||||
* Clarify ECDSA documentation and improve the sample code to avoid
|
* Clarify ECDSA documentation and improve the sample code to avoid
|
||||||
|
|
|
@ -340,7 +340,7 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix,
|
||||||
|
|
||||||
#if defined(MBEDTLS_FS_IO)
|
#if defined(MBEDTLS_FS_IO)
|
||||||
/**
|
/**
|
||||||
* \brief Read X from an opened file
|
* \brief Read MPI from a line in an opened file
|
||||||
*
|
*
|
||||||
* \param X Destination MPI
|
* \param X Destination MPI
|
||||||
* \param radix Input numeric base
|
* \param radix Input numeric base
|
||||||
|
@ -349,6 +349,15 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix,
|
||||||
* \return 0 if successful, MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if
|
* \return 0 if successful, MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if
|
||||||
* the file read buffer is too small or a
|
* the file read buffer is too small or a
|
||||||
* MBEDTLS_ERR_MPI_XXX error code
|
* MBEDTLS_ERR_MPI_XXX error code
|
||||||
|
*
|
||||||
|
* \note On success, this function advances the file stream
|
||||||
|
* to the end of the current line or to EOF.
|
||||||
|
*
|
||||||
|
* The function returns 0 on an empty line.
|
||||||
|
*
|
||||||
|
* Leading whitespaces are ignored, as is a
|
||||||
|
* '0x' prefix for radix 16.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
int mbedtls_mpi_read_file( mbedtls_mpi *X, int radix, FILE *fin );
|
int mbedtls_mpi_read_file( mbedtls_mpi *X, int radix, FILE *fin );
|
||||||
|
|
||||||
|
|
|
@ -616,11 +616,11 @@ int mbedtls_mpi_read_file( mbedtls_mpi *X, int radix, FILE *fin )
|
||||||
if( slen == sizeof( s ) - 2 )
|
if( slen == sizeof( s ) - 2 )
|
||||||
return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL );
|
return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL );
|
||||||
|
|
||||||
if( s[slen - 1] == '\n' ) { slen--; s[slen] = '\0'; }
|
if( slen > 0 && s[slen - 1] == '\n' ) { slen--; s[slen] = '\0'; }
|
||||||
if( s[slen - 1] == '\r' ) { slen--; s[slen] = '\0'; }
|
if( slen > 0 && s[slen - 1] == '\r' ) { slen--; s[slen] = '\0'; }
|
||||||
|
|
||||||
p = s + slen;
|
p = s + slen;
|
||||||
while( --p >= s )
|
while( p-- > s )
|
||||||
if( mpi_get_digit( &d, radix, *p ) != 0 )
|
if( mpi_get_digit( &d, radix, *p ) != 0 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue