From patchwork Thu Feb 7 16:20:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 218948 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6B4AF2C0092 for ; Fri, 8 Feb 2013 03:21:11 +1100 (EST) Received: from localhost ([::1]:43550 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3UDl-0002Or-9W for incoming@patchwork.ozlabs.org; Thu, 07 Feb 2013 11:21:09 -0500 Received: from eggs.gnu.org ([208.118.235.92]:47978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3UDU-0002OJ-4F for qemu-devel@nongnu.org; Thu, 07 Feb 2013 11:20:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U3UDQ-0002ek-0Q for qemu-devel@nongnu.org; Thu, 07 Feb 2013 11:20:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:7513) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3UDP-0002df-G8 for qemu-devel@nongnu.org; Thu, 07 Feb 2013 11:20:47 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r17GKkpk006267 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 7 Feb 2013 11:20:47 -0500 Received: from localhost (ovpn-113-93.phx2.redhat.com [10.3.113.93]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r17GKjnD015459; Thu, 7 Feb 2013 11:20:46 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 7 Feb 2013 14:20:42 -0200 Message-Id: <1360254042-20518-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1360254042-20518-1-git-send-email-lcapitulino@redhat.com> References: <1360254042-20518-1-git-send-email-lcapitulino@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id r17GKkpk006267 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PULL] tests/test-string-input-visitor: Handle errors provoked by fuzz test X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Peter Maydell It's OK and expected for visitors to return errors when presented with the fuzz test's random data. Since the fuzzer doesn't care about errors, we pass in NULL rather than an Error**. This fixes a bug in the fuzzer where it was passing the same Error** into each visitor, with the effect that once one visitor returned an error, each later visitor would notice that it had been passed in an Error** representing an already set error, and do nothing. For the case of visit_type_str() we also need to handle the case where an error means that the visitor doesn't set our char*. We initialize the pointer to NULL so we can safely g_free() it regardless of whether the visitor allocated a string for us or not. This fixes a problem where this test failed the MacOSX malloc() consistency checks and might segfault on other platforms [due to calling free() on an uninitialized pointer variable when visit_type_str() failed.]. Signed-off-by: Peter Maydell Reviewed-by: Andreas Färber Signed-off-by: Luiz Capitulino --- tests/test-string-input-visitor.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-visitor.c index f6b0093..5989f81 100644 --- a/tests/test-string-input-visitor.c +++ b/tests/test-string-input-visitor.c @@ -174,7 +174,6 @@ static void test_visitor_in_fuzz(TestInputVisitorData *data, double nres; char *sres; EnumOne eres; - Error *errp = NULL; Visitor *v; unsigned int i; char buf[10000]; @@ -193,21 +192,22 @@ static void test_visitor_in_fuzz(TestInputVisitorData *data, } v = visitor_input_test_init(data, buf); - visit_type_int(v, &ires, NULL, &errp); + visit_type_int(v, &ires, NULL, NULL); v = visitor_input_test_init(data, buf); - visit_type_bool(v, &bres, NULL, &errp); + visit_type_bool(v, &bres, NULL, NULL); visitor_input_teardown(data, NULL); v = visitor_input_test_init(data, buf); - visit_type_number(v, &nres, NULL, &errp); + visit_type_number(v, &nres, NULL, NULL); v = visitor_input_test_init(data, buf); - visit_type_str(v, &sres, NULL, &errp); + sres = NULL; + visit_type_str(v, &sres, NULL, NULL); g_free(sres); v = visitor_input_test_init(data, buf); - visit_type_EnumOne(v, &eres, NULL, &errp); + visit_type_EnumOne(v, &eres, NULL, NULL); visitor_input_teardown(data, NULL); } }