[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 7/7] tests/qtest/libqtest.c: Check for g_setenv() failure
From: |
Peter Maydell |
Subject: |
[PATCH 7/7] tests/qtest/libqtest.c: Check for g_setenv() failure |
Date: |
Tue, 12 Mar 2024 18:38:10 +0000 |
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(-)
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;
--
2.34.1
- [PATCH 0/7] various: 7 minor Coverity fixes, Peter Maydell, 2024/03/12
- [PATCH 4/7] hw/misc/pca9554: Correct error check bounds in get/set pin functions, Peter Maydell, 2024/03/12
- [PATCH 5/7] hw/nvram/mac_nvram: Report failure to write data, Peter Maydell, 2024/03/12
- [PATCH 6/7] tests/unit/test-throttle: Avoid unintended integer division, Peter Maydell, 2024/03/12
- [PATCH 2/7] tests/unit/socket-helpers: Don't close(-1), Peter Maydell, 2024/03/12
- [PATCH 3/7] net/af-xdp.c: Don't leak sock_fds array in net_init_af_xdp(), Peter Maydell, 2024/03/12
- [PATCH 7/7] tests/qtest/libqtest.c: Check for g_setenv() failure,
Peter Maydell <=
- [PATCH 1/7] tests/qtest/npcm7xx_emc_test: Don't leak cmd_line, Peter Maydell, 2024/03/12
- Re: [PATCH 0/7] various: 7 minor Coverity fixes, Richard Henderson, 2024/03/12