[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v1 19/59] block/ssh.c: remove unneeded labels
From: |
Richard W.M. Jones |
Subject: |
Re: [PATCH v1 19/59] block/ssh.c: remove unneeded labels |
Date: |
Mon, 6 Jan 2020 18:37:12 +0000 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Mon, Jan 06, 2020 at 03:23:45PM -0300, Daniel Henrique Barboza wrote:
> The 'out' labels for check_host_key_knownhosts() and authenticate()
> functions can be removed and, instead, call 'return' with the
> appropriate return value. The 'ret' integer from both functions
> could also be removed.
>
> CC: Richard W.M. Jones <address@hidden>
> CC: address@hidden
> Signed-off-by: Daniel Henrique Barboza <address@hidden>
> ---
> block/ssh.c | 61 +++++++++++++++++------------------------------------
> 1 file changed, 19 insertions(+), 42 deletions(-)
>
> diff --git a/block/ssh.c b/block/ssh.c
> index b4375cf7d2..e0c56d002a 100644
> --- a/block/ssh.c
> +++ b/block/ssh.c
> @@ -276,7 +276,6 @@ static void ssh_parse_filename(const char *filename,
> QDict *options,
>
> static int check_host_key_knownhosts(BDRVSSHState *s, Error **errp)
> {
> - int ret;
> #ifdef HAVE_LIBSSH_0_8
> enum ssh_known_hosts_e state;
> int r;
> @@ -295,7 +294,6 @@ static int check_host_key_knownhosts(BDRVSSHState *s,
> Error **errp)
> trace_ssh_check_host_key_knownhosts();
> break;
> case SSH_KNOWN_HOSTS_CHANGED:
> - ret = -EINVAL;
> r = ssh_get_server_publickey(s->session, &pubkey);
> if (r == 0) {
> r = ssh_get_publickey_hash(pubkey, SSH_PUBLICKEY_HASH_SHA256,
> @@ -320,28 +318,23 @@ static int check_host_key_knownhosts(BDRVSSHState *s,
> Error **errp)
> "host key does not match the one in known_hosts; this
> "
> "may be a possible attack");
> }
> - goto out;
> + return -EINVAL;
> case SSH_KNOWN_HOSTS_OTHER:
> - ret = -EINVAL;
> error_setg(errp,
> "host key for this server not found, another type
> exists");
> - goto out;
> + return -EINVAL;
> case SSH_KNOWN_HOSTS_UNKNOWN:
> - ret = -EINVAL;
> error_setg(errp, "no host key was found in known_hosts");
> - goto out;
> + return -EINVAL;
> case SSH_KNOWN_HOSTS_NOT_FOUND:
> - ret = -ENOENT;
> error_setg(errp, "known_hosts file not found");
> - goto out;
> + return -ENOENT;
> case SSH_KNOWN_HOSTS_ERROR:
> - ret = -EINVAL;
> error_setg(errp, "error while checking the host");
> - goto out;
> + return -EINVAL;
> default:
> - ret = -EINVAL;
> error_setg(errp, "error while checking for known server (%d)",
> state);
> - goto out;
> + return -EINVAL;
> }
> #else /* !HAVE_LIBSSH_0_8 */
> int state;
> @@ -355,40 +348,31 @@ static int check_host_key_knownhosts(BDRVSSHState *s,
> Error **errp)
> trace_ssh_check_host_key_knownhosts();
> break;
> case SSH_SERVER_KNOWN_CHANGED:
> - ret = -EINVAL;
> error_setg(errp,
> "host key does not match the one in known_hosts; this "
> "may be a possible attack");
> - goto out;
> + return -EINVAL;
> case SSH_SERVER_FOUND_OTHER:
> - ret = -EINVAL;
> error_setg(errp,
> "host key for this server not found, another type
> exists");
> - goto out;
> + return -EINVAL;
> case SSH_SERVER_FILE_NOT_FOUND:
> - ret = -ENOENT;
> error_setg(errp, "known_hosts file not found");
> - goto out;
> + return -ENOENT;
> case SSH_SERVER_NOT_KNOWN:
> - ret = -EINVAL;
> error_setg(errp, "no host key was found in known_hosts");
> - goto out;
> + return -EINVAL;
> case SSH_SERVER_ERROR:
> - ret = -EINVAL;
> error_setg(errp, "server error");
> - goto out;
> + return -EINVAL;
> default:
> - ret = -EINVAL;
> error_setg(errp, "error while checking for known server (%d)",
> state);
> - goto out;
> + return -EINVAL;
> }
> #endif /* !HAVE_LIBSSH_0_8 */
>
> /* known_hosts checking successful. */
> - ret = 0;
> -
> - out:
> - return ret;
> + return 0;
> }
>
> static unsigned hex2decimal(char ch)
> @@ -501,20 +485,18 @@ static int check_host_key(BDRVSSHState *s,
> SshHostKeyCheck *hkc, Error **errp)
>
> static int authenticate(BDRVSSHState *s, Error **errp)
> {
> - int r, ret;
> + int r;
> int method;
>
> /* Try to authenticate with the "none" method. */
> r = ssh_userauth_none(s->session, NULL);
> if (r == SSH_AUTH_ERROR) {
> - ret = -EPERM;
> session_error_setg(errp, s, "failed to authenticate using none "
> "authentication");
> - goto out;
> + return -EPERM;
> } else if (r == SSH_AUTH_SUCCESS) {
> /* Authenticated! */
> - ret = 0;
> - goto out;
> + return 0;
> }
>
> method = ssh_userauth_list(s->session, NULL);
> @@ -527,23 +509,18 @@ static int authenticate(BDRVSSHState *s, Error **errp)
> if (method & SSH_AUTH_METHOD_PUBLICKEY) {
> r = ssh_userauth_publickey_auto(s->session, NULL, NULL);
> if (r == SSH_AUTH_ERROR) {
> - ret = -EINVAL;
> session_error_setg(errp, s, "failed to authenticate using "
> "publickey authentication");
> - goto out;
> + return -EINVAL;
> } else if (r == SSH_AUTH_SUCCESS) {
> /* Authenticated! */
> - ret = 0;
> - goto out;
> + return 0;
> }
> }
>
> - ret = -EPERM;
> error_setg(errp, "failed to authenticate using publickey authentication "
> "and the identities held by your ssh-agent");
> -
> - out:
> - return ret;
> + return -EPERM;
> }
>
> static QemuOptsList ssh_runtime_opts = {
I agree that the code is functionality the same after this change.
Don't know whether or not one style or the other is preferred by qemu,
but in any case:
Reviewed-by: Richard W.M. Jones <address@hidden>
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top
- Re: [PATCH v1 12/59] virtfs-proxy-helper.c: remove 'err_out' label in setugid(), (continued)
- [PATCH v1 13/59] block/vdi.c: remove 'fail' label in vdi_open(), Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 14/59] block/file-posix.c: remove unneeded labels, Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 15/59] block/blkreplay.c: remove unneeded 'fail' label in blkreplay_open(), Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 16/59] block/gluster.c: remove unneeded 'exit' label, Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 17/59] block/dmg.c: remove unneeded 'fail' label in dmg_read_mish_block(), Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 19/59] block/ssh.c: remove unneeded labels, Daniel Henrique Barboza, 2020/01/06
- Re: [PATCH v1 19/59] block/ssh.c: remove unneeded labels,
Richard W.M. Jones <=
- [PATCH v1 20/59] block/vpc.c: remove unneeded 'fail' label in create_dynamic_disk(), Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 18/59] qcow2-refcount.c: remove unneeded 'fail' label in qcow2_refcount_init(), Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 21/59] block/backup.c remove unneeded 'out' label in backup_run(), Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 22/59] block/vmdk.c: remove unneeded labels, Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 23/59] block/vxhs.c: remove unneeded 'out' label in vxhs_iio_callback(), Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 24/59] block/vhdx-log.c: remove unneeded labels, Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 25/59] block/vhdx.c: remove unneeded 'exit' labels, Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 26/59] block/replication.c: remove unneeded label in replication_co_writev, Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 27/59] crypto/block-luks.c: remove unneeded label in qcrypto_block_luks_find_key, Daniel Henrique Barboza, 2020/01/06
- [PATCH v1 28/59] qga/commands-win32.c: remove 'out' label in get_pci_info, Daniel Henrique Barboza, 2020/01/06