All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] tests: Fix some minor Coverity issues
@ 2021-05-25 13:44 Peter Maydell
  2021-05-25 13:44 ` [PATCH 1/6] tests/qtest/bios-tables-test: Check for dup2() failure Peter Maydell
                   ` (5 more replies)
  0 siblings, 6 replies; 17+ messages in thread
From: Peter Maydell @ 2021-05-25 13:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Stefan Berger, Michael S. Tsirkin,
	Paolo Bonzini, Igor Mammedov

We have a backlog of Coverity issues in tests (because we only
started running the scan on test code when we switched to meson
and started building the test code in "make" rather than only
in "make check"). This series fixes some of the easier ones.
There's nothing exciting here, it's all little nits.

thanks
-- PMM

Peter Maydell (6):
  tests/qtest/bios-tables-test: Check for dup2() failure
  tests/qtest/e1000e-test: Check qemu_recv() succeeded
  tests/qtest/hd-geo-test: Fix checks on mkstemp() return value
  tests/qtest/pflash-cfi02-test: Avoid potential integer overflow
  tests/qtest/tpm-tests: Remove unnecessary NULL checks
  tests/unit/test-vmstate: Assert that dup() and mkstemp() succeed

 tests/qtest/bios-tables-test.c  |  8 ++++++--
 tests/qtest/e1000e-test.c       |  3 ++-
 tests/qtest/hd-geo-test.c       |  4 ++--
 tests/qtest/pflash-cfi02-test.c |  2 +-
 tests/qtest/tpm-tests.c         | 12 ++++--------
 tests/unit/test-vmstate.c       |  2 ++
 6 files changed, 17 insertions(+), 14 deletions(-)

-- 
2.20.1



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/6] tests/qtest/bios-tables-test: Check for dup2() failure
  2021-05-25 13:44 [PATCH 0/6] tests: Fix some minor Coverity issues Peter Maydell
@ 2021-05-25 13:44 ` Peter Maydell
  2021-05-25 16:15   ` Stefan Berger
  2021-05-25 13:44 ` [PATCH 2/6] tests/qtest/e1000e-test: Check qemu_recv() succeeded Peter Maydell
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 17+ messages in thread
From: Peter Maydell @ 2021-05-25 13:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Stefan Berger, Michael S. Tsirkin,
	Paolo Bonzini, Igor Mammedov

Coverity notes that we don't check for dup2() failing.  Add some
assertions so that if it does ever happen we get some indication.
(This is similar to how we handle other "don't expect this syscall to
fail" checks in this test code.)

Fixes: Coverity CID 1432346
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 tests/qtest/bios-tables-test.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c
index 156d4174aa3..51d3a4e2390 100644
--- a/tests/qtest/bios-tables-test.c
+++ b/tests/qtest/bios-tables-test.c
@@ -489,10 +489,14 @@ static void test_acpi_asl(test_data *data)
                                                  exp_sdt->asl_file, sdt->asl_file);
                     int out = dup(STDOUT_FILENO);
                     int ret G_GNUC_UNUSED;
+                    int dupret;
 
-                    dup2(STDERR_FILENO, STDOUT_FILENO);
+                    g_assert(out >= 0);
+                    dupret = dup2(STDERR_FILENO, STDOUT_FILENO);
+                    g_assert(dupret >= 0);
                     ret = system(diff) ;
-                    dup2(out, STDOUT_FILENO);
+                    dupret = dup2(out, STDOUT_FILENO);
+                    g_assert(dupret >= 0);
                     close(out);
                     g_free(diff);
                 }
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 2/6] tests/qtest/e1000e-test: Check qemu_recv() succeeded
  2021-05-25 13:44 [PATCH 0/6] tests: Fix some minor Coverity issues Peter Maydell
  2021-05-25 13:44 ` [PATCH 1/6] tests/qtest/bios-tables-test: Check for dup2() failure Peter Maydell
