[PATCH] hw/smbios/smbios.c: Add missing NUL terminal to string from path= parameter

Valentin David posted 1 patch 10 months, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20250326155254.2273939-1-valentin.david@canonical.com
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Igor Mammedov <imammedo@redhat.com>, Ani Sinha <anisinha@redhat.com>
hw/smbios/smbios.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] hw/smbios/smbios.c: Add missing NUL terminal to string from path= parameter
Posted by Valentin David 10 months, 2 weeks ago
Without it, it seems the data gets garbage at the end of the string.

Signed-off-by: Valentin David <valentin.david@canonical.com>
---
 hw/smbios/smbios.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
index 02a09eb9cd..7522e9a172 100644
--- a/hw/smbios/smbios.c
+++ b/hw/smbios/smbios.c
@@ -1283,6 +1283,7 @@ static int save_opt_one(void *opaque,
                 return -1;
             }
             g_byte_array_append(data, (guint8 *)buf, ret);
+            g_byte_array_append(data, (guint8 *)"\0", 1);
         }
 
         qemu_close(fd);
-- 
2.48.1
Re: [PATCH] hw/smbios/smbios.c: Add missing NUL terminal to string from path= parameter
Posted by Daniel P. Berrangé 10 months, 2 weeks ago
On Wed, Mar 26, 2025 at 04:52:54PM +0100, Valentin David wrote:
> Without it, it seems the data gets garbage at the end of the string.
> 
> Signed-off-by: Valentin David <valentin.david@canonical.com>
> ---
>  hw/smbios/smbios.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
> index 02a09eb9cd..7522e9a172 100644
> --- a/hw/smbios/smbios.c
> +++ b/hw/smbios/smbios.c
> @@ -1283,6 +1283,7 @@ static int save_opt_one(void *opaque,
>                  return -1;
>              }
>              g_byte_array_append(data, (guint8 *)buf, ret);
> +            g_byte_array_append(data, (guint8 *)"\0", 1);

That is inside the loop body, so it is appending an extra '\0' after
every 'read'.

The fix for this issue is posted here

https://lists.nongnu.org/archive/html/qemu-devel/2025-03/msg05826.html

>          }
>  
>          qemu_close(fd);


> -- 
> 2.48.1
> 
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|