From 8733303933e343deb8c58c8f2c5f41b90b327bf0 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 4 Apr 2014 16:56:29 -0600 Subject: [PATCH] conf: avoid memleak on NULL path 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 --- src/security/virt-aa-helper.c | 5 ++++- src/util/virstoragefile.c | 2 +- src/util/virstoragefile.h | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 64a382c102..7bddb2cd53 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -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); } diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 0e1461d0ce..3cdc89c868 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -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) diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 3807285550..83ec2bda79 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -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); -- GitLab