All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH buildfix for-2.1] tests: Fix unterminated string output visitor enum human string
@ 2014-07-09 20:28 Andreas Färber
  2014-07-09 20:40 ` Eric Blake
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andreas Färber @ 2014-07-09 20:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Michael S. Tsirkin, Andreas Färber, Hu Tao

The buffer was being allocated of size string length plus two.
Around the string two quotes were being added, but no terminating NUL.
It was then compared using g_assert_cmpstr(), resulting in fairly random
assertion failures:

 ERROR:tests/test-string-output-visitor.c:213:test_visitor_out_enum: assertion failed (str == str_human): ("\"value1\"" == "\"value1\"\001EEEEEEEEEEEEEE\0171")

There is no g_assert_cmpnstr() counterpart, so use g_strdup_printf()
for safely assembling the string in the first place.

Cc: Hu Tao <hutao@cn.fujitsu.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Suggested-by: Eric Blake <eblake@redhat.com>
Fixes: b4900c0 tests: add human format test for string output visitor
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 tests/test-string-output-visitor.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/tests/test-string-output-visitor.c b/tests/test-string-output-visitor.c
index e89e43c..101fb27 100644
--- a/tests/test-string-output-visitor.c
+++ b/tests/test-string-output-visitor.c
@@ -196,16 +196,11 @@ static void test_visitor_out_enum(TestOutputVisitorData *data,
 
     for (i = 0; i < ENUM_ONE_MAX; i++) {
         char *str_human;
-        int len;
 
         visit_type_EnumOne(data->ov, &i, "unused", &err);
         g_assert(!err);
 
-        len = strlen(EnumOne_lookup[i]) + 2;
-        str_human = g_malloc0(len);
-        str_human[0] = '"';
-        strncpy(str_human + 1, EnumOne_lookup[i], strlen(EnumOne_lookup[i]));
-        str_human[len - 1] = '"';
+        str_human = g_strdup_printf("\"%s\"", EnumOne_lookup[i]);
 
         str = string_output_get_string(data->sov);
         g_assert(str != NULL);
-- 
1.8.4.5

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

* Re: [Qemu-devel] [PATCH buildfix for-2.1] tests: Fix unterminated string output visitor enum human string
  2014-07-09 20:28 [Qemu-devel] [PATCH buildfix for-2.1] tests: Fix unterminated string output visitor enum human string Andreas Färber
@ 2014-07-09 20:40 ` Eric Blake
  2014-07-10  7:33 ` Hu Tao
  2014-07-10 13:29 ` Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Blake @ 2014-07-09 20:40 UTC (permalink / raw)
  To: Andreas Färber, qemu-devel; +Cc: Peter Maydell, Hu Tao, Michael S. Tsirkin

