From 3fc6f9d16d4e9a6f85a909123ba2ca233132f571 Mon Sep 17 00:00:00 2001 From: Andy Gross Date: Wed, 30 Jan 2019 10:25:53 -0600 Subject: [PATCH] Fix uninitialized variable in x509_crt This patch fixes an issue we encountered with more stringent compiler warnings. The signature_is_good variable has a possibility of being used uninitialized. This patch moves the use of the variable to a place where it cannot be used while uninitialized. Signed-off-by: Andy Gross --- ChangeLog | 3 +++ library/x509_crt.c | 10 ++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index a78257803..fea2bc29f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23,6 +23,9 @@ Bugfix * Fix propagation of restart contexts in restartable EC operations. This could previously lead to segmentation faults in builds using an address-sanitizer and enabling but not using MBEDTLS_ECP_RESTARTABLE. + * Improve code clarity in x509_crt module, removing false-positive + uninitialized variable warnings on some recent toolchains (GCC8, etc). + Discovered and fixed by Andy Gross (Linaro), #2392. Changes * Make it easier to define MBEDTLS_PARAM_FAILED as assert (which config.h diff --git a/library/x509_crt.c b/library/x509_crt.c index 56d7a3127..9c2e36547 100644 --- a/library/x509_crt.c +++ b/library/x509_crt.c @@ -2087,15 +2087,13 @@ check_signature: continue; } + *r_parent = parent; + *r_signature_is_good = signature_is_good; + break; } - if( parent != NULL ) - { - *r_parent = parent; - *r_signature_is_good = signature_is_good; - } - else + if( parent == NULL ) { *r_parent = fallback_parent; *r_signature_is_good = fallback_signature_is_good;