@ 2021-05-25 13:44 ` Peter Maydell
  2021-05-25 16:15   ` Stefan Berger
  2021-05-25 13:44 ` [PATCH 3/6] tests/qtest/hd-geo-test: Fix checks on mkstemp() return value Peter Maydell
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 17+ messages in thread
From: Peter Maydell @ 2021-05-25 13:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Stefan Berger, Michael S. Tsirkin,
	Paolo Bonzini, Igor Mammedov

The e1000e_send_verify() test calls qemu_recv() but doesn't
check that the call succeeded, which annoys Coverity. Add
an explicit test check for the length of the data.

(This is a test check, not a "we assume this syscall always
succeeds", so we use g_assert_cmpint() rather than g_assert().)

Fixes: Coverity CID 1432324
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 tests/qtest/e1000e-test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/qtest/e1000e-test.c b/tests/qtest/e1000e-test.c
index fc226fdfeb5..0273fe4c156 100644
--- a/tests/qtest/e1000e-test.c
+++ b/tests/qtest/e1000e-test.c
@@ -93,7 +93,8 @@ static void e1000e_send_verify(QE1000E *d, int *test_sockets, QGuestAllocator *a
     /* Check data sent to the backend */
     ret = qemu_recv(test_sockets[0], &recv_len, sizeof(recv_len), 0);
     g_assert_cmpint(ret, == , sizeof(recv_len));
-    qemu_recv(test_sockets[0], buffer, 64, 0);
+    ret = qemu_recv(test_sockets[0], buffer, 64, 0);
+    g_assert_cmpint(ret, >=, 5);
     g_assert_cmpstr(buffer, == , "TEST");
 
     /* Free test data buffer */
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 3/6] tests/qtest/hd-geo-test: Fix checks on mkstemp() return value
  2021-05-25 13:44 [PATCH 0/6] tests: Fix some minor Coverity issues Peter Maydell
  2021-05-25 13:44 ` [PATCH 1/6] tests/qtest/bios-tables-test: Check for dup2() failure Peter Maydell
  2021-05-25 13:44 ` [PATCH 2/6] tests/qtest/e1000e-test: Check qemu_recv() succeeded Peter Maydell
@ 2021-05-25 13:44 ` Peter Maydell
  2021-05-25 13:59   ` Philippe Mathieu-Daudé
  2021-05-25 16:14   ` Stefan Berger
  2021-05-25 13:44 ` [PATCH 4/6] tests/qtest/pflash-cfi02-test: Avoid potential integer overflow Peter Maydell
                   ` (2 subsequent siblings)
  5 siblings, 2 replies; 17+ messages in thread
From: Peter Maydell @ 2021-05-25 13:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Stefan Berger, Michael S. Tsirkin,
	Paolo Bonzini, Igor Mammedov

Coverity notices that the checks against mkstemp() failing in
create_qcow2_with_mbr() are wrong: mkstemp returns -1 on failure but
the check is just "g_assert(fd)".  Fix to use "g_assert(fd >= 0)",
matching the correct check in create_test_img().

Fixes: Coverity CID 1432274
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 tests/qtest/hd-geo-test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
index f7b7cfbc2d1..113126ae06c 100644
--- a/tests/qtest/hd-geo-test.c
+++ b/tests/qtest/hd-geo-test.c
@@ -464,7 +464,7 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors)
     }
 
     fd = mkstemp(raw_path);
-    g_assert(fd);
+    g_assert(fd >= 0);
     close(fd);
 
     fd = open(raw_path, O_WRONLY);
@@ -474,7 +474,7 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors)
     close(fd);
 
     fd = mkstemp(qcow2_path);
-    g_assert(fd);
+    g_assert(fd >= 0);
     close(fd);
 
     qemu_img_path = getenv("QTEST_QEMU_IMG");
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 4/6] tests/qtest/pflash-cfi02-test: Avoid potential integer overflow
  2021-05-25 13:44 [PATCH 0/6] tests: Fix some minor Coverity issues Peter Maydell
                   ` (2 preceding siblings ...)
  2021-05-25 13:44 ` [PATCH 3/6] tests/qtest/hd-geo-test: Fix checks on mkstemp() return value Peter Maydell
