[PATCH 1/6] tests/qtest/bios-tables-test: Check for dup2() failure

Peter Maydell posted 6 patches 4 years, 1 month ago
Maintainers: Igor Mammedov <imammedo@redhat.com>, Stefan Berger <stefanb@linux.vnet.ibm.com>, "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Thomas Huth <thuth@redhat.com>, Laurent Vivier <lvivier@redhat.com>
[PATCH 1/6] tests/qtest/bios-tables-test: Check for dup2() failure
Posted by Peter Maydell 4 years, 1 month ago
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


Re: [PATCH 1/6] tests/qtest/bios-tables-test: Check for dup2() failure
Posted by Stefan Berger 4 years, 1 month ago
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);
>                   }