]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
conf: avoid memleak on NULL path
authorEric Blake <eblake@redhat.com>
Fri, 4 Apr 2014 22:56:29 +0000 (16:56 -0600)
committerEric Blake <eblake@redhat.com>
Mon, 7 Apr 2014 22:31:45 +0000 (16:31 -0600)
I noticed that the apparmor code could request metadata even
for a cdrom with no media, which would cause a memory leak of
the hash table used to look for loops in the backing chain.
But even before that, we blindly dereferenced the path for
printing a debug statement, so it is just better to enforce
that this is only used on non-NULL names.

* src/util/virstoragefile.c (virStorageFileGetMetadata): Assume
non-NULL path.
* src/util/virstoragefile.h: Annotate this.
* src/security/virt-aa-helper.c (get_files): Fix caller.

Signed-off-by: Eric Blake <eblake@redhat.com>
src/security/virt-aa-helper.c
src/util/virstoragefile.c
src/util/virstoragefile.h

index 64a382c1027d4e3f11151d3976a9528349edb41b..7bddb2cd53871e501d00fa5322d9b46e04b8f00a 100644 (file)
@@ -943,13 +943,16 @@ get_files(vahControl * ctl)
 
     for (i = 0; i < ctl->def->ndisks; i++) {
         virDomainDiskDefPtr disk = ctl->def->disks[i];
+        const char *src = virDomainDiskGetSource(disk);
 
+        if (!src)
+            continue;
         /* XXX - if we knew the qemu user:group here we could send it in
          *        so that the open could be re-tried as that user:group.
          */
         if (!disk->backingChain) {
             bool probe = ctl->allowDiskFormatProbing;
-            disk->backingChain = virStorageFileGetMetadata(virDomainDiskGetSource(disk),
+            disk->backingChain = virStorageFileGetMetadata(src,
                                                            virDomainDiskGetFormat(disk),
                                                            -1, -1, probe);
         }
index 0e1461d0ce17b9d2f863792041853bf7ff4a4fe9..3cdc89c8682fd0f871b543221220af4027a5d954 100644 (file)
@@ -1144,7 +1144,7 @@ virStorageFileGetMetadata(const char *path, int format,
     virHashTablePtr cycle = virHashCreate(5, NULL);
     virStorageFileMetadataPtr ret;
 
-    if (!cycle || !path)
+    if (!cycle)
         return NULL;
 
     if (format <= VIR_STORAGE_FILE_NONE)
index 3807285550dc509812dba78450f2c5b37423c21f..83ec2bda79a6d3aa044e2cbee1cedd825e804905 100644 (file)
@@ -257,7 +257,8 @@ int virStorageFileProbeFormatFromBuf(const char *path, char *buf,
 virStorageFileMetadataPtr virStorageFileGetMetadata(const char *path,
                                                     int format,
                                                     uid_t uid, gid_t gid,
-                                                    bool allow_probe);
+                                                    bool allow_probe)
+    ATTRIBUTE_NONNULL(1);
 virStorageFileMetadataPtr virStorageFileGetMetadataFromFD(const char *path,
                                                           int fd,
                                                           int format);