mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 02:25:40 +01:00
Add macro for bounds checking
This commit adds a macro for buffer bounds checks in the SSL module. It takes the buffer's current and end position as the first argument(s), followed by the needed space; if the available space is too small, it returns an SSL_BUFFER_TOO_SMALL error. Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
parent
711eea30b9
commit
7ea4b4d70a
@ -236,6 +236,41 @@
|
||||
#define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS_PRESENT (1 << 0)
|
||||
#define MBEDTLS_TLS_EXT_ECJPAKE_KKPP_OK (1 << 1)
|
||||
|
||||
/**
|
||||
* \brief This function checks if the remaining size in a buffer is
|
||||
* greater or equal than a needed space.
|
||||
*
|
||||
* \param cur Pointer to the current position in the buffer.
|
||||
* \param end Pointer to one past the end of the buffer.
|
||||
* \param need Needed space in bytes.
|
||||
*
|
||||
* \return Non-zero if the needed space is available in the buffer, 0
|
||||
* otherwise.
|
||||
*/
|
||||
static inline int mbedtls_ssl_chk_buf_ptr( const uint8_t *cur,
|
||||
const uint8_t *end, size_t need )
|
||||
{
|
||||
return( cur <= end && need <= (size_t)( end - cur ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief This macro checks if the remaining size in a buffer is
|
||||
* greater or equal than a needed space. If it is not the case,
|
||||
* it returns an SSL_BUFFER_TOO_SMALL error.
|
||||
*
|
||||
* \param cur Pointer to the current position in the buffer.
|
||||
* \param end Pointer to one past the end of the buffer.
|
||||
* \param need Needed space in bytes.
|
||||
*
|
||||
*/
|
||||
#define MBEDTLS_SSL_CHK_BUF_PTR( cur, end, need ) \
|
||||
do { \
|
||||
if( mbedtls_ssl_chk_buf_ptr( ( cur ), ( end ), ( need ) ) == 0 ) \
|
||||
{ \
|
||||
return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); \
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user