From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:47438) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ROTsG-0003gS-G3 for qemu-devel@nongnu.org; Thu, 10 Nov 2011 07:37:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ROTsC-0005th-Gk for qemu-devel@nongnu.org; Thu, 10 Nov 2011 07:36:56 -0500 Received: from mtagate3.uk.ibm.com ([194.196.100.163]:38803) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ROTsC-0005sx-4C for qemu-devel@nongnu.org; Thu, 10 Nov 2011 07:36:52 -0500 Received: from d06nrmr1307.portsmouth.uk.ibm.com (d06nrmr1307.portsmouth.uk.ibm.com [9.149.38.129]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id pAACan2k010933 for ; Thu, 10 Nov 2011 12:36:49 GMT Received: from d06av08.portsmouth.uk.ibm.com (d06av08.portsmouth.uk.ibm.com [9.149.37.249]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pAACanbA1593554 for ; Thu, 10 Nov 2011 12:36:49 GMT Received: from d06av08.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pAACan3c026865 for ; Thu, 10 Nov 2011 12:36:49 GMT From: Stefan Hajnoczi Date: Thu, 10 Nov 2011 12:36:40 +0000 Message-Id: <1320928604-6642-5-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1320928604-6642-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1320928604-6642-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 4/8] ui/vnc: Convert sasl.mechlist to g_malloc() & friends List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , Markus Armbruster , Stefan Hajnoczi From: Markus Armbruster Fixes protocol_client_auth_sasl_mechname() not to crash when malloc() fails. Spotted by Coverity. Signed-off-by: Markus Armbruster Signed-off-by: Stefan Hajnoczi --- ui/vnc-auth-sasl.c | 19 +++++-------------- 1 files changed, 5 insertions(+), 14 deletions(-) diff --git a/ui/vnc-auth-sasl.c b/ui/vnc-auth-sasl.c index 23b1bf5..e2045fc 100644 --- a/ui/vnc-auth-sasl.c +++ b/ui/vnc-auth-sasl.c @@ -35,7 +35,7 @@ void vnc_sasl_client_cleanup(VncState *vs) vs->sasl.encodedLength = vs->sasl.encodedOffset = 0; vs->sasl.encoded = NULL; g_free(vs->sasl.username); - free(vs->sasl.mechlist); + g_free(vs->sasl.mechlist); vs->sasl.username = vs->sasl.mechlist = NULL; sasl_dispose(&vs->sasl.conn); vs->sasl.conn = NULL; @@ -430,11 +430,7 @@ static int protocol_client_auth_sasl_start_len(VncState *vs, uint8_t *data, size static int protocol_client_auth_sasl_mechname(VncState *vs, uint8_t *data, size_t len) { - char *mechname = malloc(len + 1); - if (!mechname) { - VNC_DEBUG("Out of memory reading mechname\n"); - vnc_client_error(vs); - } + char *mechname = g_malloc(len + 1); strncpy(mechname, (char*)data, len); mechname[len] = '\0'; VNC_DEBUG("Got client mechname '%s' check against '%s'\n", @@ -460,7 +456,7 @@ static int protocol_client_auth_sasl_mechname(VncState *vs, uint8_t *data, size_ } } - free(vs->sasl.mechlist); + g_free(vs->sasl.mechlist); vs->sasl.mechlist = mechname; VNC_DEBUG("Validated mechname '%s'\n", mechname); @@ -469,7 +465,7 @@ static int protocol_client_auth_sasl_mechname(VncState *vs, uint8_t *data, size_ fail: vnc_client_error(vs); - free(mechname); + g_free(mechname); return -1; } @@ -608,12 +604,7 @@ void start_auth_sasl(VncState *vs) } VNC_DEBUG("Available mechanisms for client: '%s'\n", mechlist); - if (!(vs->sasl.mechlist = strdup(mechlist))) { - VNC_DEBUG("Out of memory"); - sasl_dispose(&vs->sasl.conn); - vs->sasl.conn = NULL; - goto authabort; - } + vs->sasl.mechlist = g_strdup(mechlist); mechlistlen = strlen(mechlist); vnc_write_u32(vs, mechlistlen); vnc_write(vs, mechlist, mechlistlen); -- 1.7.7.1