rusticl/program: protect against 0 length in slice::from_raw_parts

Fixes: e028baa177 ("rusticl/program: implement clCreateProgramWithBinary")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30410>
This commit is contained in:
Karol Herbst
2024-07-29 14:40:08 +02:00
committed by Marge Bot
parent 7a8b1dc6e5
commit ad6fb3406b

View File

@@ -183,14 +183,16 @@ fn create_program_with_binary(
) -> CLResult<cl_program> {
let c = Context::arc_from_raw(context)?;
let devs = Device::refs_from_arr(device_list, num_devices)?;
let mut binary_status =
unsafe { cl_slice::from_raw_parts_mut(binary_status, num_devices as usize) }.ok();
// CL_INVALID_VALUE if device_list is NULL or num_devices is zero.
if devs.is_empty() {
return Err(CL_INVALID_VALUE);
}
// needs to happen after `devs.is_empty` check to protect against num_devices being 0
let mut binary_status =
unsafe { cl_slice::from_raw_parts_mut(binary_status, num_devices as usize) }.ok();
// CL_INVALID_VALUE if lengths or binaries is NULL
if lengths.is_null() || binaries.is_null() {
return Err(CL_INVALID_VALUE);