qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 1/2] vfio: Fix overrun after readlink() fills buffer


From: Markus Armbruster
Subject: [Qemu-devel] [PATCH 1/2] vfio: Fix overrun after readlink() fills buffer completely
Date: Fri, 21 Feb 2014 17:42:04 +0100

readlink() returns the number of bytes written to the buffer, and it
doesn't write a terminating null byte.  vfio_init() writes it itself.
Overruns the buffer when readlink() filled it completely.

Fix by reserving space for the null byte when calling readlink(), like
we do elsewhere.

Spotted by Coverity.

Signed-off-by: Markus Armbruster <address@hidden>
---
 hw/misc/vfio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
index 8db182f..8e56785 100644
--- a/hw/misc/vfio.c
+++ b/hw/misc/vfio.c
@@ -3681,7 +3681,7 @@ static int vfio_initfn(PCIDevice *pdev)
 
     strncat(path, "iommu_group", sizeof(path) - strlen(path) - 1);
 
-    len = readlink(path, iommu_group_path, PATH_MAX);
+    len = readlink(path, iommu_group_path, PATH_MAX - 1);
     if (len <= 0) {
         error_report("vfio: error no iommu_group for device");
         return -errno;
-- 
1.8.1.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]