From aa13e9394168e1ea467ccbb1971614b94245f6ac Mon Sep 17 00:00:00 2001 From: Shawn Carey Date: Thu, 6 May 2021 15:11:30 -0400 Subject: [PATCH] avoid "maybe-uninitialized" and "free-nonheap-object" errors/warnings with gcc11 Signed-off-by: Shawn Carey --- library/ecdsa.c | 2 +- library/x509write_crt.c | 4 ++-- library/x509write_csr.c | 4 ++-- programs/test/udp_proxy.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/library/ecdsa.c b/library/ecdsa.c index 35713a696..922063356 100644 --- a/library/ecdsa.c +++ b/library/ecdsa.c @@ -651,7 +651,7 @@ static int ecdsa_signature_to_asn1( const mbedtls_mpi *r, const mbedtls_mpi *s, unsigned char *sig, size_t *slen ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - unsigned char buf[MBEDTLS_ECDSA_MAX_LEN]; + unsigned char buf[MBEDTLS_ECDSA_MAX_LEN] = {0}; unsigned char *p = buf + sizeof( buf ); size_t len = 0; diff --git a/library/x509write_crt.c b/library/x509write_crt.c index 498b8b0a0..8f4a4f5ea 100644 --- a/library/x509write_crt.c +++ b/library/x509write_crt.c @@ -233,7 +233,7 @@ int mbedtls_x509write_crt_set_authority_key_identifier( mbedtls_x509write_cert * int mbedtls_x509write_crt_set_key_usage( mbedtls_x509write_cert *ctx, unsigned int key_usage ) { - unsigned char buf[5], ku[2]; + unsigned char buf[5] = {0}, ku[2] = {0}; unsigned char *c; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; const unsigned int allowed_bits = MBEDTLS_X509_KU_DIGITAL_SIGNATURE | @@ -272,7 +272,7 @@ int mbedtls_x509write_crt_set_key_usage( mbedtls_x509write_cert *ctx, int mbedtls_x509write_crt_set_ns_cert_type( mbedtls_x509write_cert *ctx, unsigned char ns_cert_type ) { - unsigned char buf[4]; + unsigned char buf[4] = {0}; unsigned char *c; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; diff --git a/library/x509write_csr.c b/library/x509write_csr.c index c7c8032be..afda95034 100644 --- a/library/x509write_csr.c +++ b/library/x509write_csr.c @@ -91,7 +91,7 @@ int mbedtls_x509write_csr_set_extension( mbedtls_x509write_csr *ctx, int mbedtls_x509write_csr_set_key_usage( mbedtls_x509write_csr *ctx, unsigned char key_usage ) { - unsigned char buf[4]; + unsigned char buf[4] = {0}; unsigned char *c; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; @@ -113,7 +113,7 @@ int mbedtls_x509write_csr_set_key_usage( mbedtls_x509write_csr *ctx, unsigned ch int mbedtls_x509write_csr_set_ns_cert_type( mbedtls_x509write_csr *ctx, unsigned char ns_cert_type ) { - unsigned char buf[4]; + unsigned char buf[4] = {0}; unsigned char *c; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; diff --git a/programs/test/udp_proxy.c b/programs/test/udp_proxy.c index 0b1bfd738..afe0118d0 100644 --- a/programs/test/udp_proxy.c +++ b/programs/test/udp_proxy.c @@ -1005,8 +1005,8 @@ exit: for( delay_idx = 0; delay_idx < MAX_DELAYED_HS; delay_idx++ ) { - mbedtls_free( opt.delay_cli + delay_idx ); - mbedtls_free( opt.delay_srv + delay_idx ); + mbedtls_free( opt.delay_cli[delay_idx] ); + mbedtls_free( opt.delay_srv[delay_idx] ); } mbedtls_net_free( &client_fd );