From patchwork Thu Oct 7 11:15:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 67036 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CB9FDB6F07 for ; Thu, 7 Oct 2010 22:16:44 +1100 (EST) Received: from localhost ([127.0.0.1]:58417 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P3oSm-0000kn-L9 for incoming@patchwork.ozlabs.org; Thu, 07 Oct 2010 07:16:40 -0400 Received: from [140.186.70.92] (port=39153 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P3oRa-0000kW-Ox for qemu-devel@nongnu.org; Thu, 07 Oct 2010 07:15:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P3oRZ-0006Xf-KK for qemu-devel@nongnu.org; Thu, 07 Oct 2010 07:15:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55490) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P3oRZ-0006Wr-Ay for qemu-devel@nongnu.org; Thu, 07 Oct 2010 07:15:25 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o97BFOw9026968 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 7 Oct 2010 07:15:24 -0400 Received: from rincewind.home.kraxel.org (vpn1-5-214.ams2.redhat.com [10.36.5.214]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o97BFNfi031496; Thu, 7 Oct 2010 07:15:24 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id B340D4522C; Thu, 7 Oct 2010 13:15:21 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 7 Oct 2010 13:15:19 +0200 Message-Id: <1286450121-17153-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1286450121-17153-1-git-send-email-kraxel@redhat.com> References: <1286450121-17153-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 1/3] vnc: auth reject cleanup X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 c7a1831..1ef0fc5 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -2081,15 +2081,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); @@ -2105,14 +2097,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 */ @@ -2121,6 +2106,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)