@ 2021-05-25 13:44 ` Peter Maydell
  2021-05-25 14:00   ` Philippe Mathieu-Daudé
  2021-05-25 16:14   ` Stefan Berger
  2021-05-25 13:44 ` [PATCH 5/6] tests/qtest/tpm-tests: Remove unnecessary NULL checks Peter Maydell
  2021-05-25 13:44 ` [PATCH 6/6] tests/unit/test-vmstate: Assert that dup() and mkstemp() succeed Peter Maydell
  5 siblings, 2 replies; 17+ messages in thread
From: Peter Maydell @ 2021-05-25 13:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Stefan Berger, Michael S. Tsirkin,
	Paolo Bonzini, Igor Mammedov

Coverity points out that we calculate a 64-bit value using 32-bit
arithmetic; add the cast to force the multiply to be done as 64-bits.
(The overflow will never happen with the current test data.)

Fixes: Coverity CID 1432320
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 tests/qtest/pflash-cfi02-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/qtest/pflash-cfi02-test.c b/tests/qtest/pflash-cfi02-test.c
index 60db81a3a2b..6168edc821a 100644
--- a/tests/qtest/pflash-cfi02-test.c
+++ b/tests/qtest/pflash-cfi02-test.c
@@ -406,7 +406,7 @@ static void test_geometry(const void *opaque)
 
     for (int region = 0; region < nb_erase_regions; ++region) {
         for (uint32_t i = 0; i < c->nb_blocs[region]; ++i) {
-            uint64_t byte_addr = i * c->sector_len[region];
+            uint64_t byte_addr = (uint64_t)i * c->sector_len[region];
             g_assert_cmphex(flash_read(c, byte_addr), ==, bank_mask(c));
         }
     }
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 5/6] tests/qtest/tpm-tests: Remove unnecessary NULL checks
  2021-05-25 13:44 [PATCH 0/6] tests: Fix some minor Coverity issues Peter Maydell
                   ` (3 preceding siblings ...)
  2021-05-25 13:44 ` [PATCH 4/6] tests/qtest/pflash-cfi02-test: Avoid potential integer overflow Peter Maydell
@ 2021-05-25 13:44 ` Peter Maydell
  2021-05-25 14:00   ` Philippe Mathieu-Daudé
  2021-05-25 16:14   ` Stefan Berger
  2021-05-25 13:44 ` [PATCH 6/6] tests/unit/test-vmstate: Assert that dup() and mkstemp() succeed Peter Maydell
  5 siblings, 2 replies; 17+ messages in thread
From: Peter Maydell @ 2021-05-25 13:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Stefan Berger, Michael S. Tsirkin,
	Paolo Bonzini, Igor Mammedov

Coverity points out that in tpm_test_swtpm_migration_test() we
assume that src_tpm_addr and dst_tpm_addr are non-NULL (we
pass them to tpm_util_migration_start_qemu() which will
unconditionally dereference them) but then later explicitly
check them for NULL. Remove the pointless checks.

Fixes: Coverity CID 1432367, 1432359

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 tests/qtest/tpm-tests.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/tests/qtest/tpm-tests.c b/tests/qtest/tpm-tests.c
index 0da3a8a4df5..25073d1f9e9 100644
--- a/tests/qtest/tpm-tests.c
+++ b/tests/qtest/tpm-tests.c
@@ -123,14 +123,10 @@ void tpm_test_swtpm_migration_test(const char *src_tpm_path,
     qtest_quit(src_qemu);
 
     tpm_util_swtpm_kill(dst_tpm_pid);
-    if (dst_tpm_addr) {
-        g_unlink(dst_tpm_addr->u.q_unix.path);
-        qapi_free_SocketAddress(dst_tpm_addr);
-    }
+    g_unlink(dst_tpm_addr->u.q_unix.path);
+    qapi_free_SocketAddress(dst_tpm_addr);
 
     tpm_util_swtpm_kill(src_tpm_pid);
-    if (src_tpm_addr) {
-        g_unlink(src_tpm_addr->u.q_unix.path);
-        qapi_free_SocketAddress(src_tpm_addr);
-    }
+    g_unlink(src_tpm_addr->u.q_unix.path);
+    qapi_free_SocketAddress(src_tpm_addr);
 }
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 6/6] tests/unit/test-vmstate: Assert that dup() and mkstemp() succeed
  2021-05-25 13:44 [PATCH 0/6] tests: Fix some minor Coverity issues Peter Maydell
                   ` (4 preceding siblings ...)
  2021-05-25 13:44 ` [PATCH 5/6] tests/qtest/tpm-tests: Remove unnecessary NULL checks Peter Maydell
@ 2021-05-25 13:44 ` Peter Maydell
  2021-05-25 14:02   ` Philippe Mathieu-Daudé
  2021-05-25 16:13   ` Stefan Berger
  5 siblings, 2 replies; 17+ messages in thread
