radv: honour the number of properties available
authorEmil Velikov <emil.velikov@collabora.com>
Thu, 24 Nov 2016 18:14:58 +0000 (18:14 +0000)
committerDave Airlie <airlied@redhat.com>
Sun, 27 Nov 2016 23:03:01 +0000 (23:03 +0000)
Cap up-to the number of properties available while copying the data.
Otherwise we might crash and/or leak data.

Cc: Dave Airlie <airlied@redhat.com>
Cc: "13.0" <mesa-stable@lists.freedesktop.org>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Signed-off-by: Dave Airlie <airlied@redhat.com>
src/amd/vulkan/radv_device.c

index 3559c30c82343ac11f119adac457301380ffeaa3..f89fc9dde572472026077a762d1328e7dcbece74 100644 (file)
@@ -712,17 +712,15 @@ VkResult radv_EnumerateInstanceExtensionProperties(
        uint32_t*                                   pPropertyCount,
        VkExtensionProperties*                      pProperties)
 {
-       unsigned i;
        if (pProperties == NULL) {
                *pPropertyCount = ARRAY_SIZE(global_extensions);
                return VK_SUCCESS;
        }
 
-       for (i = 0; i < *pPropertyCount; i++)
-               memcpy(&pProperties[i], &global_extensions[i], sizeof(VkExtensionProperties));
+       *pPropertyCount = MIN2(*pPropertyCount, ARRAY_SIZE(global_extensions));
+       typed_memcpy(pProperties, global_extensions, *pPropertyCount);
 
-       *pPropertyCount = i;
-       if (i < ARRAY_SIZE(global_extensions))
+       if (*pPropertyCount < ARRAY_SIZE(global_extensions))
                return VK_INCOMPLETE;
 
        return VK_SUCCESS;
@@ -734,19 +732,17 @@ VkResult radv_EnumerateDeviceExtensionProperties(
        uint32_t*                                   pPropertyCount,
        VkExtensionProperties*                      pProperties)
 {
-       unsigned i;
-
        if (pProperties == NULL) {
                *pPropertyCount = ARRAY_SIZE(device_extensions);
                return VK_SUCCESS;
        }
 
-       for (i = 0; i < *pPropertyCount; i++)
-               memcpy(&pProperties[i], &device_extensions[i], sizeof(VkExtensionProperties));
+       *pPropertyCount = MIN2(*pPropertyCount, ARRAY_SIZE(device_extensions));
+       typed_memcpy(pProperties, device_extensions, *pPropertyCount);
 
-       *pPropertyCount = i;
-       if (i < ARRAY_SIZE(device_extensions))
+       if (*pPropertyCount < ARRAY_SIZE(device_extensions))
                return VK_INCOMPLETE;
+
        return VK_SUCCESS;
 }