Skip to contentSkip to conversation

libqtest: check for g_setenv() failure

PATCH In review Peter Maydell 3 participants 3 messages Aug 20, 2021 – Sep 1, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libqtest: check for g_setenv() failure

g_setenv() can fail; check for it when starting a QEMU process when we set the QEMU_AUDIO_DRV environment variable.

Because this happens after fork() reporting an exact message via printf() is a bad idea; just exit(1), as we already do for the case of execlp() failure.

Fixes Coverity CID 1460117
---
 tests/qtest/libqtest.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/qtest/libqtest.c +3 -1
index 825b13a44c7..73f6b977a66 100644
@@ -301,7 +301,9 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     s->expected_status = 0;
     s->qemu_pid = fork();
     if (s->qemu_pid == 0) {
-        g_setenv("QEMU_AUDIO_DRV", "none", true);
+        if (!g_setenv("QEMU_AUDIO_DRV", "none", true)) {
+            exit(1);
+        }
         execlp("/bin/sh", "sh", "-c", command, NULL);
         exit(1);
     }
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Peter Maydell

g_setenv() can fail; check for it when starting a QEMU process when we set the QEMU_AUDIO_DRV environment variable.

Because this happens after fork() reporting an exact message via printf() is a bad idea; just exit(1), as we already do for the case of execlp() failure.

Quoted 5 lines
Fixes Coverity CID 1460117
---
 tests/qtest/libqtest.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
#2 lore raw
In reply to Peter Maydell
Quoted 18 lines · Peter Maydell

g_setenv() can fail; check for it when starting a QEMU process when we set the QEMU_AUDIO_DRV environment variable.

Because this happens after fork() reporting an exact message via printf() is a bad idea; just exit(1), as we already do for the case of execlp() failure.

Fixes Coverity CID 1460117
---
  tests/qtest/libqtest.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
tests/qtest/libqtest.c +0 -0
index 825b13a44c7..73f6b977a66 100644

tests/qtest/libqtest.c QTestState *qtest_init_without_qmp_handshake(const char *extra_args) · line 309

Quoted 10 lines
tests/qtest/libqtest.c +3 -1
@@ -301,7 +301,9 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
      s->expected_status = 0;
      s->qemu_pid = fork();
      if (s->qemu_pid == 0) {
-        g_setenv("QEMU_AUDIO_DRV", "none", true);
+        if (!g_setenv("QEMU_AUDIO_DRV", "none", true)) {
+            exit(1);
+        }
          execlp("/bin/sh", "sh", "-c", command, NULL);
          exit(1);
      }

Thanks, queued to my testing-next branch:

https://gitlab.com/thuth/qemu/-/commits/testing-next

Thomas