qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Blue Swirl <blauwirbel@gmail.com>, Kevin Wolf <kwolf@redhat.com>,
	qemu-devel@nongnu.org, patches@linaro.org
Subject: Re: [Qemu-devel] [PATCH for-1.4] tests/test-string-input-visitor: Handle errors provoked by fuzz test
Date: Sat, 02 Feb 2013 22:37:22 +0100	[thread overview]
Message-ID: <510D8712.7090005@suse.de> (raw)
In-Reply-To: <1359839979-26852-1-git-send-email-peter.maydell@linaro.org>

Am 02.02.2013 22:19, schrieb Peter Maydell:
> It's OK and expected for visitors to return errors when presented with
> the fuzz test's random data. This means the test harness needs to
> handle them; check for and free any error after each visitor call,
> and only free the string returned by visit_type_str if visit_type_str
> succeeded.
> 
> 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].
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  tests/test-string-input-visitor.c | 23 ++++++++++++++++++++++-
>  1 file changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-visitor.c
> index f6b0093..793b334 100644
> --- a/tests/test-string-input-visitor.c
> +++ b/tests/test-string-input-visitor.c
> @@ -194,20 +194,41 @@ static void test_visitor_in_fuzz(TestInputVisitorData *data,
>  
>          v = visitor_input_test_init(data, buf);
>          visit_type_int(v, &ires, NULL, &errp);
> +        if (error_is_set(&errp)) {
> +            error_free(errp);
> +            errp = NULL;
> +        }

It seems to me the naming is bad here: errp appears to be an Error*, not
an Error**. It would be nice to fix this within the function touched.

Since it is an Error*, I think it was said that we should not use
error_is_set() but err != NULL (or if you prefer, just err).
error_is_set() is intended for **errp arguments that may be NULL.

Your analysis and the freeing and NULL'ing as solution looks correct.

Andreas

>  
>          v = visitor_input_test_init(data, buf);
>          visit_type_bool(v, &bres, NULL, &errp);
> +        if (error_is_set(&errp)) {
> +            error_free(errp);
> +            errp = NULL;
> +        }
>          visitor_input_teardown(data, NULL);
>  
>          v = visitor_input_test_init(data, buf);
>          visit_type_number(v, &nres, NULL, &errp);
> +        if (error_is_set(&errp)) {
> +            error_free(errp);
> +            errp = NULL;
> +        }
>  
>          v = visitor_input_test_init(data, buf);
>          visit_type_str(v, &sres, NULL, &errp);
> -        g_free(sres);
> +        if (error_is_set(&errp)) {
> +            error_free(errp);
> +            errp = NULL;
> +        } else {
> +            g_free(sres);
> +        }
>  
>          v = visitor_input_test_init(data, buf);
>          visit_type_EnumOne(v, &eres, NULL, &errp);
> +        if (error_is_set(&errp)) {
> +            error_free(errp);
> +            errp = NULL;
> +        }
>          visitor_input_teardown(data, NULL);
>      }
>  }
> 


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

  reply	other threads:[~2013-02-02 21:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-02 21:19 [Qemu-devel] [PATCH for-1.4] tests/test-string-input-visitor: Handle errors provoked by fuzz test Peter Maydell
2013-02-02 21:37 ` Andreas Färber [this message]
2013-02-02 23:19   ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=510D8712.7090005@suse.de \
    --to=afaerber@suse.de \
    --cc=blauwirbel@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=patches@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).