All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org,
	"Andreas Färber" <andreas.faerber@web.de>,
	patches@linaro.org
Subject: Re: [Qemu-trivial] [PATCH] tests/Makefile: Suppress format-security warnings on JSON tests
Date: Wed, 26 Feb 2014 23:58:17 +0100	[thread overview]
Message-ID: <530E7189.7060205@redhat.com> (raw)
In-Reply-To: <1393454861-24705-1-git-send-email-peter.maydell@linaro.org>

Il 26/02/2014 23:47, Peter Maydell ha scritto:
> Some of our test binaries programmatically generate JSON format
> strings to feed to qobject_from_json(). Since that function is
> marked with GCC_FMT_ATTR(), clang complains about this:
>  tests/test-qmp-input-visitor.c:76:35: warning: format string is not a
>  string literal (potentially insecure) [-Wformat-security]
>     data->obj = qobject_from_json(json_string);
>                                   ^~~~~~~~~~~

qobject_from_json shouldn't have a GCC_FMT_ATTR marker, only 
qobject_from_jsonf and qobject_from_jsonv.

qobject_from_json passes a NULL va_list*, and then parse_escape in 
qobject/json-parser.c returns NULL before calling va_arg.  Ultimately 
this produces a parse error.

Paolo

> Since these are only test cases and not potential attack vectors,
> the simplest approach is simply to suppress this particular
> compiler warning when compiling the relevant test cases.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> I couldn't think of a better way to do this...
>
>  tests/Makefile | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/tests/Makefile b/tests/Makefile
> index b17d41e..496c02f 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -146,6 +146,17 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \
>
>  GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h tests/test-qmp-commands.h
>
> +# These tests use the qobject_from_json() function with programmatically
> +# generated format strings; since this would otherwise trip clang's
> +# format-security warnings and these are only test binaries, disable
> +# the warnings when building them.
> +JSON_USERS=check-qjson \
> +           check-input-visitor \
> +           test-qmp-input-visitor \
> +           test-visitor-serialization
> +
> +$(JSON_USERS:%=tests/%.o): CFLAGS += -Wno-format-security
> +
>  test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \
>  	tests/check-qlist.o tests/check-qfloat.o tests/check-qjson.o \
>  	tests/test-coroutine.o tests/test-string-output-visitor.o \
>



WARNING: multiple messages have this Message-ID (diff)
From: Paolo Bonzini <pbonzini@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org,
	"Andreas Färber" <andreas.faerber@web.de>,
	patches@linaro.org
Subject: Re: [Qemu-devel] [PATCH] tests/Makefile: Suppress format-security warnings on JSON tests
Date: Wed, 26 Feb 2014 23:58:17 +0100	[thread overview]
Message-ID: <530E7189.7060205@redhat.com> (raw)
In-Reply-To: <1393454861-24705-1-git-send-email-peter.maydell@linaro.org>

Il 26/02/2014 23:47, Peter Maydell ha scritto:
> Some of our test binaries programmatically generate JSON format
> strings to feed to qobject_from_json(). Since that function is
> marked with GCC_FMT_ATTR(), clang complains about this:
>  tests/test-qmp-input-visitor.c:76:35: warning: format string is not a
>  string literal (potentially insecure) [-Wformat-security]
>     data->obj = qobject_from_json(json_string);
>                                   ^~~~~~~~~~~

qobject_from_json shouldn't have a GCC_FMT_ATTR marker, only 
qobject_from_jsonf and qobject_from_jsonv.

qobject_from_json passes a NULL va_list*, and then parse_escape in 
qobject/json-parser.c returns NULL before calling va_arg.  Ultimately 
this produces a parse error.

Paolo

> Since these are only test cases and not potential attack vectors,
> the simplest approach is simply to suppress this particular
> compiler warning when compiling the relevant test cases.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> I couldn't think of a better way to do this...
>
>  tests/Makefile | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/tests/Makefile b/tests/Makefile
> index b17d41e..496c02f 100644
> --- a/tests/Makefile
> +++ b/tests/Makefile
> @@ -146,6 +146,17 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \
>
>  GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h tests/test-qmp-commands.h
>
> +# These tests use the qobject_from_json() function with programmatically
> +# generated format strings; since this would otherwise trip clang's
> +# format-security warnings and these are only test binaries, disable
> +# the warnings when building them.
> +JSON_USERS=check-qjson \
> +           check-input-visitor \
> +           test-qmp-input-visitor \
> +           test-visitor-serialization
> +
> +$(JSON_USERS:%=tests/%.o): CFLAGS += -Wno-format-security
> +
>  test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \
>  	tests/check-qlist.o tests/check-qfloat.o tests/check-qjson.o \
>  	tests/test-coroutine.o tests/test-string-output-visitor.o \
>

  reply	other threads:[~2014-02-26 22:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-26 22:47 [Qemu-trivial] [PATCH] tests/Makefile: Suppress format-security warnings on JSON tests Peter Maydell
2014-02-26 22:47 ` [Qemu-devel] " Peter Maydell
2014-02-26 22:58 ` Paolo Bonzini [this message]
2014-02-26 22:58   ` Paolo Bonzini
2014-02-26 23:26   ` [Qemu-trivial] " Peter Maydell
2014-02-26 23:26     ` [Qemu-devel] " 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=530E7189.7060205@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=andreas.faerber@web.de \
    --cc=patches@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.