From: Peter Maydell @ 2021-05-25 13:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Stefan Berger, Michael S. Tsirkin,
	Paolo Bonzini, Igor Mammedov

Coverity complains that we don't check for failures from dup()
and mkstemp(); add asserts that these syscalls succeeded.

Fixes: Coverity CID 1432516, 1432574
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 tests/unit/test-vmstate.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/unit/test-vmstate.c b/tests/unit/test-vmstate.c
index a001879585e..8d46af61511 100644
--- a/tests/unit/test-vmstate.c
+++ b/tests/unit/test-vmstate.c
@@ -44,6 +44,7 @@ static QEMUFile *open_test_file(bool write)
     QIOChannel *ioc;
     QEMUFile *f;
 
+    g_assert(fd >= 0);
     lseek(fd, 0, SEEK_SET);
     if (write) {
         g_assert_cmpint(ftruncate(fd, 0), ==, 0);
@@ -1486,6 +1487,7 @@ int main(int argc, char **argv)
     g_autofree char *temp_file = g_strdup_printf("%s/vmst.test.XXXXXX",
                                                  g_get_tmp_dir());
     temp_fd = mkstemp(temp_file);
+    g_assert(temp_fd >= 0);
 
     module_call_init(MODULE_INIT_QOM);
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/6] tests/qtest/hd-geo-test: Fix checks on mkstemp() return value
  2021-05-25 13:44 ` [PATCH 3/6] tests/qtest/hd-geo-test: Fix checks on mkstemp() return value Peter Maydell
@ 2021-05-25 13:59   ` Philippe Mathieu-Daudé
  2021-05-25 16:14   ` Stefan Berger
  1 sibling, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-05-25 13:59 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Michael S. Tsirkin, Stefan Berger,
	Igor Mammedov, Paolo Bonzini

On 5/25/21 3:44 PM, Peter Maydell wrote:
> Coverity notices that the checks against mkstemp() failing in
> create_qcow2_with_mbr() are wrong: mkstemp returns -1 on failure but
> the check is just "g_assert(fd)".  Fix to use "g_assert(fd >= 0)",
> matching the correct check in create_test_img().
> 
> Fixes: Coverity CID 1432274
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  tests/qtest/hd-geo-test.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 4/6] tests/qtest/pflash-cfi02-test: Avoid potential integer overflow
  2021-05-25 13:44 ` [PATCH 4/6] tests/qtest/pflash-cfi02-test: Avoid potential integer overflow Peter Maydell
@ 2021-05-25 14:00   ` Philippe Mathieu-Daudé
  2021-05-25 16:14   ` Stefan Berger
  1 sibling, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-05-25 14:00 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Michael S. Tsirkin, Stefan Berger,
	Igor Mammedov, Paolo Bonzini

