[PATCH 0/3] Fix 3 minor leaks/undefined behaviour
Peter Krempa (3): virDomainDefParseMemory: Avoid leak of invalid hugepages bitmap qcow2GetExtensions: Consider only 1 data file qcow2GetImageSpecific: Avoid undefined behaviour when shifting bits src/conf/domain_conf.c | 2 +- src/storage_file/storage_file_probe.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) -- 2.56.0
From: Peter Krempa <pkrempa@redhat.com> Set 'nhugepages' directly to the potential maximum amount of hugepages as we'll parse less than that only on error at which point the function freeing the domain definition needs to clean up also the partially filled entries. Closes: https://gitlab.com/libvirt/libvirt/-/work_items/951 Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/conf/domain_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f3179926c9..bb195264c4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19513,12 +19513,12 @@ virDomainDefParseMemory(virDomainDef *def, if (n) { def->mem.hugepages = g_new0(virDomainHugePage, n); + def->mem.nhugepages = n; for (i = 0; i < n; i++) { if (virDomainHugepagesParseXML(nodes[i], ctxt, &def->mem.hugepages[i]) < 0) return -1; - def->mem.nhugepages++; } VIR_FREE(nodes); -- 2.56.0
From: Peter Krempa <pkrempa@redhat.com> While technically the qcow2 header can have multiple data file extensions, such setup doesn't practically make sense. Parse only the first entry to close a potential memory leak when multiple such headers would cause our parser to overwrite the parsed string. Closes: https://gitlab.com/libvirt/libvirt/-/work_items/953 Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/storage_file/storage_file_probe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/storage_file_probe.c index efe95bf818..a30528b02c 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -552,7 +552,8 @@ qcow2GetExtensions(virStorageSource *meta, } case QCOW2_HDR_EXTENSION_DATA_FILE_NAME: - if (virBitmapIsBitSet(meta->features, VIR_STORAGE_FILE_FEATURE_DATA_FILE)) + if (!meta->dataFileRaw && + virBitmapIsBitSet(meta->features, VIR_STORAGE_FILE_FEATURE_DATA_FILE)) meta->dataFileRaw = g_strndup(buf + offset, len); break; -- 2.56.0
From: Peter Krempa <pkrempa@redhat.com> If the QCOW2 header had more than 64 cluster bits, our parser would do a bitshift operation to determine cluster size beyond the amount of bits in the variable which is undefined behaviour. Any normal implementation would then have the clusterSize variable to be 0 which is what we've wanted but to avoid relying on UB avoid the bitshift completely if the QCOW2 header specifies 64 or more cluster bits. Closes: https://gitlab.com/libvirt/libvirt/-/work_items/952 Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/storage_file/storage_file_probe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/storage_file_probe.c index a30528b02c..7436ce34a5 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -671,7 +671,8 @@ qcow2GetImageSpecific(virStorageSource *meta, if (buf_size > (QCOWX_HDR_CLUSTER_BITS_OFFSET + 4)) { int clusterBits = virReadBufInt32BE(buf + QCOWX_HDR_CLUSTER_BITS_OFFSET); - if (clusterBits > 0) + if (clusterBits > 0 && + clusterBits < sizeof(meta->clusterSize) * 8) meta->clusterSize = 1ULL << clusterBits; } -- 2.56.0
On a Monday in 2026, Peter Krempa via Devel wrote:
Peter Krempa (3): virDomainDefParseMemory: Avoid leak of invalid hugepages bitmap qcow2GetExtensions: Consider only 1 data file qcow2GetImageSpecific: Avoid undefined behaviour when shifting bits
src/conf/domain_conf.c | 2 +- src/storage_file/storage_file_probe.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko -
Peter Krempa