From b9cfaa0c7f41c7adb28755cb7bc46a624e98d3b6 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Fri, 11 Oct 2013 18:58:55 +0200 Subject: [PATCH] Explicit conversions and minor changes to prevent MSVC compiler warnings --- include/polarssl/cipher.h | 2 +- library/asn1write.c | 28 +++++++++++----------- library/base64.c | 2 +- library/cipher.c | 18 +++++++++------ library/ctr_drbg.c | 8 ++++--- library/ecp.c | 9 ++++---- library/entropy_poll.c | 2 +- library/error.c | 7 +++++- library/pk_wrap.c | 6 ++--- library/pkcs12.c | 6 ++--- library/pkcs5.c | 2 +- library/pkwrite.c | 12 +++++----- library/rsa.c | 6 ++--- library/ssl_cli.c | 4 ++-- library/ssl_srv.c | 8 +++---- library/ssl_tls.c | 45 ++++++++++++++++++++++++------------ library/x509_create.c | 10 ++++---- library/x509_crt.c | 2 +- library/x509write_crt.c | 4 ++-- library/x509write_csr.c | 2 +- scripts/data_files/error.fmt | 7 +++++- 21 files changed, 111 insertions(+), 79 deletions(-) diff --git a/include/polarssl/cipher.h b/include/polarssl/cipher.h index 853c7e643..5ae25c1ea 100644 --- a/include/polarssl/cipher.h +++ b/include/polarssl/cipher.h @@ -379,7 +379,7 @@ static inline int cipher_get_iv_size( const cipher_context_t *ctx ) return 0; if( ctx->iv_size != 0 ) - return ctx->iv_size; + return (int) ctx->iv_size; return ctx->cipher_info->iv_size; } diff --git a/library/asn1write.c b/library/asn1write.c index d4c1d8d02..32d1c736f 100644 --- a/library/asn1write.c +++ b/library/asn1write.c @@ -44,7 +44,7 @@ int asn1_write_len( unsigned char **p, unsigned char *start, size_t len ) if( *p - start < 1 ) return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL ); - *--(*p) = len; + *--(*p) = (unsigned char) len; return( 1 ); } @@ -53,7 +53,7 @@ int asn1_write_len( unsigned char **p, unsigned char *start, size_t len ) if( *p - start < 2 ) return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL ); - *--(*p) = len; + *--(*p) = (unsigned char) len; *--(*p) = 0x81; return( 2 ); } @@ -92,7 +92,7 @@ int asn1_write_raw_buffer( unsigned char **p, unsigned char *start, (*p) -= len; memcpy( *p, buf, len ); - return( len ); + return( (int) len ); } #if defined(POLARSSL_BIGNUM_C) @@ -126,7 +126,7 @@ int asn1_write_mpi( unsigned char **p, unsigned char *start, mpi *X ) ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_INTEGER ) ); - return( len ); + return( (int) len ); } #endif /* POLARSSL_BIGNUM_C */ @@ -140,7 +140,7 @@ int asn1_write_null( unsigned char **p, unsigned char *start ) ASN1_CHK_ADD( len, asn1_write_len( p, start, 0) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_NULL ) ); - return( len ); + return( (int) len ); } int asn1_write_oid( unsigned char **p, unsigned char *start, @@ -154,7 +154,7 @@ int asn1_write_oid( unsigned char **p, unsigned char *start, ASN1_CHK_ADD( len , asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len , asn1_write_tag( p, start, ASN1_OID ) ); - return( len ); + return( (int) len ); } int asn1_write_algorithm_identifier( unsigned char **p, unsigned char *start, @@ -175,7 +175,7 @@ int asn1_write_algorithm_identifier( unsigned char **p, unsigned char *start, ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ); - return( len ); + return( (int) len ); } int asn1_write_bool( unsigned char **p, unsigned char *start, int boolean ) @@ -192,7 +192,7 @@ int asn1_write_bool( unsigned char **p, unsigned char *start, int boolean ) ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_BOOLEAN ) ); - return( len ); + return( (int) len ); } int asn1_write_int( unsigned char **p, unsigned char *start, int val ) @@ -222,7 +222,7 @@ int asn1_write_int( unsigned char **p, unsigned char *start, int val ) ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_INTEGER ) ); - return( len ); + return( (int) len ); } int asn1_write_printable_string( unsigned char **p, unsigned char *start, @@ -237,7 +237,7 @@ int asn1_write_printable_string( unsigned char **p, unsigned char *start, ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_PRINTABLE_STRING ) ); - return( len ); + return( (int) len ); } int asn1_write_ia5_string( unsigned char **p, unsigned char *start, @@ -252,7 +252,7 @@ int asn1_write_ia5_string( unsigned char **p, unsigned char *start, ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_IA5_STRING ) ); - return( len ); + return( (int) len ); } int asn1_write_bitstring( unsigned char **p, unsigned char *start, @@ -274,12 +274,12 @@ int asn1_write_bitstring( unsigned char **p, unsigned char *start, // Write unused bits // - *--(*p) = size * 8 - bits; + *--(*p) = (unsigned char) (size * 8 - bits); ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_BIT_STRING ) ); - return( len ); + return( (int) len ); } int asn1_write_octet_string( unsigned char **p, unsigned char *start, @@ -293,7 +293,7 @@ int asn1_write_octet_string( unsigned char **p, unsigned char *start, ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_OCTET_STRING ) ); - return( len ); + return( (int) len ); } asn1_named_data *asn1_store_named_data( asn1_named_data **head, diff --git a/library/base64.c b/library/base64.c index 4b823b297..e9527dbde 100644 --- a/library/base64.c +++ b/library/base64.c @@ -137,7 +137,7 @@ int base64_decode( unsigned char *dst, size_t *dlen, uint32_t j, x; unsigned char *p; - for( i = j = n = 0; i < slen; i++ ) + for( i = n = j = 0; i < slen; i++ ) { if( ( slen - i ) >= 2 && src[i] == '\r' && src[i + 1] == '\n' ) diff --git a/library/cipher.c b/library/cipher.c index d14781b8d..5edc39a6c 100644 --- a/library/cipher.c +++ b/library/cipher.c @@ -216,7 +216,7 @@ int cipher_update_ad( cipher_context_t *ctx, #if defined(POLARSSL_GCM_C) if( POLARSSL_MODE_GCM == ctx->cipher_info->mode ) { - return gcm_starts( ctx->cipher_ctx, ctx->operation, + return gcm_starts( (gcm_context *) ctx->cipher_ctx, ctx->operation, ctx->iv, ctx->iv_size, ad, ad_len ); } #endif @@ -257,7 +257,8 @@ int cipher_update( cipher_context_t *ctx, const unsigned char *input, size_t ile if( ctx->cipher_info->mode == POLARSSL_MODE_GCM ) { *olen = ilen; - return gcm_update( ctx->cipher_ctx, ilen, input, output ); + return gcm_update( (gcm_context *) ctx->cipher_ctx, ilen, input, + output ); } #endif @@ -414,7 +415,7 @@ static void add_pkcs_padding( unsigned char *output, size_t output_len, static int get_pkcs_padding( unsigned char *input, size_t input_len, size_t *data_len ) { - unsigned int i, padding_len = 0; + size_t i, padding_len = 0; if( NULL == input || NULL == data_len ) return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; @@ -487,7 +488,7 @@ static void add_zeros_and_len_padding( unsigned char *output, static int get_zeros_and_len_padding( unsigned char *input, size_t input_len, size_t *data_len ) { - unsigned int i, padding_len = 0; + size_t i, padding_len = 0; if( NULL == input || NULL == data_len ) return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; @@ -514,7 +515,7 @@ static int get_zeros_and_len_padding( unsigned char *input, size_t input_len, static void add_zeros_padding( unsigned char *output, size_t output_len, size_t data_len ) { - unsigned char i; + size_t i; for( i = data_len; i < output_len; i++ ) output[i] = 0x00; @@ -693,7 +694,7 @@ int cipher_write_tag( cipher_context_t *ctx, #if defined(POLARSSL_GCM_C) if( POLARSSL_MODE_GCM == ctx->cipher_info->mode ) - return gcm_finish( ctx->cipher_ctx, tag, tag_len ); + return gcm_finish( (gcm_context *) ctx->cipher_ctx, tag, tag_len ); #endif return 0; @@ -720,8 +721,11 @@ int cipher_check_tag( cipher_context_t *ctx, if( tag_len > sizeof( check_tag ) ) return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA; - if( 0 != ( ret = gcm_finish( ctx->cipher_ctx, check_tag, tag_len ) ) ) + if( 0 != ( ret = gcm_finish( (gcm_context *) ctx->cipher_ctx, + check_tag, tag_len ) ) ) + { return( ret ); + } /* Check the tag in "constant-time" */ for( diff = 0, i = 0; i < tag_len; i++ ) diff --git a/library/ctr_drbg.c b/library/ctr_drbg.c index 54fb791d9..53b8b54c3 100644 --- a/library/ctr_drbg.c +++ b/library/ctr_drbg.c @@ -108,7 +108,8 @@ static int block_cipher_df( unsigned char *output, unsigned char *p = buf, *iv; aes_context aes_ctx; - int i, j, buf_len, use_len; + int i, j; + size_t buf_len, use_len; memset( buf, 0, CTR_DRBG_MAX_SEED_INPUT + CTR_DRBG_BLOCKSIZE + 16 ); @@ -150,11 +151,12 @@ static int block_cipher_df( unsigned char *output, for( i = 0; i < CTR_DRBG_BLOCKSIZE; i++ ) chain[i] ^= p[i]; p += CTR_DRBG_BLOCKSIZE; - use_len -= CTR_DRBG_BLOCKSIZE; + use_len -= ( use_len >= CTR_DRBG_BLOCKSIZE ) ? + CTR_DRBG_BLOCKSIZE : use_len; aes_crypt_ecb( &aes_ctx, AES_ENCRYPT, chain, chain ); } - + memcpy( tmp + j, chain, CTR_DRBG_BLOCKSIZE ); /* diff --git a/library/ecp.c b/library/ecp.c index b7af16a1b..d3880be55 100644 --- a/library/ecp.c +++ b/library/ecp.c @@ -442,7 +442,7 @@ int ecp_tls_write_point( const ecp_group *grp, const ecp_point *pt, /* * write length to the first byte and update total length */ - buf[0] = *olen; + buf[0] = (unsigned char) *olen; ++*olen; return 0; @@ -1427,7 +1427,7 @@ int ecp_mul( ecp_group *grp, ecp_point *R, { int ret; unsigned char w, m_is_odd, p_eq_g; - size_t pre_len, naf_len, i, j; + size_t pre_len = 1, naf_len, i, j; signed char naf[ MAX_NAF_LEN ]; ecp_point Q, *T = NULL, S[2]; mpi M; @@ -1469,7 +1469,7 @@ int ecp_mul( ecp_group *grp, ecp_point *R, if( w < 2 || w >= grp->nbits ) w = 2; - pre_len = 1 << ( w - 1 ); + pre_len <<= ( w - 1 ); naf_len = grp->nbits / w + 1; /* @@ -1478,7 +1478,8 @@ int ecp_mul( ecp_group *grp, ecp_point *R, */ if( ! p_eq_g || grp->T == NULL ) { - if( ( T = polarssl_malloc( pre_len * sizeof( ecp_point ) ) ) == NULL ) + T = (ecp_point *) polarssl_malloc( pre_len * sizeof( ecp_point ) ); + if( T == NULL ) { ret = POLARSSL_ERR_ECP_MALLOC_FAILED; goto cleanup; diff --git a/library/entropy_poll.c b/library/entropy_poll.c index b5d9f787c..eec8ec465 100644 --- a/library/entropy_poll.c +++ b/library/entropy_poll.c @@ -59,7 +59,7 @@ int platform_entropy_poll( void *data, unsigned char *output, size_t len, return POLARSSL_ERR_ENTROPY_SOURCE_FAILED; } - if( CryptGenRandom( provider, len, output ) == FALSE ) + if( CryptGenRandom( provider, (DWORD) len, output ) == FALSE ) return POLARSSL_ERR_ENTROPY_SOURCE_FAILED; CryptReleaseContext( provider, 0 ); diff --git a/library/error.c b/library/error.c index 47bfcc43d..ff6fb071e 100644 --- a/library/error.c +++ b/library/error.c @@ -169,8 +169,13 @@ void polarssl_strerror( int ret, char *buf, size_t buflen ) size_t len; int use_ret; + if( buflen == 0 ) + return; + memset( buf, 0x00, buflen ); - + /* Reduce buflen to make sure MSVC _snprintf() ends with \0 as well */ + buflen -= 1; + if( ret < 0 ) ret = -ret; diff --git a/library/pk_wrap.c b/library/pk_wrap.c index a26bc08ff..6f22b095f 100644 --- a/library/pk_wrap.c +++ b/library/pk_wrap.c @@ -68,7 +68,7 @@ static int rsa_verify_wrap( void *ctx, md_type_t md_alg, return( POLARSSL_ERR_RSA_VERIFY_FAILED ); return( rsa_pkcs1_verify( (rsa_context *) ctx, NULL, NULL, - RSA_PUBLIC, md_alg, hash_len, hash, sig ) ); + RSA_PUBLIC, md_alg, (unsigned int) hash_len, hash, sig ) ); } static int rsa_sign_wrap( void *ctx, md_type_t md_alg, @@ -79,7 +79,7 @@ static int rsa_sign_wrap( void *ctx, md_type_t md_alg, *sig_len = ((rsa_context *) ctx)->len; return( rsa_pkcs1_sign( (rsa_context *) ctx, f_rng, p_rng, RSA_PRIVATE, - md_alg, hash_len, hash, sig ) ); + md_alg, (unsigned int) hash_len, hash, sig ) ); } static int rsa_decrypt_wrap( void *ctx, @@ -361,7 +361,7 @@ static int rsa_alt_sign_wrap( void *ctx, md_type_t md_alg, *sig_len = rsa_alt->key_len_func( rsa_alt->key ); return( rsa_alt->sign_func( rsa_alt->key, f_rng, p_rng, RSA_PRIVATE, - md_alg, hash_len, hash, sig ) ); + md_alg, (unsigned int) hash_len, hash, sig ) ); } static int rsa_alt_decrypt_wrap( void *ctx, diff --git a/library/pkcs12.c b/library/pkcs12.c index 9ef557cdc..16821b03b 100644 --- a/library/pkcs12.c +++ b/library/pkcs12.c @@ -225,7 +225,7 @@ int pkcs12_derivation( unsigned char *data, size_t datalen, const unsigned char *salt, size_t saltlen, md_type_t md_type, int id, int iterations ) { - int ret, i; + int ret; unsigned int j; unsigned char diversifier[128]; @@ -234,7 +234,7 @@ int pkcs12_derivation( unsigned char *data, size_t datalen, unsigned char *p; unsigned char c; - size_t hlen, use_len, v; + size_t hlen, use_len, v, i; const md_info_t *md_info; md_context_t md_ctx; @@ -281,7 +281,7 @@ int pkcs12_derivation( unsigned char *data, size_t datalen, goto exit; // Perform remaining ( iterations - 1 ) recursive hash calculations - for( i = 1; i < iterations; i++ ) + for( i = 1; i < (size_t) iterations; i++ ) { if( ( ret = md( md_info, hash_output, hlen, hash_output ) ) != 0 ) goto exit; diff --git a/library/pkcs5.c b/library/pkcs5.c index c2aa06d6c..39aa5b96e 100644 --- a/library/pkcs5.c +++ b/library/pkcs5.c @@ -269,7 +269,7 @@ int pkcs5_pbkdf2_hmac( md_context_t *ctx, const unsigned char *password, use_len = ( key_length < md_size ) ? key_length : md_size; memcpy( out_p, work, use_len ); - key_length -= use_len; + key_length -= (uint32_t) use_len; out_p += use_len; for( i = 4; i > 0; i-- ) diff --git a/library/pkwrite.c b/library/pkwrite.c index fcebd48d5..8b6d7356e 100644 --- a/library/pkwrite.c +++ b/library/pkwrite.c @@ -71,7 +71,7 @@ static int pk_write_rsa_pubkey( unsigned char **p, unsigned char *start, ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ); - return( len ); + return( (int) len ); } #endif /* POLARSSL_RSA_C */ @@ -99,7 +99,7 @@ static int pk_write_ec_pubkey( unsigned char **p, unsigned char *start, *p -= len; memcpy( *p, buf, len ); - return( len ); + return( (int) len ); } /* @@ -120,7 +120,7 @@ static int pk_write_ec_param( unsigned char **p, unsigned char *start, ASN1_CHK_ADD( len, asn1_write_oid( p, start, oid, oid_len ) ); - return( len ); + return( (int) len ); } #endif /* POLARSSL_ECP_C */ @@ -142,7 +142,7 @@ int pk_write_pubkey( unsigned char **p, unsigned char *start, #endif return( POLARSSL_ERR_PK_FEATURE_UNAVAILABLE ); - return( len ); + return( (int) len ); } int pk_write_pubkey_der( pk_context *key, unsigned char *buf, size_t size ) @@ -189,7 +189,7 @@ int pk_write_pubkey_der( pk_context *key, unsigned char *buf, size_t size ) ASN1_CHK_ADD( len, asn1_write_len( &c, buf, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( &c, buf, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ); - return( len ); + return( (int) len ); } int pk_write_key_der( pk_context *key, unsigned char *buf, size_t size ) @@ -273,7 +273,7 @@ int pk_write_key_der( pk_context *key, unsigned char *buf, size_t size ) #endif return( POLARSSL_ERR_PK_FEATURE_UNAVAILABLE ); - return( len ); + return( (int) len ); } #if defined(POLARSSL_PEM_WRITE_C) diff --git a/library/rsa.c b/library/rsa.c index 2713b5c95..210ea46e3 100644 --- a/library/rsa.c +++ b/library/rsa.c @@ -1018,11 +1018,11 @@ int rsa_rsassa_pkcs1_v15_sign( rsa_context *ctx, * Digest ::= OCTET STRING */ *p++ = ASN1_SEQUENCE | ASN1_CONSTRUCTED; - *p++ = 0x08 + oid_size + hashlen; + *p++ = (unsigned char) ( 0x08 + oid_size + hashlen ); *p++ = ASN1_SEQUENCE | ASN1_CONSTRUCTED; - *p++ = 0x04 + oid_size; + *p++ = (unsigned char) ( 0x04 + oid_size ); *p++ = ASN1_OID; - *p++ = oid_size; + *p++ = oid_size & 0xFF; memcpy( p, oid, oid_size ); p += oid_size; *p++ = ASN1_NULL; diff --git a/library/ssl_cli.c b/library/ssl_cli.c index 81d8e8834..1db11ba13 100644 --- a/library/ssl_cli.c +++ b/library/ssl_cli.c @@ -1714,7 +1714,7 @@ static int ssl_write_client_key_exchange( ssl_context *ssl ) i = 6; ret = dhm_make_public( &ssl->handshake->dhm_ctx, - mpi_size( &ssl->handshake->dhm_ctx.P ), + (int) mpi_size( &ssl->handshake->dhm_ctx.P ), &ssl->out_msg[i], n, ssl->f_rng, ssl->p_rng ); if( ret != 0 ) @@ -1845,7 +1845,7 @@ static int ssl_write_client_key_exchange( ssl_context *ssl ) ssl->out_msg[7 + ssl->psk_identity_len] = (unsigned char)( n ); ret = dhm_make_public( &ssl->handshake->dhm_ctx, - mpi_size( &ssl->handshake->dhm_ctx.P ), + (int) mpi_size( &ssl->handshake->dhm_ctx.P ), &ssl->out_msg[8 + ssl->psk_identity_len], n, ssl->f_rng, ssl->p_rng ); if( ret != 0 ) diff --git a/library/ssl_srv.c b/library/ssl_srv.c index aa754306f..d4f56fa1d 100644 --- a/library/ssl_srv.c +++ b/library/ssl_srv.c @@ -1568,8 +1568,8 @@ static int ssl_write_server_hello( ssl_context *ssl ) #if defined(POLARSSL_HAVE_TIME) time_t t; #endif - int ret, n; - size_t olen, ext_len = 0; + int ret; + size_t olen, ext_len = 0, n; unsigned char *buf, *p; SSL_DEBUG_MSG( 2, ( "=> write server hello" ) ); @@ -1813,7 +1813,7 @@ static int ssl_write_certificate_request( ssl_context *ssl ) p[1 + ct_len++] = SSL_CERT_TYPE_ECDSA_SIGN; #endif - p[0] = ct_len++; + p[0] = (unsigned char) ct_len++; p += ct_len; sa_len = 0; @@ -1969,7 +1969,7 @@ static int ssl_write_server_key_exchange( ssl_context *ssl ) } if( ( ret = dhm_make_params( &ssl->handshake->dhm_ctx, - mpi_size( &ssl->handshake->dhm_ctx.P ), + (int) mpi_size( &ssl->handshake->dhm_ctx.P ), p, &len, ssl->f_rng, ssl->p_rng ) ) != 0 ) { diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 3f3bf11a7..065693ac6 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -80,7 +80,8 @@ static int ssl_session_copy( ssl_session *dst, const ssl_session *src ) { int ret; - if( ( dst->peer_cert = polarssl_malloc( sizeof(x509_crt) ) ) == NULL ) + dst->peer_cert = (x509_crt *) polarssl_malloc( sizeof(x509_crt) ); + if( dst->peer_cert == NULL ) return( POLARSSL_ERR_SSL_MALLOC_FAILED ); x509_crt_init( dst->peer_cert ); @@ -98,7 +99,8 @@ static int ssl_session_copy( ssl_session *dst, const ssl_session *src ) #if defined(POLARSSL_SSL_SESSION_TICKETS) if( src->ticket != NULL ) { - if( ( dst->ticket = polarssl_malloc( src->ticket_len ) ) == NULL ) + dst->ticket = (unsigned char *) polarssl_malloc( src->ticket_len ); + if( dst->ticket == NULL ) return( POLARSSL_ERR_SSL_MALLOC_FAILED ); memcpy( dst->ticket, src->ticket, src->ticket_len ); @@ -149,7 +151,7 @@ static int ssl3_prf( const unsigned char *secret, size_t slen, */ for( i = 0; i < dlen / 16; i++ ) { - memset( padding, 'A' + i, 1 + i ); + memset( padding, (unsigned char) ('A' + i), 1 + i ); sha1_starts( &sha1 ); sha1_update( &sha1, padding, 1 + i ); @@ -362,7 +364,7 @@ int ssl_derive_keys( ssl_context *ssl ) unsigned char *key2; unsigned char *mac_enc; unsigned char *mac_dec; - unsigned int iv_copy_len; + size_t iv_copy_len; const cipher_info_t *cipher_info; const md_info_t *md_info; @@ -1595,7 +1597,7 @@ static int ssl_decrypt_buf( ssl_context *ssl ) * correctly. (We round down instead of up, so -56 is the correct * value for our calculations instead of -55) */ - int j, extra_run = 0; + size_t j, extra_run = 0; extra_run = ( 13 + ssl->in_msglen + padlen + 8 ) / 64 - ( 13 + ssl->in_msglen + 8 ) / 64; @@ -3128,17 +3130,26 @@ static int ssl_handshake_init( ssl_context *ssl ) if( ssl->transform_negotiate ) ssl_transform_free( ssl->transform_negotiate ); else - ssl->transform_negotiate = polarssl_malloc( sizeof(ssl_transform) ); + { + ssl->transform_negotiate = + (ssl_transform *) polarssl_malloc( sizeof(ssl_transform) ); + } if( ssl->session_negotiate ) ssl_session_free( ssl->session_negotiate ); else - ssl->session_negotiate = polarssl_malloc( sizeof(ssl_session) ); + { + ssl->session_negotiate = + (ssl_session *) polarssl_malloc( sizeof(ssl_session) ); + } if( ssl->handshake ) ssl_handshake_free( ssl->handshake ); else - ssl->handshake = polarssl_malloc( sizeof(ssl_handshake_params) ); + { + ssl->handshake = (ssl_handshake_params *) + polarssl_malloc( sizeof(ssl_handshake_params) ); + } if( ssl->handshake == NULL || ssl->transform_negotiate == NULL || @@ -3329,7 +3340,8 @@ static int ssl_ticket_keys_init( ssl_context *ssl ) if( ssl->ticket_keys != NULL ) return( 0 ); - if( ( tkeys = polarssl_malloc( sizeof( ssl_ticket_keys ) ) ) == NULL ) + tkeys = (ssl_ticket_keys *) polarssl_malloc( sizeof(ssl_ticket_keys) ); + if( tkeys == NULL ) return( POLARSSL_ERR_SSL_MALLOC_FAILED ); if( ( ret = ssl->f_rng( ssl->p_rng, tkeys->key_name, 16 ) ) != 0 ) @@ -3461,7 +3473,8 @@ static ssl_key_cert *ssl_add_key_cert( ssl_context *ssl ) { ssl_key_cert *key_cert, *last; - if( ( key_cert = polarssl_malloc( sizeof( ssl_key_cert ) ) ) == NULL ) + key_cert = (ssl_key_cert *) polarssl_malloc( sizeof(ssl_key_cert) ); + if( key_cert == NULL ) return( NULL ); memset( key_cert, 0, sizeof( ssl_key_cert ) ); @@ -3512,7 +3525,8 @@ int ssl_set_own_cert_rsa( ssl_context *ssl, x509_crt *own_cert, if( key_cert == NULL ) return( POLARSSL_ERR_SSL_MALLOC_FAILED ); - if( ( key_cert->key = polarssl_malloc( sizeof( pk_context ) ) ) == NULL ) + key_cert->key = (pk_context *) polarssl_malloc( sizeof(pk_context) ); + if( key_cert->key == NULL ) return( POLARSSL_ERR_SSL_MALLOC_FAILED ); pk_init( key_cert->key ); @@ -3521,7 +3535,7 @@ int ssl_set_own_cert_rsa( ssl_context *ssl, x509_crt *own_cert, if( ret != 0 ) return( ret ); - if( ( ret = rsa_copy( key_cert->key->pk_ctx, rsa_key ) ) != 0 ) + if( ( ret = rsa_copy( pk_rsa( *key_cert->key ), rsa_key ) ) != 0 ) return( ret ); key_cert->cert = own_cert; @@ -3543,7 +3557,8 @@ int ssl_set_own_cert_alt( ssl_context *ssl, x509_crt *own_cert, if( key_cert == NULL ) return( POLARSSL_ERR_SSL_MALLOC_FAILED ); - if( ( key_cert->key = polarssl_malloc( sizeof( pk_context ) ) ) == NULL ) + key_cert->key = (pk_context *) polarssl_malloc( sizeof(pk_context) ); + if( key_cert->key == NULL ) return( POLARSSL_ERR_SSL_MALLOC_FAILED ); pk_init( key_cert->key ); @@ -3575,8 +3590,8 @@ int ssl_set_psk( ssl_context *ssl, const unsigned char *psk, size_t psk_len, ssl->psk_len = psk_len; ssl->psk_identity_len = psk_identity_len; - ssl->psk = polarssl_malloc( ssl->psk_len ); - ssl->psk_identity = polarssl_malloc( ssl->psk_identity_len ); + ssl->psk = (unsigned char *) polarssl_malloc( ssl->psk_len ); + ssl->psk_identity = (unsigned char *) polarssl_malloc( ssl->psk_identity_len ); if( ssl->psk == NULL || ssl->psk_identity == NULL ) return( POLARSSL_ERR_SSL_MALLOC_FAILED ); diff --git a/library/x509_create.c b/library/x509_create.c index d3d5851e3..4a15e7d17 100644 --- a/library/x509_create.c +++ b/library/x509_create.c @@ -159,7 +159,7 @@ static int x509_write_name( unsigned char **p, unsigned char *start, ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_CONSTRUCTED | ASN1_SET ) ); - return( len ); + return( (int) len ); } int x509_write_names( unsigned char **p, unsigned char *start, @@ -180,7 +180,7 @@ int x509_write_names( unsigned char **p, unsigned char *start, ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ); - return( len ); + return( (int) len ); } int x509_write_sig( unsigned char **p, unsigned char *start, @@ -208,7 +208,7 @@ int x509_write_sig( unsigned char **p, unsigned char *start, ASN1_CHK_ADD( len, asn1_write_algorithm_identifier( p, start, oid, oid_len, 0 ) ); - return( len ); + return( (int) len ); } static int x509_write_extension( unsigned char **p, unsigned char *start, @@ -235,7 +235,7 @@ static int x509_write_extension( unsigned char **p, unsigned char *start, ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ); - return( len ); + return( (int) len ); } /* @@ -261,7 +261,7 @@ int x509_write_extensions( unsigned char **p, unsigned char *start, cur_ext = cur_ext->next; } - return( len ); + return( (int) len ); } #endif /* POLARSSL_X509_CREATE_C */ diff --git a/library/x509_crt.c b/library/x509_crt.c index 91d46264f..d7723ac1c 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -940,7 +940,7 @@ int x509_crt_parse_path( x509_crt *chain, const char *path ) WCHAR szDir[MAX_PATH]; char filename[MAX_PATH]; char *p; - int len = strlen( path ); + int len = (int) strlen( path ); WIN32_FIND_DATAW file_data; HANDLE hFind; diff --git a/library/x509write_crt.c b/library/x509write_crt.c index db5ae0a2a..c3db3c4e2 100644 --- a/library/x509write_crt.c +++ b/library/x509write_crt.c @@ -270,7 +270,7 @@ static int x509_write_time( unsigned char **p, unsigned char *start, ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_GENERALIZED_TIME ) ); } - return( len ); + return( (int) len ); } int x509write_crt_der( x509write_cert *ctx, unsigned char *buf, size_t size, @@ -396,7 +396,7 @@ int x509write_crt_der( x509write_cert *ctx, unsigned char *buf, size_t size, ASN1_CHK_ADD( len, asn1_write_len( &c2, buf, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( &c2, buf, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ); - return( len ); + return( (int) len ); } #define PEM_BEGIN_CRT "-----BEGIN CERTIFICATE-----\n" diff --git a/library/x509write_csr.c b/library/x509write_csr.c index 1eb2afb3d..febed67d2 100644 --- a/library/x509write_csr.c +++ b/library/x509write_csr.c @@ -209,7 +209,7 @@ int x509write_csr_der( x509write_csr *ctx, unsigned char *buf, size_t size, ASN1_CHK_ADD( len, asn1_write_len( &c2, buf, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( &c2, buf, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ); - return( len ); + return( (int) len ); } #define PEM_BEGIN_CSR "-----BEGIN CERTIFICATE REQUEST-----\n" diff --git a/scripts/data_files/error.fmt b/scripts/data_files/error.fmt index 789f182bc..61f63cf5a 100644 --- a/scripts/data_files/error.fmt +++ b/scripts/data_files/error.fmt @@ -42,8 +42,13 @@ void polarssl_strerror( int ret, char *buf, size_t buflen ) size_t len; int use_ret; + if( buflen == 0 ) + return; + memset( buf, 0x00, buflen ); - + /* Reduce buflen to make sure MSVC _snprintf() ends with \0 as well */ + buflen -= 1; + if( ret < 0 ) ret = -ret;