From d653c84a688d65b8b421c08fdbea6b22878a364d Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Thu, 24 Nov 2016 18:14:58 +0000 Subject: radv: honour the number of properties available Cap up-to the number of properties available while copying the data. Otherwise we might crash and/or leak data. Cc: Dave Airlie Cc: "13.0" Signed-off-by: Emil Velikov Reviewed-by: Bas Nieuwenhuizen Signed-off-by: Dave Airlie (cherry picked from commit a025c5b2c7c9c6862006b13c9b8ab46c3acf8e53) --- src/amd/vulkan/radv_device.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/amd/vulkan/radv_device.c') diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index 4a924ea..94a2ef0 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -659,17 +659,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; @@ -681,19 +679,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; } -- cgit v1.1