[-- Attachment #1: Type: text/plain, Size: 1111 bytes --]

On 07/09/2014 02:28 PM, Andreas Färber wrote:
> The buffer was being allocated of size string length plus two.
> Around the string two quotes were being added, but no terminating NUL.
> It was then compared using g_assert_cmpstr(), resulting in fairly random
> assertion failures:
> 
>  ERROR:tests/test-string-output-visitor.c:213:test_visitor_out_enum: assertion failed (str == str_human): ("\"value1\"" == "\"value1\"\001EEEEEEEEEEEEEE\0171")
> 
> There is no g_assert_cmpnstr() counterpart, so use g_strdup_printf()
> for safely assembling the string in the first place.
> 
> Cc: Hu Tao <hutao@cn.fujitsu.com>
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Suggested-by: Eric Blake <eblake@redhat.com>
> Fixes: b4900c0 tests: add human format test for string output visitor
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> ---
>  tests/test-string-output-visitor.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

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

* Re: [Qemu-devel] [PATCH buildfix for-2.1] tests: Fix unterminated string output visitor enum human string
  2014-07-09 20:28 [Qemu-devel] [PATCH buildfix for-2.1] tests: Fix unterminated string output visitor enum human string Andreas Färber
  2014-07-09 20:40 ` Eric Blake
@ 2014-07-10  7:33 ` Hu Tao
  2014-07-10 13:29 ` Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Hu Tao @ 2014-07-10  7:33 UTC (permalink / raw)
  To: Andreas Färber; +Cc: Peter Maydell, qemu-devel, Michael S. Tsirkin

On Wed, Jul 09, 2014 at 10:28:49PM +0200, Andreas Färber wrote:
> The buffer was being allocated of size string length plus two.
> Around the string two quotes were being added, but no terminating NUL.
> It was then compared using g_assert_cmpstr(), resulting in fairly random
> assertion failures:
> 
>  ERROR:tests/test-string-output-visitor.c:213:test_visitor_out_enum: assertion failed (str == str_human): ("\"value1\"" == "\"value1\"\001EEEEEEEEEEEEEE\0171")
> 
> There is no g_assert_cmpnstr() counterpart, so use g_strdup_printf()
> for safely assembling the string in the first place.
> 
> Cc: Hu Tao <hutao@cn.fujitsu.com>
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Suggested-by: Eric Blake <eblake@redhat.com>
> Fixes: b4900c0 tests: add human format test for string output visitor
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> ---
>  tests/test-string-output-visitor.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/tests/test-string-output-visitor.c b/tests/test-string-output-visitor.c
> index e89e43c..101fb27 100644
> --- a/tests/test-string-output-visitor.c
> +++ b/tests/test-string-output-visitor.c
> @@ -196,16 +196,11 @@ static void test_visitor_out_enum(TestOutputVisitorData *data,
>  
>      for (i = 0; i < ENUM_ONE_MAX; i++) {
>          char *str_human;
> -        int len;
>  
>          visit_type_EnumOne(data->ov, &i, "unused", &err);
>          g_assert(!err);
>  
> -        len = strlen(EnumOne_lookup[i]) + 2;
> -        str_human = g_malloc0(len);
> -        str_human[0] = '"';
> -        strncpy(str_human + 1, EnumOne_lookup[i], strlen(EnumOne_lookup[i]));
> -        str_human[len - 1] = '"';
> +        str_human = g_strdup_printf("\"%s\"", EnumOne_lookup[i]);
>  
>          str = string_output_get_string(data->sov);
>          g_assert(str != NULL);
> -- 
> 1.8.4.5

Reviewed-by: Hu Tao <hutao@cn.fujitsu.com>

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

* Re: [Qemu-devel] [PATCH buildfix for-2.1] tests: Fix unterminated string output visitor enum human string
  2014-07-09 20:28 [Qemu-devel] [PATCH buildfix for-2.1] tests: Fix unterminated string output visitor enum human string Andreas Färber
  2014-07-09 20:40 ` Eric Blake
  2014-07-10  7:33 ` Hu Tao
@ 2014-07-10 13:29 ` Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2014-07-10 13:29 UTC (permalink / raw)
  To: Andreas Färber; +Cc: Hu Tao, QEMU Developers, Michael S. Tsirkin

On 9 July 2014 21:28, Andreas Färber <afaerber@suse.de> wrote:
> The buffer was being allocated of size string length plus two.
> Around the string two quotes were being added, but no terminating NUL.
> It was then compared using g_assert_cmpstr(), resulting in fairly random
> assertion failures:
>
>  ERROR:tests/test-string-output-visitor.c:213:test_visitor_out_enum: assertion failed (str == str_human): ("\"value1\"" == "\"value1\"\001EEEEEEEEEEEEEE\0171")
>
> There is no g_assert_cmpnstr() counterpart, so use g_strdup_printf()
> for safely assembling the string in the first place.

Applied to master as a buildfix, thanks.

-- PMM

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

end of thread, other threads:[~2014-07-10 13:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-09 20:28 [Qemu-devel] [PATCH buildfix for-2.1] tests: Fix unterminated string output visitor enum human string Andreas Färber
2014-07-09 20:40 ` Eric Blake
2014-07-10  7:33 ` Hu Tao
2014-07-10 13:29 ` Peter Maydell

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.