From ead741c43a6b1f29d86f5076e4ca1a4fe2e1152d Mon Sep 17 00:00:00 2001 From: Brice Videau Date: Wed, 23 Oct 2013 10:13:44 +0200 Subject: [PATCH] cl_platform_id s provided by users to clCreateContext and clCreateContextFromType will be checked against the list of platforms gathered during setup to assert validity. --- ocl_icd_loader.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/ocl_icd_loader.c b/ocl_icd_loader.c index 6c4a631..b2143a8 100644 --- a/ocl_icd_loader.c +++ b/ocl_icd_loader.c @@ -712,16 +712,30 @@ clCreateContext(const cl_context_properties * properties , cl_uint i=0; if( properties != NULL){ while( properties[i] != 0 ) { - if( properties[i] == CL_CONTEXT_PLATFORM ) + if( properties[i] == CL_CONTEXT_PLATFORM ) { if((struct _cl_platform_id *) properties[i+1] == NULL) { if(errcode_ret) { *errcode_ret = CL_INVALID_PLATFORM; } RETURN(NULL); + } else { + int good = 0; + cl_uint j; + for( j=0; j<_num_picds; j++) { + if( _picds[j].pid == (cl_platform_id) properties[i+1] ) + good = 1; + } + if( !good ) { + if(errcode_ret) { + *errcode_ret = CL_INVALID_PLATFORM; + } + RETURN(NULL); + } } RETURN(((struct _cl_platform_id *) properties[i+1]) ->dispatch->clCreateContext(properties, num_devices, devices, pfn_notify, user_data, errcode_ret)); + } i += 2; } } @@ -754,13 +768,27 @@ clCreateContextFromType(const cl_context_properties * properties , cl_uint i=0; if( properties != NULL){ while( properties[i] != 0 ) { - if( properties[i] == CL_CONTEXT_PLATFORM ) + if( properties[i] == CL_CONTEXT_PLATFORM ) { if (properties[i+1] == 0) { goto out; + } else { + int good = 0; + cl_uint j; + for( j=0; j<_num_picds; j++) { + if( _picds[j].pid == (cl_platform_id) properties[i+1] ) + good = 1; + } + if( !good ) { + if(errcode_ret) { + *errcode_ret = CL_INVALID_PLATFORM; + } + RETURN(NULL); + } } return ((struct _cl_platform_id *) properties[i+1]) ->dispatch->clCreateContextFromType(properties, device_type, pfn_notify, user_data, errcode_ret); + } i += 2; } } else { -- 2.32.0.93.g670b81a890