[PATCH] tests/qtest/arm-cpu-features: Fix thinko in g_strdup_printf() call

Peter Maydell posted 1 patch 2 weeks, 6 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260317111121.2062455-1-peter.maydell@linaro.org
Maintainers: Peter Maydell <peter.maydell@linaro.org>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
tests/qtest/arm-cpu-features.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] tests/qtest/arm-cpu-features: Fix thinko in g_strdup_printf() call
Posted by Peter Maydell 2 weeks, 6 days ago
In commit 62272f9f8891 we changed some uses of fixed char arrays
to call g_strdup_printf() instead. In one place I made a silly
error where in changing
  sprintf(name, "fmt string", ...)
to
  name = g_strdup_printf("fmt string", ...)
I forgot to delete "name" from the argument list.

Luckily Coverity spotted this (as CID 1645771) because at this
point "name" is NULL and passing g_strdup_printf() a NULL first
argument is not valid.

We didn't notice the mistake in testing or CI because this bit of
code is only run if on an AArch64 host with KVM and SVE available.

Correct the error by removing the stray function argument.

Fixes: 62272f9f8891 ("tests/qtest/arm-cpu-features: Use g_strdup_printf() instead of char arrays")
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 tests/qtest/arm-cpu-features.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/qtest/arm-cpu-features.c b/tests/qtest/arm-cpu-features.c
index 5444e4d40b..bbdd89a81d 100644
--- a/tests/qtest/arm-cpu-features.c
+++ b/tests/qtest/arm-cpu-features.c
@@ -612,7 +612,7 @@ static void test_query_cpu_model_expansion_kvm(const void *data)
              * we need at least one vector length enabled.
              */
             vq = __builtin_ffsll(vls);
-            name = g_strdup_printf(name, "sve%u", vq * 128);
+            name = g_strdup_printf("sve%u", vq * 128);
             error = g_strdup_printf("cannot disable %s", name);
             assert_error(qts, "host", error, "{ %s: false }", name);
             g_free(error);
-- 
2.43.0
Re: [PATCH] tests/qtest/arm-cpu-features: Fix thinko in g_strdup_printf() call
Posted by Cédric Le Goater 2 weeks, 6 days ago
On 3/17/26 12:11, Peter Maydell wrote:
> In commit 62272f9f8891 we changed some uses of fixed char arrays
> to call g_strdup_printf() instead. In one place I made a silly
> error where in changing
>    sprintf(name, "fmt string", ...)
> to
>    name = g_strdup_printf("fmt string", ...)
> I forgot to delete "name" from the argument list.
> 
> Luckily Coverity spotted this (as CID 1645771) because at this
> point "name" is NULL and passing g_strdup_printf() a NULL first
> argument is not valid.
> 
> We didn't notice the mistake in testing or CI because this bit of
> code is only run if on an AArch64 host with KVM and SVE available.
> 
> Correct the error by removing the stray function argument.
> 
> Fixes: 62272f9f8891 ("tests/qtest/arm-cpu-features: Use g_strdup_printf() instead of char arrays")
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   tests/qtest/arm-cpu-features.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/qtest/arm-cpu-features.c b/tests/qtest/arm-cpu-features.c
> index 5444e4d40b..bbdd89a81d 100644
> --- a/tests/qtest/arm-cpu-features.c
> +++ b/tests/qtest/arm-cpu-features.c
> @@ -612,7 +612,7 @@ static void test_query_cpu_model_expansion_kvm(const void *data)
>                * we need at least one vector length enabled.
>                */
>               vq = __builtin_ffsll(vls);
> -            name = g_strdup_printf(name, "sve%u", vq * 128);
> +            name = g_strdup_printf("sve%u", vq * 128);
>               error = g_strdup_printf("cannot disable %s", name);
>               assert_error(qts, "host", error, "{ %s: false }", name);
>               g_free(error);

Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


Re: [PATCH] tests/qtest/arm-cpu-features: Fix thinko in g_strdup_printf() call
Posted by Philippe Mathieu-Daudé 2 weeks, 6 days ago
On 17/3/26 12:11, Peter Maydell wrote:
> In commit 62272f9f8891 we changed some uses of fixed char arrays
> to call g_strdup_printf() instead. In one place I made a silly
> error where in changing
>    sprintf(name, "fmt string", ...)
> to
>    name = g_strdup_printf("fmt string", ...)
> I forgot to delete "name" from the argument list.
> 
> Luckily Coverity spotted this (as CID 1645771) because at this
> point "name" is NULL and passing g_strdup_printf() a NULL first
> argument is not valid.
> 
> We didn't notice the mistake in testing or CI because this bit of
> code is only run if on an AArch64 host with KVM and SVE available.
> 
> Correct the error by removing the stray function argument.
> 
> Fixes: 62272f9f8891 ("tests/qtest/arm-cpu-features: Use g_strdup_printf() instead of char arrays")
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   tests/qtest/arm-cpu-features.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

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