From 66ecca5dce2c4425a48bdb0cf0de606e4da43ab5 Mon Sep 17 00:00:00 2001 From: Alastair Murray Date: Thu, 11 Apr 2019 17:17:06 +0100 Subject: [PATCH] Do parameter validation in clGetExtensionFunctionAddress Also undefine the local macros as soon as possible. Patch originally from Jeroen Ketema. --- icd_dispatch.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/icd_dispatch.c b/icd_dispatch.c index ecf52fc..df967cb 100644 --- a/icd_dispatch.c +++ b/icd_dispatch.c @@ -1359,6 +1359,8 @@ CL_API_ENTRY void * CL_API_CALL clGetExtensionFunctionAddressForPlatform(cl_platform_id platform, const char * function_name) CL_API_SUFFIX__VERSION_1_2 { + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(function_name, NULL); + // make sure the ICD is initialized khrIcdInitialize(); @@ -1426,6 +1428,8 @@ clGetExtensionFunctionAddressForPlatform(cl_platform_id platform, /* cl_khr_sub_groups */ CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clGetKernelSubGroupInfoKHR); + #undef CL_COMMON_EXTENSION_ENTRYPOINT_ADD + // This is not an ICD-aware extension, so call into the implementation // to get the extension function address. @@ -1567,11 +1571,14 @@ clEnqueueBarrier(cl_command_queue command_queue) CL_EXT_SUFFIX__VERSION_1_1_DEPR CL_API_ENTRY void * CL_API_CALL clGetExtensionFunctionAddress(const char *function_name) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED { - size_t function_name_length = strlen(function_name); + size_t function_name_length = 0; KHRicdVendor* vendor = NULL; + KHR_ICD_VALIDATE_HANDLE_RETURN_ERROR(function_name, NULL); + // make sure the ICD is initialized khrIcdInitialize(); + function_name_length = strlen(function_name); // return any ICD-aware extensions @@ -1637,6 +1644,8 @@ clGetExtensionFunctionAddress(const char *function_name) CL_EXT_SUFFIX__VERSION_ /* cl_khr_sub_groups */ CL_COMMON_EXTENSION_ENTRYPOINT_ADD(clGetKernelSubGroupInfoKHR); + #undef CL_COMMON_EXTENSION_ENTRYPOINT_ADD + // fall back to vendor extension detection for (vendor = khrIcdVendors; vendor; vendor = vendor->next) { -- 2.7.4