From: Peter Krempa <[email protected]>

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 <[email protected]>
---
 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

Reply via email to