On 5/25/21 3:44 PM, Peter Maydell wrote:
> Coverity points out that we calculate a 64-bit value using 32-bit
> arithmetic; add the cast to force the multiply to be done as 64-bits.
> (The overflow will never happen with the current test data.)
> 
> Fixes: Coverity CID 1432320
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  tests/qtest/pflash-cfi02-test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 5/6] tests/qtest/tpm-tests: Remove unnecessary NULL checks
  2021-05-25 13:44 ` [PATCH 5/6] tests/qtest/tpm-tests: Remove unnecessary NULL checks Peter Maydell
@ 2021-05-25 14:00   ` Philippe Mathieu-Daudé
  2021-05-25 16:14   ` Stefan Berger
  1 sibling, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-05-25 14:00 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Michael S. Tsirkin, Stefan Berger,
	Igor Mammedov, Paolo Bonzini

On 5/25/21 3:44 PM, Peter Maydell wrote:
> Coverity points out that in tpm_test_swtpm_migration_test() we
> assume that src_tpm_addr and dst_tpm_addr are non-NULL (we
> pass them to tpm_util_migration_start_qemu() which will
> unconditionally dereference them) but then later explicitly
> check them for NULL. Remove the pointless checks.
> 
> Fixes: Coverity CID 1432367, 1432359
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  tests/qtest/tpm-tests.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 6/6] tests/unit/test-vmstate: Assert that dup() and mkstemp() succeed
  2021-05-25 13:44 ` [PATCH 6/6] tests/unit/test-vmstate: Assert that dup() and mkstemp() succeed Peter Maydell
@ 2021-05-25 14:02   ` Philippe Mathieu-Daudé
  2021-05-25 16:13   ` Stefan Berger
  1 sibling, 0 replies; 17+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-05-25 14:02 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Michael S. Tsirkin, Stefan Berger,
	Igor Mammedov, Paolo Bonzini

On 5/25/21 3:44 PM, Peter Maydell wrote:
> Coverity complains that we don't check for failures from dup()
> and mkstemp(); add asserts that these syscalls succeeded.
> 
> Fixes: Coverity CID 1432516, 1432574
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  tests/unit/test-vmstate.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/tests/unit/test-vmstate.c b/tests/unit/test-vmstate.c
> index a001879585e..8d46af61511 100644
> --- a/tests/unit/test-vmstate.c
> +++ b/tests/unit/test-vmstate.c
> @@ -44,6 +44,7 @@ static QEMUFile *open_test_file(bool write)
>      QIOChannel *ioc;
>      QEMUFile *f;
>  

Eventually move the assignation before the assertion:

