[Qemu-devel] [PATCH] hw: intel_iommu: initialize 'name' in vtd_find_add_as

Li Qiang posted 1 patch 4 years, 8 months ago
Test FreeBSD passed
Test docker-mingw@fedora passed
Test docker-clang@ubuntu passed
Test s390x failed
Test checkpatch passed
Test asan passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20190801162820.11238-1-liq3ea@163.com
Maintainers: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Michael S. Tsirkin" <mst@redhat.com>, Eduardo Habkost <ehabkost@redhat.com>, Richard Henderson <rth@twiddle.net>, Paolo Bonzini <pbonzini@redhat.com>
hw/i386/intel_iommu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[Qemu-devel] [PATCH] hw: intel_iommu: initialize 'name' in vtd_find_add_as
Posted by Li Qiang 4 years, 8 months ago
The 'name' variable in vtd_find_add_as function is not initialized
now, so when in gdb, we will got following output:

(gdb) p name
$1 = "vtd-00.0\000\000\000\000\000\000\000\000\060\330\377\377\377\177\000\000\001\000\000\000\000\000\000\000p\330\377\377\377\177\000\000\353\362\372VUU\000\000p\330\377\377\377\177\000\000  \000\000\060b\000\000\220\021\000\000\360a\000\000\200\"\002\000\020a\000\000  \000\000\060b\000\000\200\332\377\377\377\177\000\000\240\330\377\377\377\177\000\000<\364\372VUU\000\000\000\000\000\000\000\000\000\000  \000\000\060b\000"

After this patch, it is more clear:

(gdb) p name
$1 = "vtd-00.0", '\000' <repeats 119 times>

Signed-off-by: Li Qiang <liq3ea@163.com>
---
 hw/i386/intel_iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index de86f53b4e..e379c2a512 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -3286,7 +3286,7 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, PCIBus *bus, int devfn)
     uintptr_t key = (uintptr_t)bus;
     VTDBus *vtd_bus = g_hash_table_lookup(s->vtd_as_by_busptr, &key);
     VTDAddressSpace *vtd_dev_as;
-    char name[128];
+    char name[128] = {};
 
     if (!vtd_bus) {
         uintptr_t *new_key = g_malloc(sizeof(*new_key));
-- 
2.17.1



Re: [Qemu-devel] [PATCH] hw: intel_iommu: initialize 'name' in vtd_find_add_as
Posted by Paolo Bonzini 4 years, 8 months ago
On 01/08/19 18:28, Li Qiang wrote:
> The 'name' variable in vtd_find_add_as function is not initialized
> now, so when in gdb, we will got following output:
> 
> (gdb) p name
> $1 = "vtd-00.0\000\000\000\000\000\000\000\000\060\330\377\377\377\177\000\000\001\000\000\000\000\000\000\000p\330\377\377\377\177\000\000\353\362\372VUU\000\000p\330\377\377\377\177\000\000  \000\000\060b\000\000\220\021\000\000\360a\000\000\200\"\002\000\020a\000\000  \000\000\060b\000\000\200\332\377\377\377\177\000\000\240\330\377\377\377\177\000\000<\364\372VUU\000\000\000\000\000\000\000\000\000\000  \000\000\060b\000"
> 
> After this patch, it is more clear:
> 
> (gdb) p name
> $1 = "vtd-00.0", '\000' <repeats 119 times>
> 
> Signed-off-by: Li Qiang <liq3ea@163.com>

There are hundreds of other occurrences of this same phenomenon.  It's
not a bug, it's just how the debugger chooses to print character arrays.

Paolo

> ---
>  hw/i386/intel_iommu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
> index de86f53b4e..e379c2a512 100644
> --- a/hw/i386/intel_iommu.c
> +++ b/hw/i386/intel_iommu.c
> @@ -3286,7 +3286,7 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, PCIBus *bus, int devfn)
>      uintptr_t key = (uintptr_t)bus;
>      VTDBus *vtd_bus = g_hash_table_lookup(s->vtd_as_by_busptr, &key);
>      VTDAddressSpace *vtd_dev_as;
> -    char name[128];
> +    char name[128] = {};
>  
>      if (!vtd_bus) {
>          uintptr_t *new_key = g_malloc(sizeof(*new_key));
>