From ad6fb3406b500be4a78ef87f554fffcecff057dc Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Mon, 29 Jul 2024 14:40:08 +0200 Subject: [PATCH] rusticl/program: protect against 0 length in slice::from_raw_parts Fixes: e028baa1772 ("rusticl/program: implement clCreateProgramWithBinary") Part-of: --- src/gallium/frontends/rusticl/api/program.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gallium/frontends/rusticl/api/program.rs b/src/gallium/frontends/rusticl/api/program.rs index 8dcec4d7c62..7f4a3c4ed29 100644 --- a/src/gallium/frontends/rusticl/api/program.rs +++ b/src/gallium/frontends/rusticl/api/program.rs @@ -183,14 +183,16 @@ fn create_program_with_binary( ) -> CLResult { 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);