-- >8 --
@@ -40,10 +40,12 @@ static int temp_fd;
 /* Duplicate temp_fd and seek to the beginning of the file */
 static QEMUFile *open_test_file(bool write)
 {
-    int fd = dup(temp_fd);
+    int fd;
     QIOChannel *ioc;
     QEMUFile *f;

+    fd = dup(temp_fd);
+    g_assert(fd >= 0);
     lseek(fd, 0, SEEK_SET);
     if (write) {
         g_assert_cmpint(ftruncate(fd, 0), ==, 0);

---

Regardless:
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> +    g_assert(fd >= 0);
>      lseek(fd, 0, SEEK_SET);
>      if (write) {
>          g_assert_cmpint(ftruncate(fd, 0), ==, 0);
> @@ -1486,6 +1487,7 @@ int main(int argc, char **argv)
>      g_autofree char *temp_file = g_strdup_printf("%s/vmst.test.XXXXXX",
>                                                   g_get_tmp_dir());
>      temp_fd = mkstemp(temp_file);
> +    g_assert(temp_fd >= 0);
>  
>      module_call_init(MODULE_INIT_QOM);
>  
> 



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 6/6] tests/unit/test-vmstate: Assert that dup() and mkstemp() succeed
  2021-05-25 13:44 ` [PATCH 6/6] tests/unit/test-vmstate: Assert that dup() and mkstemp() succeed Peter Maydell
  2021-05-25 14:02   ` Philippe Mathieu-Daudé
@ 2021-05-25 16:13   ` Stefan Berger
  1 sibling, 0 replies; 17+ messages in thread
From: Stefan Berger @ 2021-05-25 16:13 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Stefan Berger, Michael S. Tsirkin,
	Paolo Bonzini, Igor Mammedov


On 5/25/21 9:44 AM, Peter Maydell wrote:
> Coverity complains that we don't check for failures from dup()
> and mkstemp(); add asserts that these syscalls succeeded.
>
> Fixes: Coverity CID 1432516, 1432574
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>


> ---
>   tests/unit/test-vmstate.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/tests/unit/test-vmstate.c b/tests/unit/test-vmstate.c
> index a001879585e..8d46af61511 100644
> --- a/tests/unit/test-vmstate.c
> +++ b/tests/unit/test-vmstate.c
> @@ -44,6 +44,7 @@ static QEMUFile *open_test_file(bool write)
>       QIOChannel *ioc;
>       QEMUFile *f;
>
> +    g_assert(fd >= 0);
>       lseek(fd, 0, SEEK_SET);
>       if (write) {
>           g_assert_cmpint(ftruncate(fd, 0), ==, 0);
> @@ -1486,6 +1487,7 @@ int main(int argc, char **argv)
>       g_autofree char *temp_file = g_strdup_printf("%s/vmst.test.XXXXXX",
>                                                    g_get_tmp_dir());
>       temp_fd = mkstemp(temp_file);
> +    g_assert(temp_fd >= 0);
>
>       module_call_init(MODULE_INIT_QOM);
>


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 5/6] tests/qtest/tpm-tests: Remove unnecessary NULL checks
  2021-05-25 13:44 ` [PATCH 5/6] tests/qtest/tpm-tests: Remove unnecessary NULL checks Peter Maydell
  2021-05-25 14:00   ` Philippe Mathieu-Daudé
@ 2021-05-25 16:14   ` Stefan Berger
  1 sibling, 0 replies; 17+ messages in thread
From: Stefan Berger @ 2021-05-25 16:14 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Michael S. Tsirkin, Stefan Berger,
	Igor Mammedov, Paolo Bonzini


On 5/25/21 9:44 AM, Peter Maydell wrote:
> Coverity points out that in tpm_test_swtpm_migration_test() we
> assume that src_tpm_addr and dst_tpm_addr are non-NULL (we
> pass them to tpm_util_migration_start_qemu() which will
> unconditionally dereference them) but then later explicitly
> check them for NULL. Remove the pointless checks.
>
> Fixes: Coverity CID 1432367, 1432359
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>


> ---
>   tests/qtest/tpm-tests.c | 12 ++++--------
>   1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/tests/qtest/tpm-tests.c b/tests/qtest/tpm-tests.c
> index 0da3a8a4df5..25073d1f9e9 100644
> --- a/tests/qtest/tpm-tests.c
> +++ b/tests/qtest/tpm-tests.c
> @@ -123,14 +123,10 @@ void tpm_test_swtpm_migration_test(const char *src_tpm_path,
>       qtest_quit(src_qemu);
>
>       tpm_util_swtpm_kill(dst_tpm_pid);
> -    if (dst_tpm_addr) {
> -        g_unlink(dst_tpm_addr->u.q_unix.path);
> -        qapi_free_SocketAddress(dst_tpm_addr);
> -    }
> +    g_unlink(dst_tpm_addr->u.q_unix.path);
> +    qapi_free_SocketAddress(dst_tpm_addr);
>
>       tpm_util_swtpm_kill(src_tpm_pid);
> -    if (src_tpm_addr) {
> -        g_unlink(src_tpm_addr->u.q_unix.path);
> -        qapi_free_SocketAddress(src_tpm_addr);
> -    }
> +    g_unlink(src_tpm_addr->u.q_unix.path);
> +    qapi_free_SocketAddress(src_tpm_addr);
>   }


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 4/6] tests/qtest/pflash-cfi02-test: Avoid potential integer overflow
  2021-05-25 13:44 ` [PATCH 4/6] tests/qtest/pflash-cfi02-test: Avoid potential integer overflow Peter Maydell
  2021-05-25 14:00   ` Philippe Mathieu-Daudé
@ 2021-05-25 16:14   ` Stefan Berger
  1 sibling, 0 replies; 17+ messages in thread
From: Stefan Berger @ 2021-05-25 16:14 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Stefan Berger, Michael S. Tsirkin,
	Paolo Bonzini, Igor Mammedov


On 5/25/21 9:44 AM, Peter Maydell wrote:
> Coverity points out that we calculate a 64-bit value using 32-bit
> arithmetic; add the cast to force the multiply to be done as 64-bits.
> (The overflow will never happen with the current test data.)
>
> Fixes: Coverity CID 1432320
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>


> ---
>   tests/qtest/pflash-cfi02-test.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tests/qtest/pflash-cfi02-test.c b/tests/qtest/pflash-cfi02-test.c
> index 60db81a3a2b..6168edc821a 100644
> --- a/tests/qtest/pflash-cfi02-test.c
> +++ b/tests/qtest/pflash-cfi02-test.c
> @@ -406,7 +406,7 @@ static void test_geometry(const void *opaque)
>
>       for (int region = 0; region < nb_erase_regions; ++region) {
>           for (uint32_t i = 0; i < c->nb_blocs[region]; ++i) {
> -            uint64_t byte_addr = i * c->sector_len[region];
> +            uint64_t byte_addr = (uint64_t)i * c->sector_len[region];
>               g_assert_cmphex(flash_read(c, byte_addr), ==, bank_mask(c));
>           }
>       }


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/6] tests/qtest/hd-geo-test: Fix checks on mkstemp() return value
  2021-05-25 13:44 ` [PATCH 3/6] tests/qtest/hd-geo-test: Fix checks on mkstemp() return value Peter Maydell
  2021-05-25 13:59   ` Philippe Mathieu-Daudé
@ 2021-05-25 16:14   ` Stefan Berger
  1 sibling, 0 replies; 17+ messages in thread
From: Stefan Berger @ 2021-05-25 16:14 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Michael S. Tsirkin, Stefan Berger,
	Igor Mammedov, Paolo Bonzini


On 5/25/21 9:44 AM, Peter Maydell wrote:
> Coverity notices that the checks against mkstemp() failing in
> create_qcow2_with_mbr() are wrong: mkstemp returns -1 on failure but
> the check is just "g_assert(fd)".  Fix to use "g_assert(fd >= 0)",
> matching the correct check in create_test_img().
>
> Fixes: Coverity CID 1432274
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>


> ---
>   tests/qtest/hd-geo-test.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
> index f7b7cfbc2d1..113126ae06c 100644
> --- a/tests/qtest/hd-geo-test.c
> +++ b/tests/qtest/hd-geo-test.c
> @@ -464,7 +464,7 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors)
>       }
>
>       fd = mkstemp(raw_path);
> -    g_assert(fd);
> +    g_assert(fd >= 0);
>       close(fd);
>
>       fd = open(raw_path, O_WRONLY);
> @@ -474,7 +474,7 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors)
>       close(fd);
>
>       fd = mkstemp(qcow2_path);
> -    g_assert(fd);
> +    g_assert(fd >= 0);
>       close(fd);
>
>       qemu_img_path = getenv("QTEST_QEMU_IMG");


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/6] tests/qtest/e1000e-test: Check qemu_recv() succeeded
  2021-05-25 13:44 ` [PATCH 2/6] tests/qtest/e1000e-test: Check qemu_recv() succeeded Peter Maydell
@ 2021-05-25 16:15   ` Stefan Berger
  0 siblings, 0 replies; 17+ messages in thread
