[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 9/9] qtest: Avoid passing raw strings through hmp()
From: |
Thomas Huth |
Subject: |
[Qemu-devel] [PULL 9/9] qtest: Avoid passing raw strings through hmp() |
Date: |
Fri, 15 Sep 2017 10:02:29 +0200 |
From: Eric Blake <address@hidden>
hmp() passes its string argument through the sprintf() family;
with a proper attribute, gcc -Wformat warns us when we do something
dangerous like passing a non-constant format string. Fortunately,
all our strings were safe, but checking whether the string can
contain an unintended % is easy to avoid and therefore worth doing.
Signed-off-by: Eric Blake <address@hidden>
Reviewed-by: Dr. David Alan Gilbert <address@hidden>
Reviewed-by: Thomas Huth <address@hidden>
Signed-off-by: Thomas Huth <address@hidden>
---
tests/libqtest.h | 8 ++++----
tests/test-hmp.c | 4 ++--
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/tests/libqtest.h b/tests/libqtest.h
index 44803d7..86b3a3b 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -134,14 +134,14 @@ QDict *qtest_qmp_eventwait_ref(QTestState *s, const char
*event);
/**
* qtest_hmp:
* @s: #QTestState instance to operate on.
- * @fmt...: HMP command to send to QEMU
+ * @fmt...: HMP command to send to QEMU, formats arguments like sprintf().
*
* Send HMP command to QEMU via QMP's human-monitor-command.
* QMP events are discarded.
*
* Returns: the command's output. The caller should g_free() it.
*/
-char *qtest_hmp(QTestState *s, const char *fmt, ...);
+char *qtest_hmp(QTestState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
/**
* qtest_hmpv:
@@ -592,13 +592,13 @@ static inline QDict *qmp_eventwait_ref(const char *event)
/**
* hmp:
- * @fmt...: HMP command to send to QEMU
+ * @fmt...: HMP command to send to QEMU, formats arguments like sprintf().
*
* Send HMP command to QEMU via QMP's human-monitor-command.
*
* Returns: the command's output. The caller should g_free() it.
*/
-char *hmp(const char *fmt, ...);
+char *hmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
/**
* get_irq:
diff --git a/tests/test-hmp.c b/tests/test-hmp.c
index 4156d61..5677fbf 100644
--- a/tests/test-hmp.c
+++ b/tests/test-hmp.c
@@ -81,7 +81,7 @@ static void test_commands(void)
if (verbose) {
fprintf(stderr, "\t%s\n", hmp_cmds[i]);
}
- response = hmp(hmp_cmds[i]);
+ response = hmp("%s", hmp_cmds[i]);
g_free(response);
}
@@ -104,7 +104,7 @@ static void test_info_commands(void)
if (verbose) {
fprintf(stderr, "\t%s\n", info);
}
- resp = hmp(info);
+ resp = hmp("%s", info);
g_free(resp);
/* And move forward to the next line */
info = strchr(endp + 1, '\n');
--
1.8.3.1
- [Qemu-devel] [PULL 0/9] Fixes and improvements for various qtests, Thomas Huth, 2017/09/15
- [Qemu-devel] [PULL 1/9] tests: Introduce generic device hot-plug/hot-unplug functions, Thomas Huth, 2017/09/15
- [Qemu-devel] [PULL 2/9] tests/test-hmp: Remove puv3 and tricore_testboard from the blacklist, Thomas Huth, 2017/09/15
- [Qemu-devel] [PULL 3/9] tests/libqtest: Use a proper error message if QTEST_QEMU_BINARY is missing, Thomas Huth, 2017/09/15
- [Qemu-devel] [PULL 4/9] tests: Fix broken ivshmem-server-msi/-irq tests, Thomas Huth, 2017/09/15
- [Qemu-devel] [PULL 7/9] numa-test: Use hmp(), Thomas Huth, 2017/09/15
- [Qemu-devel] [PULL 6/9] qtest: Don't perform side effects inside assertion, Thomas Huth, 2017/09/15
- [Qemu-devel] [PULL 5/9] test-qga: Kill broken and dead QGA_TEST_SIDE_EFFECTING code, Thomas Huth, 2017/09/15
- [Qemu-devel] [PULL 9/9] qtest: Avoid passing raw strings through hmp(),
Thomas Huth <=
- [Qemu-devel] [PULL 8/9] libqtest: Remove dead qtest_instances variable, Thomas Huth, 2017/09/15
- Re: [Qemu-devel] [PULL 0/9] Fixes and improvements for various qtests, Peter Maydell, 2017/09/15