[Mesa-stable] [Mesa-dev] [PATCH] radv: honour the number of properties available

Bas Nieuwenhuizen bas at basnieuwenhuizen.nl
Thu Nov 24 18:32:11 UTC 2016


Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>

On Thu, Nov 24, 2016 at 7:14 PM, Emil Velikov <emil.l.velikov at gmail.com> wrote:
> From: Emil Velikov <emil.velikov at collabora.com>
>
> Cap up-to the number of properties available while copying the data.
> Otherwise we might crash and/or leak data.
>
> Cc: Dave Airlie <airlied at redhat.com>
> Cc: "13.0" <mesa-stable at lists.freedesktop.org>
> Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
> ---
>  src/amd/vulkan/radv_device.c | 18 +++++++-----------
>  1 file changed, 7 insertions(+), 11 deletions(-)
>
> diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
> index 390fde0..e6e5c37 100644
> --- a/src/amd/vulkan/radv_device.c
> +++ b/src/amd/vulkan/radv_device.c
> @@ -669,17 +669,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;
> @@ -691,19 +689,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;
>  }
>
> --
> 2.10.2
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-stable mailing list