[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL for-2.1 16/22] tests: Fix unterminated string output
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL for-2.1 16/22] tests: Fix unterminated string output visitor enum human string |
Date: |
Thu, 10 Jul 2014 14:35:21 +0200 |
From: Andreas Färber <address@hidden>
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 <address@hidden>
Cc: Michael S. Tsirkin <address@hidden>
Suggested-by: Eric Blake <address@hidden>
Fixes: b4900c0 tests: add human format test for string output visitor
Signed-off-by: Andreas Färber <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
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.3.1
- [Qemu-devel] [PULL for-2.1 01/22] block/backup: Fix hang for unaligned image size, (continued)
- [Qemu-devel] [PULL for-2.1 01/22] block/backup: Fix hang for unaligned image size, Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 03/22] block: prefer aio_poll to qemu_aio_wait, Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 05/22] test-aio: fix GSource-based timer test, Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 04/22] block: drop aio functions that operate on the main AioContext, Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 02/22] block: Fix bdrv_is_allocated() return value, Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 06/22] AioContext: speed up aio_notify, Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 09/22] qed: Make qiov match request size until backing file EOF, Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 07/22] block: Make qiov match the request size until EOF, Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 08/22] qcow2: Make qiov match request size until backing file EOF, Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 10/22] block: Assert qiov length matches request length, Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 16/22] tests: Fix unterminated string output visitor enum human string,
Kevin Wolf <=
- [Qemu-devel] [PULL for-2.1 11/22] virtio-blk: avoid dataplane VirtIOBlockReq early free, Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 12/22] dataplane: do not free VirtQueueElement in vring_push(), Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 13/22] virtio-blk: avoid g_slice_new0() for VirtIOBlockReq and VirtQueueElement, Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 15/22] AioContext: do not rely on aio_poll(ctx, true) result to end a loop, Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 17/22] qtest: fix vhost-user-test compilation with old GLib, Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 19/22] virtio-blk: Factor common checks out of virtio_blk_handle_read/write(), Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 14/22] virtio-blk: embed VirtQueueElement in VirtIOBlockReq, Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 21/22] virtio-blk: Treat read/write beyond end as invalid, Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 20/22] virtio-blk: Bypass error action and I/O accounting on invalid r/w, Kevin Wolf, 2014/07/10
- [Qemu-devel] [PULL for-2.1 18/22] dma-helpers: Fix too long qiov, Kevin Wolf, 2014/07/10