From 9028c5af9a61b9113edff8c6d0bcad767ebdb459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Wed, 12 Aug 2015 14:51:36 +0200 Subject: [PATCH] Improve const correctness of read() functions --- library/ecjpake.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/library/ecjpake.c b/library/ecjpake.c index 9e074c9cf..f56142cc9 100644 --- a/library/ecjpake.c +++ b/library/ecjpake.c @@ -185,7 +185,7 @@ static int ecjpake_zkp_read( const mbedtls_md_info_t *md_info, const mbedtls_ecp_point *G, const mbedtls_ecp_point *X, const char *id, - unsigned char **p, + const unsigned char **p, const unsigned char *end ) { int ret; @@ -207,8 +207,7 @@ static int ecjpake_zkp_read( const mbedtls_md_info_t *md_info, if( end < *p ) return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); - MBEDTLS_MPI_CHK( mbedtls_ecp_tls_read_point( grp, &V, - (const unsigned char **) p, end - *p ) ); + MBEDTLS_MPI_CHK( mbedtls_ecp_tls_read_point( grp, &V, p, end - *p ) ); if( end < *p || (size_t)( end - *p ) < 1 ) { @@ -217,6 +216,7 @@ static int ecjpake_zkp_read( const mbedtls_md_info_t *md_info, } r_len = *(*p)++; + if( end < *p || (size_t)( end - *p ) < r_len ) { ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA; @@ -257,7 +257,7 @@ static int ecjpake_kkp_read( const mbedtls_md_info_t *md_info, const mbedtls_ecp_point *G, mbedtls_ecp_point *X, const char *id, - unsigned char **p, + const unsigned char **p, const unsigned char *end ) { int ret; @@ -271,8 +271,7 @@ static int ecjpake_kkp_read( const mbedtls_md_info_t *md_info, * ECSchnorrZKP zkp; * } ECJPAKEKeyKP; */ - MBEDTLS_MPI_CHK( mbedtls_ecp_tls_read_point( grp, X, - (const unsigned char **) p, end - *p ) ); + MBEDTLS_MPI_CHK( mbedtls_ecp_tls_read_point( grp, X, p, end - *p ) ); MBEDTLS_MPI_CHK( ecjpake_zkp_read( md_info, grp, G, X, id, p, end ) ); cleanup: @@ -329,7 +328,7 @@ static int ecjpake_kkpp_read( const mbedtls_md_info_t *md_info, size_t len ) { int ret; - unsigned char *p = (unsigned char *) buf; + const unsigned char *p = buf; const unsigned char *end = buf + len; /*