From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=41823 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PLIl5-0007BD-EG for qemu-devel@nongnu.org; Wed, 24 Nov 2010 12:03:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PLIl4-0001S0-7S for qemu-devel@nongnu.org; Wed, 24 Nov 2010 12:03:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:15372) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PLIl3-0001Rk-UQ for qemu-devel@nongnu.org; Wed, 24 Nov 2010 12:03:50 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oAOH3nWG002655 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 24 Nov 2010 12:03:49 -0500 From: Gerd Hoffmann Date: Wed, 24 Nov 2010 18:03:43 +0100 Message-Id: <1290618225-28879-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1290618225-28879-1-git-send-email-kraxel@redhat.com> References: <1290618225-28879-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 1/3] vnc: auth reject cleanup List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann protocol_client_auth_vnc() has two places where the auth can fail, with identical code sending the reject message to the client. Move the common code to the end of the function and make both error paths jump there. No functional change. Signed-off-by: Gerd Hoffmann --- ui/vnc.c | 30 +++++++++++++----------------- 1 files changed, 13 insertions(+), 17 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 864342e..da70757 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -2085,15 +2085,7 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) if (!vs->vd->password || !vs->vd->password[0]) { VNC_DEBUG("No password configured on server"); - vnc_write_u32(vs, 1); /* Reject auth */ - if (vs->minor >= 8) { - static const char err[] = "Authentication failed"; - vnc_write_u32(vs, sizeof(err)); - vnc_write(vs, err, sizeof(err)); - } - vnc_flush(vs); - vnc_client_error(vs); - return 0; + goto reject; } memcpy(response, vs->challenge, VNC_AUTH_CHALLENGE_SIZE); @@ -2109,14 +2101,7 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) /* Compare expected vs actual challenge response */ if (memcmp(response, data, VNC_AUTH_CHALLENGE_SIZE) != 0) { VNC_DEBUG("Client challenge reponse did not match\n"); - vnc_write_u32(vs, 1); /* Reject auth */ - if (vs->minor >= 8) { - static const char err[] = "Authentication failed"; - vnc_write_u32(vs, sizeof(err)); - vnc_write(vs, err, sizeof(err)); - } - vnc_flush(vs); - vnc_client_error(vs); + goto reject; } else { VNC_DEBUG("Accepting VNC challenge response\n"); vnc_write_u32(vs, 0); /* Accept auth */ @@ -2125,6 +2110,17 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) start_client_init(vs); } return 0; + +reject: + vnc_write_u32(vs, 1); /* Reject auth */ + if (vs->minor >= 8) { + static const char err[] = "Authentication failed"; + vnc_write_u32(vs, sizeof(err)); + vnc_write(vs, err, sizeof(err)); + } + vnc_flush(vs); + vnc_client_error(vs); + return 0; } void start_auth_vnc(VncState *vs) -- 1.7.1