From 5cf4af80f03f7be62a34310a31de60852a0c1b2c Mon Sep 17 00:00:00 2001 From: Sergei Ianovich Date: Tue, 30 Jul 2024 14:33:18 +0000 Subject: [PATCH] Fix false positive static analysis issue Infer complains: ``` test_tls.c:172: error: Uninitialized Value `_.cert` is read without initialization. 170. 171. T(sctx = SSL_CTX_new(TLS_server_method())); 172. T(SSL_CTX_use_certificate(sctx, ck.cert)); ^ 173. T(SSL_CTX_use_PrivateKey(sctx, ck.pkey)); 174. T(SSL_CTX_check_private_key(sctx)); test_tls.c:173: error: Uninitialized Value `_.pkey` is read without initialization. 171. T(sctx = SSL_CTX_new(TLS_server_method())); 172. T(SSL_CTX_use_certificate(sctx, ck.cert)); 173. T(SSL_CTX_use_PrivateKey(sctx, ck.pkey)); ^ 174. T(SSL_CTX_check_private_key(sctx)); 175. ``` Altough the complain is false positive, fixing it will allow for future use of the tools in automated tests. --- test_tls.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test_tls.c b/test_tls.c index 77e6281..72a8e08 100644 --- a/test_tls.c +++ b/test_tls.c @@ -78,7 +78,7 @@ static void err(int eval, const char *fmt, ...) } /* Generate simple cert+key pair. Based on req.c */ -static struct certkey certgen(const char *algname, const char *paramset) +static void certgen(const char *algname, const char *paramset, struct certkey *ck) { /* Keygen. */ EVP_PKEY *tkey; @@ -150,7 +150,8 @@ static struct certkey certgen(const char *algname, const char *paramset) PEM_write_bio_X509(out, x509ss); BIO_free_all(out); #endif - return (struct certkey){ .pkey = pkey, .cert = x509ss }; + ck->pkey = pkey; + ck->cert = x509ss; } /* Non-blocking BIO test mechanic is based on sslapitest.c */ @@ -164,7 +165,7 @@ int test(const char *algname, const char *paramset) printf(cNORM "\n"); struct certkey ck; - ck = certgen(algname, paramset); + certgen(algname, paramset, &ck); SSL_CTX *cctx, *sctx; -- 2.39.5