From 3bbfdf1f6e71515fe315f5367ec1b2ccae16f29e Mon Sep 17 00:00:00 2001 From: William Smith Date: Thu, 17 Jan 2013 21:42:41 -0500 Subject: [PATCH] ssl_server: initialize all structures, so that we can call *_free() in case of error In ssl_server, initialize at the beginning all the structures that are used in the program. This ensures that calls to functions like x509_free(), rsa_free() and ssl_free() do not cause a segmentation fault or other undesired behaviour. --- programs/ssl/ssl_server.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/programs/ssl/ssl_server.c b/programs/ssl/ssl_server.c index 5ede4fe..dd997fb 100644 --- a/programs/ssl/ssl_server.c +++ b/programs/ssl/ssl_server.c @@ -173,8 +173,8 @@ static int my_set_session(ssl_context * ssl) int main(void) { int ret, len; - int listen_fd; - int client_fd; + int listen_fd = -1; + int client_fd = -1; unsigned char buf[1024]; havege_state hs; @@ -189,7 +189,10 @@ int main(void) printf("\n . Loading the server cert. and key..."); fflush(stdout); + memset(&ssl, 0, sizeof(ssl_context)); + memset(&ssn, 0, sizeof(ssl_session)); memset(&srvcert, 0, sizeof(x509_cert)); + memset(&rsa, 0, sizeof(rsa_context)); /* * This demonstration program uses embedded test certificates. @@ -284,8 +287,6 @@ accept: ssl_set_ciphers(&ssl, my_ciphers); ssl_set_session(&ssl, 1, 0, &ssn); - memset(&ssn, 0, sizeof(ssl_session)); - ssl_set_ca_chain(&ssl, srvcert.next, NULL); ssl_set_own_cert(&ssl, &srvcert, &rsa); ssl_set_dh_param(&ssl, my_dhm_P, my_dhm_G); -- 2.11.4.GIT