diff mbox series

[7/7] tests/qtest/libqtest.c: Check for g_setenv() failure

Message ID 20240312183810.557768-8-peter.maydell@linaro.org
State Superseded
Headers show
Series various: 7 minor Coverity fixes | expand

Commit Message

Peter Maydell March 12, 2024, 6:38 p.m. UTC
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>
---
 tests/qtest/libqtest.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Philippe Mathieu-Daudé March 12, 2024, 8:20 p.m. UTC | #1
On 12/3/24 19:38, Peter Maydell wrote:
> 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>
> ---
>   tests/qtest/libqtest.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
diff mbox series

Patch

diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index f33a2108610..d8f80d335e7 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;