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>
(cherry picked from commit ad6fb3406b)
This commit is contained in:
Karol Herbst 2024-07-29 14:40:08 +02:00 committed by Eric Engestrom
parent 85c000fbd2
commit fb663417c7
2 changed files with 5 additions and 3 deletions

View file

@ -144,7 +144,7 @@
"description": "rusticl/program: protect against 0 length in slice::from_raw_parts",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "e028baa1772eeaa55393b1d01d5e5fb217474f95",
"notes": null

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);