From 4e239484fe21681b9fb24c246433f8a25bdccac3 Mon Sep 17 00:00:00 2001 From: Eshan Kelkar Date: Wed, 7 Jun 2023 13:19:54 +0530 Subject: [PATCH] Use helper variable in connect_host() According to libssh coding conventions, function return values must not be directly passed to if- or while- conditions. This rule was not being followed in connect_host(). A helper variable has been introduced which stores the return code of the functions which is then passed to the if- conditions. Signed-off-by: Eshan Kelkar Reviewed-by: Sahana Prasad Reviewed-by: Jakub Jelen --- tests/benchmarks/benchmarks.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/tests/benchmarks/benchmarks.c b/tests/benchmarks/benchmarks.c index 178ac7f9..5b7c498c 100644 --- a/tests/benchmarks/benchmarks.c +++ b/tests/benchmarks/benchmarks.c @@ -278,26 +278,43 @@ static void arguments_init(struct argument_s *arguments) static ssh_session connect_host(const char *host, int verbose, char *cipher) { - ssh_session session = ssh_new(); + ssh_session session = NULL; + int rc; + + session = ssh_new(); if (session == NULL) goto error; - if (ssh_options_set(session, SSH_OPTIONS_HOST, host) < 0) + rc = ssh_options_set(session, SSH_OPTIONS_HOST, host); + if (rc < 0) + goto error; + + rc = ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbose); + if (rc < 0) goto error; - ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbose); if (cipher != NULL) { - if (ssh_options_set(session, SSH_OPTIONS_CIPHERS_C_S, cipher) || - ssh_options_set(session, SSH_OPTIONS_CIPHERS_S_C, cipher)) { + rc = ssh_options_set(session, SSH_OPTIONS_CIPHERS_C_S, cipher); + if (rc < 0) + goto error; + + rc = ssh_options_set(session, SSH_OPTIONS_CIPHERS_S_C, cipher); + if (rc < 0) goto error; - } } - ssh_options_parse_config(session, NULL); - if (ssh_connect(session) == SSH_ERROR) + rc = ssh_options_parse_config(session, NULL); + if (rc < 0) goto error; - if (ssh_userauth_autopubkey(session, NULL) != SSH_AUTH_SUCCESS) + + rc = ssh_connect(session); + if (rc == SSH_ERROR) goto error; + + rc = ssh_userauth_autopubkey(session, NULL); + if (rc != SSH_AUTH_SUCCESS) + goto error; + return session; error: