- remote_driver: Restore special behavior of remoteDomainGetBlockIoTune() (RHEL-22800) - conf: Introduce dynamicMemslots attribute for virtio-mem (RHEL-15316) - qemu_capabilities: Add QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI_DYNAMIC_MEMSLOTS capability (RHEL-15316) - qemu_validate: Check capability for virtio-mem dynamicMemslots (RHEL-15316) - qemu_command: Generate cmd line for virtio-mem dynamicMemslots (RHEL-15316) - qemu_snapshot: fix detection if non-leaf snapshot isn't in active chain (RHEL-23212) - qemu_snapshot: create: refactor external snapshot detection (RHEL-22797) - qemu_snapshot: create: don't require disk-only flag for offline external snapshot (RHEL-22797) - remoteDispatchAuthPolkit: Fix lock ordering deadlock if client closes connection during auth (RHEL-20337) - util: virtportallocator: Add VIR_DEBUG statements for port allocations and release (RHEL-21543) - qemu: migration: Properly handle reservation of manually specified NBD port (RHEL-21543) - qemuMigrationDstStartNBDServer: Refactor cleanup (RHEL-21543) - virPCIVPDResourceIsValidTextValue: Adjust comment to reflect actual code (RHEL-22314) - util: pcivpd: Refactor virPCIVPDResourceIsValidTextValue (RHEL-22314) - virNodeDeviceCapVPDFormatCustom*: Escape unsanitized strings (RHEL-22314) - virNodeDeviceCapVPDFormat: Properly escape system-originated strings (RHEL-22314) - schema: nodedev: Adjust allowed characters in 'vpdFieldValueFormat' (RHEL-22314) - tests: Test the previously mishandled PCI VPD characters (RHEL-22314) - Don't overwrite error message from 'virXPathNodeSet' (RHEL-22314) - tests: virpcivpdtest: Remove 'testVirPCIVPDReadVPDBytes' case (RHEL-22314) - util: virpcivpd: Unexport 'virPCIVPDReadVPDBytes' (RHEL-22314) - util: pcivpd: Unexport virPCIVPDParseVPDLargeResourceFields (RHEL-22314) - tests: virpcivpd: Remove 'testVirPCIVPDParseVPDStringResource' case (RHEL-22314) - util: virpcivpd: Unexport 'virPCIVPDParseVPDLargeResourceString' (RHEL-22314) - virPCIVPDResourceGetKeywordPrefix: Fix logging (RHEL-22314) - util: virpcivpd: Remove return value from virPCIVPDResourceCustomUpsertValue (RHEL-22314) - conf: virNodeDeviceCapVPDParse*: Remove pointless NULL checks (RHEL-22314) - virpcivpdtest: testPCIVPDResourceBasic: Remove tests for uninitialized 'ro'/'rw' section (RHEL-22314) - util: virPCIVPDResourceUpdateKeyword: Remove impossible checks (RHEL-22314) - conf: node_device: Refactor 'virNodeDeviceCapVPDParseCustomFields' to fix error reporting (RHEL-22314) - virNodeDeviceCapVPDParseXML: Fix error reporting (RHEL-22314) - util: virpcivpd: Remove return value from virPCIVPDResourceUpdateKeyword (RHEL-22314) - virPCIDeviceHasVPD: Refactor "debug" messages (RHEL-22314) - virPCIDeviceGetVPD: Fix multiple error handling bugs (RHEL-22314) - virPCIDeviceGetVPD: Handle errors in callers (RHEL-22314) - virPCIVPDReadVPDBytes: Refactor error handling (RHEL-22314) - virPCIVPDParseVPDLargeResourceString: Properly report errors (RHEL-22314) - virPCIVPDParseVPDLargeResourceFields: Merge logic conditions (RHEL-22314) - virPCIVPDParseVPDLargeResourceFields: Remove impossible 'default' switch case (RHEL-22314) - virPCIVPDParseVPDLargeResourceFields: Refactor processing of read data (RHEL-22314) - virPCIVPDParseVPDLargeResourceFields: Refactor return logic (RHEL-22314) - virPCIVPDParseVPDLargeResourceFields: Report proper errors (RHEL-22314) - virPCIVPDParse: Do reasonable error reporting (RHEL-22314) - virt-admin: Add warning when connection to default daemon fails (RHEL-23170) Resolves: RHEL-15316, RHEL-20337, RHEL-21543, RHEL-22314, RHEL-22797 Resolves: RHEL-22800, RHEL-23170, RHEL-23212
106 lines
4.4 KiB
Diff
106 lines
4.4 KiB
Diff
From 72da25da974a1fa9d995b46afb76714d56f4cb9b Mon Sep 17 00:00:00 2001
|
|
Message-ID: <72da25da974a1fa9d995b46afb76714d56f4cb9b.1707394627.git.jdenemar@redhat.com>
|
|
From: Peter Krempa <pkrempa@redhat.com>
|
|
Date: Tue, 30 Jan 2024 16:45:39 +0100
|
|
Subject: [PATCH] virPCIVPDParseVPDLargeResourceFields: Refactor return logic
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
Rewrite the conditions after exiting the parser so that they are easier
|
|
to understand. This partially decreases the granularity of "error"
|
|
messages as they are not strictly necessary albeit for debugging.
|
|
|
|
As it was already observed in this code the logic itself often does
|
|
something else than the comment claims, thus the code logic is
|
|
preserved.
|
|
|
|
Changes:
|
|
- any case when not all data was processed is aggregated together and
|
|
gets a common "error" message
|
|
- absence of 'checksum' field is checked separately
|
|
- helper variables are removed as they are no longer needed
|
|
|
|
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
|
|
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
(cherry picked from commit a352bcf1c64e4efaa31ff5b193ff8ff4ca9d1329)
|
|
|
|
https://issues.redhat.com/browse/RHEL-22314 [9.4.0]
|
|
---
|
|
src/util/virpcivpd.c | 32 +++++++++++++-------------------
|
|
1 file changed, 13 insertions(+), 19 deletions(-)
|
|
|
|
diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c
|
|
index 60e520c46f..be19f7b747 100644
|
|
--- a/src/util/virpcivpd.c
|
|
+++ b/src/util/virpcivpd.c
|
|
@@ -415,10 +415,7 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uint16_t resPos, uint16_t re
|
|
g_autofree uint8_t *buf = g_malloc0(PCI_VPD_MAX_FIELD_SIZE + 1);
|
|
uint16_t fieldDataLen = 0, bytesToRead = 0;
|
|
uint16_t fieldPos = resPos;
|
|
-
|
|
bool hasChecksum = false;
|
|
- bool hasRW = false;
|
|
- bool endReached = false;
|
|
|
|
/* Note the equal sign - fields may have a zero length in which case they will
|
|
* just occupy 3 header bytes. In the in case of the RW field this may mean that
|
|
@@ -507,7 +504,9 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uint16_t resPos, uint16_t re
|
|
|
|
case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RDWR:
|
|
/* Skip the read-write space since it is used for indication only. */
|
|
- hasRW = true;
|
|
+ /* The lack of RW is allowed on purpose in the read-write section since some vendors
|
|
+ * violate the PCI/PCIe specs and do not include it, however, this does not prevent parsing
|
|
+ * of valid data. */
|
|
goto done;
|
|
|
|
case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RESVD:
|
|
@@ -531,6 +530,7 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uint16_t resPos, uint16_t re
|
|
if (!res->rw)
|
|
res->rw = virPCIVPDResourceRWNew();
|
|
}
|
|
+
|
|
/* The field format, keyword and value are determined. Attempt to update the resource. */
|
|
virPCIVPDResourceUpdateKeyword(res, readOnly, fieldKeyword, fieldValue);
|
|
}
|
|
@@ -538,27 +538,21 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uint16_t resPos, uint16_t re
|
|
done:
|
|
/* May have exited the loop prematurely in case RV or RW were encountered and
|
|
* they were not the last fields in the section. */
|
|
- endReached = (fieldPos >= resPos + resDataLen);
|
|
- if (readOnly && !(hasChecksum && endReached)) {
|
|
- VIR_DEBUG("VPD-R does not contain the mandatory RV field as the last field");
|
|
+ if ((fieldPos < resPos + resDataLen)) {
|
|
+ /* unparsed data still present */
|
|
+ VIR_DEBUG("PCI VPD data parsing failed");
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ if (readOnly && !hasChecksum) {
|
|
+ VIR_DEBUG("VPD-R does not contain the mandatory checksum");
|
|
return false;
|
|
- } else if (!readOnly && !endReached) {
|
|
- /* The lack of RW is allowed on purpose in the read-write section since some vendors
|
|
- * violate the PCI/PCIe specs and do not include it, however, this does not prevent parsing
|
|
- * of valid data. If the RW is present, however, we make sure it is the last field in
|
|
- * the read-write section. */
|
|
- if (hasRW) {
|
|
- VIR_DEBUG("VPD-W section parsing ended prematurely (RW is not the last field).");
|
|
- return false;
|
|
- } else {
|
|
- VIR_DEBUG("VPD-W section parsing ended prematurely.");
|
|
- return false;
|
|
- }
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
+
|
|
/**
|
|
* virPCIVPDParseVPDLargeResourceString:
|
|
* @vpdFileFd: A file descriptor associated with a file containing PCI device VPD.
|
|
--
|
|
2.43.0
|