qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] tests/Makefile: Suppress format-security warnings on JSON tests
@ 2014-02-26 22:47 Peter Maydell
  2014-02-26 22:58 ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Maydell @ 2014-02-26 22:47 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Andreas Färber, patches

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);
                                  ^~~~~~~~~~~

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 \
-- 
1.8.5.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] tests/Makefile: Suppress format-security warnings on JSON tests
  2014-02-26 22:47 [Qemu-devel] [PATCH] tests/Makefile: Suppress format-security warnings on JSON tests Peter Maydell
@ 2014-02-26 22:58 ` Paolo Bonzini
  2014-02-26 23:26   ` Peter Maydell
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2014-02-26 22:58 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: qemu-trivial, Andreas Färber, patches

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 \
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] tests/Makefile: Suppress format-security warnings on JSON tests
  2014-02-26 22:58 ` Paolo Bonzini
@ 2014-02-26 23:26   ` Peter Maydell
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2014-02-26 23:26 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: QEMU Trivial, Andreas Färber, QEMU Developers,
	Patch Tracking

On 26 February 2014 22:58, Paolo Bonzini <pbonzini@redhat.com> wrote:
> 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.

That's a nicer way to fix this :-)  I was assuming the attribute marking
was correct...

-- PMM

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-02-26 23:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-26 22:47 [Qemu-devel] [PATCH] tests/Makefile: Suppress format-security warnings on JSON tests Peter Maydell
2014-02-26 22:58 ` Paolo Bonzini
2014-02-26 23:26   ` Peter Maydell

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).