aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2024-03-25 10:41:01 +0000
committerPeter Maydell <peter.maydell@linaro.org>2024-03-25 10:41:01 +0000
commit55c79639d553c1b7a82b4cde781ad5f316f45b0e (patch)
treee3a43f9adf81fbc48ac3d39898f7f820517cae35
parentc44a352a77225aeb8b7db9fe9af3361c08b5b1f9 (diff)
tests/qtest/libqtest.c: Check for g_setenv() failurepull-target-arm-20240325
Coverity points out that g_setenv() can fail and we don't check for this in qtest_inproc_init(). In practice this will only fail if a memory allocation failed in setenv() or if the caller passed an invalid architecture name (e.g. one with an '=' in it), so rather than requiring the callsite to check for failure, make g_setenv() failure fatal here, similarly to what we did in commit aca68d95c515. Resolves: Coverity CID 1497485 Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-id: 20240312183810.557768-8-peter.maydell@linaro.org
-rw-r--r--tests/qtest/libqtest.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index f33a210861..d8f80d335e 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -1814,7 +1814,11 @@ QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch,
* way, qtest_get_arch works for inproc qtest.
*/
gchar *bin_path = g_strconcat("/qemu-system-", arch, NULL);
- g_setenv("QTEST_QEMU_BINARY", bin_path, 0);
+ if (!g_setenv("QTEST_QEMU_BINARY", bin_path, 0)) {
+ fprintf(stderr,
+ "Could not set environment variable QTEST_QEMU_BINARY\n");
+ exit(1);
+ }
g_free(bin_path);
return qts;