From: Stefan Berger @ 2021-05-25 16:15 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Michael S. Tsirkin, Stefan Berger,
	Igor Mammedov, Paolo Bonzini


On 5/25/21 9:44 AM, Peter Maydell wrote:
> The e1000e_send_verify() test calls qemu_recv() but doesn't
> check that the call succeeded, which annoys Coverity. Add
> an explicit test check for the length of the data.
>
> (This is a test check, not a "we assume this syscall always
> succeeds", so we use g_assert_cmpint() rather than g_assert().)
>
> Fixes: Coverity CID 1432324
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>


> ---
>   tests/qtest/e1000e-test.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tests/qtest/e1000e-test.c b/tests/qtest/e1000e-test.c
> index fc226fdfeb5..0273fe4c156 100644
> --- a/tests/qtest/e1000e-test.c
> +++ b/tests/qtest/e1000e-test.c
> @@ -93,7 +93,8 @@ static void e1000e_send_verify(QE1000E *d, int *test_sockets, QGuestAllocator *a
>       /* Check data sent to the backend */
>       ret = qemu_recv(test_sockets[0], &recv_len, sizeof(recv_len), 0);
>       g_assert_cmpint(ret, == , sizeof(recv_len));
> -    qemu_recv(test_sockets[0], buffer, 64, 0);
> +    ret = qemu_recv(test_sockets[0], buffer, 64, 0);
> +    g_assert_cmpint(ret, >=, 5);
>       g_assert_cmpstr(buffer, == , "TEST");
>
>       /* Free test data buffer */


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/6] tests/qtest/bios-tables-test: Check for dup2() failure
  2021-05-25 13:44 ` [PATCH 1/6] tests/qtest/bios-tables-test: Check for dup2() failure Peter Maydell
@ 2021-05-25 16:15   ` Stefan Berger
  0 siblings, 0 replies; 17+ messages in thread
From: Stefan Berger @ 2021-05-25 16:15 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Michael S. Tsirkin, Stefan Berger,
	Igor Mammedov, Paolo Bonzini


On 5/25/21 9:44 AM, Peter Maydell wrote:
> Coverity notes that we don't check for dup2() failing.  Add some
> assertions so that if it does ever happen we get some indication.
> (This is similar to how we handle other "don't expect this syscall to
> fail" checks in this test code.)
>
> Fixes: Coverity CID 1432346
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>


> ---
>   tests/qtest/bios-tables-test.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c
> index 156d4174aa3..51d3a4e2390 100644
> --- a/tests/qtest/bios-tables-test.c
> +++ b/tests/qtest/bios-tables-test.c
> @@ -489,10 +489,14 @@ static void test_acpi_asl(test_data *data)
>                                                    exp_sdt->asl_file, sdt->asl_file);
>                       int out = dup(STDOUT_FILENO);
>                       int ret G_GNUC_UNUSED;
> +                    int dupret;
>
> -                    dup2(STDERR_FILENO, STDOUT_FILENO);
> +                    g_assert(out >= 0);
> +                    dupret = dup2(STDERR_FILENO, STDOUT_FILENO);
> +                    g_assert(dupret >= 0);
>                       ret = system(diff) ;
> -                    dup2(out, STDOUT_FILENO);
> +                    dupret = dup2(out, STDOUT_FILENO);
> +                    g_assert(dupret >= 0);
>                       close(out);
>                       g_free(diff);
>                   }


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-05-25 17:25 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-25 13:44 [PATCH 0/6] tests: Fix some minor Coverity issues Peter Maydell
2021-05-25 13:44 ` [PATCH 1/6] tests/qtest/bios-tables-test: Check for dup2() failure Peter Maydell
2021-05-25 16:15   ` Stefan Berger
2021-05-25 13:44 ` [PATCH 2/6] tests/qtest/e1000e-test: Check qemu_recv() succeeded Peter Maydell
2021-05-25 16:15   ` Stefan Berger
2021-05-25 13:44 ` [PATCH 3/6] tests/qtest/hd-geo-test: Fix checks on mkstemp() return value Peter Maydell
2021-05-25 13:59   ` Philippe Mathieu-Daudé
2021-05-25 16:14   ` Stefan Berger
2021-05-25 13:44 ` [PATCH 4/6] tests/qtest/pflash-cfi02-test: Avoid potential integer overflow Peter Maydell
2021-05-25 14:00   ` Philippe Mathieu-Daudé
2021-05-25 16:14   ` Stefan Berger
2021-05-25 13:44 ` [PATCH 5/6] tests/qtest/tpm-tests: Remove unnecessary NULL checks Peter Maydell
2021-05-25 14:00   ` Philippe Mathieu-Daudé
2021-05-25 16:14   ` Stefan Berger
2021-05-25 13:44 ` [PATCH 6/6] tests/unit/test-vmstate: Assert that dup() and mkstemp() succeed Peter Maydell
2021-05-25 14:02   ` Philippe Mathieu-Daudé
2021-05-25 16:13   ` Stefan Berger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.