[PATCH] virpci: fix handling newline in PCI device class

Marek Marczykowski-Górecki posted 1 patch 1 week, 1 day ago
src/util/virpci.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] virpci: fix handling newline in PCI device class
Posted by Marek Marczykowski-Górecki 1 week, 1 day ago
The referenced commit removed trimming newline resulting in errors like:

    Unusual value in /sys/bus/pci//devices/0000:00:17.0/class: 0x010601

It's a perfectly valid class, it's just the newline that virStrToLong_ui
didn't like (as it wasn't parsed and endptr is given NULL).

Restore stripping newline, but do so a bit nicer than hardcoded offset.

Fixes: 58b3a78aff "virPCIDeviceReadClass: Don't write beyond end of buffer from virFileReadAll"
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
 src/util/virpci.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/util/virpci.c b/src/util/virpci.c
index 34fc70e261..66500132c9 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -488,6 +488,8 @@ virPCIDeviceReadClass(virPCIDevice *dev, uint16_t *device_class)
     if (virFileReadAll(path, 9, &id_str) < 0)
         return -1;
 
+    virStringTrimOptionalNewline(id_str);
+
     if (virStrToLong_ui(id_str, NULL, 16, &value) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Unusual value in %1$s/devices/%2$s/class: %3$s"),
-- 
2.54.0

Re: [PATCH] virpci: fix handling newline in PCI device class
Posted by Michal Prívozník via Devel 1 week, 1 day ago
On 10/16/26 02:04, Marek Marczykowski-Górecki wrote:
> The referenced commit removed trimming newline resulting in errors like:
> 
>     Unusual value in /sys/bus/pci//devices/0000:00:17.0/class: 0x010601
> 
> It's a perfectly valid class, it's just the newline that virStrToLong_ui
> didn't like (as it wasn't parsed and endptr is given NULL).
> 
> Restore stripping newline, but do so a bit nicer than hardcoded offset.
> 
> Fixes: 58b3a78aff "virPCIDeviceReadClass: Don't write beyond end of buffer from virFileReadAll"
> Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
> ---
>  src/util/virpci.c | 2 ++
>  1 file changed, 2 insertions(+)
> 

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Michal